joyent/node — Issue #2188: Push down readline prompt
Author: whitman
Created: 2011-11-25 11:27:12+00:00
State: open

Using the following as a test:

var readline = require('readline');
var stdin = process.openStdin();
var stdout = process.stdout;

var repl = readline.createInterface(stdin, stdout, null);

repl.on('close', function() {
stdin.destroy();
process.exit(0);
});

repl.on('line', function(buffer) {
if (buffer.toLowerCase() === 'exit') {
repl.close();
}
repl.prompt();
});

repl.setPrompt('> ');
repl.prompt();

setInterval(function() {
repl.write('\nTest');
}, 5000);

if I am typing at the prompt and `repl.write()` is called then it gets printed on the same line as what I am currently typing. So I end up with something like this:

> I am typing something
> Testwhen all of a sudden
> Test I get iterupted
> Test

Would it be possible to instead, either using `write` or another function, to get output more like this:

Test
Test
Test
> I am typing something but no longer getting interupted

The current prompt would be pushed down and the output wouldn't appear mid command.