Question: I have a simple readline shell written in Coffeescript:

```coffee
rl = require 'readline'
cli = rl.createInterface process.stdin, process.stdout, null
cli.setPrompt "hello> "

cli.on 'line', (line) ->
  console.log line
  cli.prompt()

cli.prompt()

```

Running this displays a prompt:

```
$ coffee cli.coffee 
hello> 

```

I would like to be able to hit `Ctrl-L` to clear the screen. Is this possible?

I have also noticed that I cannot hit `Ctrl-L` in either the **node** or **coffee** REPLs either.

I am running on Ubuntu 11.04.

Answer: 
This is the only answer that will clear the screen **AND** scroll history.

```
function clear() {
  // 1. Print empty lines until the screen is blank.
  process.stdout.write('\033[2J');

  // 2. Clear the scrollback.
  process.stdout.write('\u001b[H\u001b[2J\u001b[3J');
}

// Try this example to see it in action!
(function loop() {
  let i = -40; // Print 40 lines extra.
  (function printLine() {
    console.log('line ' + (i + 41));
    if (++i < process.stdout.columns) {
      setTimeout(printLine, 40);
    }
    else {
      clear();
      setTimeout(loop, 3000);
    }
  })()
})()

```

* The first line ensures the visible lines are always cleared.
* The second line ensures the scroll history is cleared.
On response to @loganfsmyth comment on his answer (thanks for the edit!).

I have been looking here and there and, besides of the wonderfull [keypress](https://github.com/TooTallNate/keypress) module, there is a core module that makes possible to create a `cli` with all standard terminal behavior (all things we give for granted today such as history, options to provide an auto-complete function and input events such as `keypress` are there).

The module is `readline` ([documentation](http://nodejs.org/api/readline.html)). The good news is that all the standar behaviour is already done for us so there is no need to attach event handlers (i.e. history, clearing the screen on `Ctrl`+`L`, man if you provided the auto complete function it'll be on `Tab`press). 

Just as an example

```
var readline = require('readline')
  , cli = readline.createInterface({
      input : process.stdin,
      output : process.stdout
  });

var myPrompt = ' > myPropmt '
cli.setPrompt(myPrompt, myPrompt.length); 
// prompt length so you can use "color" in your prompt
cli.prompt(); 
// Display ' > myPrompt ' with all standard features (history also!)

cli.on('line', function(cmd){ // fired each time the input has a new line       
   cli.prompt();
})

cli.input.on('keypress', function(key){  // self explanatory
  // arguments is a "key" object
  // with really nice properties such as ctrl : false
  process.stdout.write(JSON.stringify(arguments))
});

```

Really good discovery. 

The node version I'm using is `v0.10.29`. I have been looking at the [changelog](http://nodejs.org/changelog.html) and it was there since 2010 (commit [10d8ad](https://github.com/joyent/node/commit/10d8ad)).