You can use ANSI Escape sequences to move the cursor...
Example : printing "\033[3A"
will make the cursor move three lines up
If I have understood what you want... This should help:
var writeEscape = a => process.stdout.write("\033[" + a);
var moveUp = n => writeEscape(n +"A")
var moveDown = n => writeEscape(n + "B")
var moveRight = n => writeEscape(n +"C")
var moveLeft = n => writeEscape(n + "D")
var waitFor = n => new Promise(r => setTimeout(r,n))
writeEscape("25l"); // hide cursor use writeEscape("","25h") to show it again
process.stdout.write("waiting\n")
process.stdout.write("some other text");
moveUp(1)
moveLeft(15) // "some other text".length = 15
var printWaiting = async() => {
writeEscape("K"); // erase the whole line
process.stdout.write("waiting")
await waitFor(1000)
process.stdout.write(".")
await waitFor(1000)
process.stdout.write(".")
await waitFor(1000)
process.stdout.write(".")
moveLeft(10) // "waiting".length = 7, "...".length = 3
await waitFor(1000)
printWaiting()
}
printWaiting();
I have used async/await functions... But setTimeout only will also work...