I have a setInterval who logs the time every second. I want to use STDIN to execute commands in my script, but the STDOUT is moving the cursor while I'm typing and puts itself in the prompt.
I don't have much experience with prompts, just started diving into this.
Script:
setInterval(function(){
console.log(new Date().toUTCString());
},1000)
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Hi there, how are you?", function(answer) {
});
Output:
Hi there, how are you?Mon, 17 Dec 2012 16:20:34 GMT
fine
Mon, 17 Dec 2012 16:20:35 GMT
Mon, 17 Dec 2012 16:20:36 GMT
Mon, 17 Dec 2012 16:20:37 GMT
Mon, 17 Dec 2012 16:20:38 GMT
How would you solve something like this? Cache all the STDOUT, clear the screen, write all the STDOUT and prompt again every time console.log() is logging?
Yes I do want to create some kind of chat based system/command line interface where the output stays above the input.
Thanks!