I have a daemon script that clears/outputs to stdout every X seconds, like this:
function clearTerminal(){
process.stdout.write('\u001B[2J\u001B[0;0f');
}
function printNum(){
var rand = Math.floor(Math.random() * 10) + 2;
console.log(rand);
}
function refreshTerminal(){
clearTerminal();
printNum();
}
refreshTerminal();
var interval = setInterval(refreshTerminal, 1000);
This works, but the daemon's output history is viewable by scrolling up after the daemon terminates. I'd like to rewind and truncate stdout, as described here:
Clearing output of a terminal program Linux C/C++
+1 if there's already a module out there for this, thanks!