What I'd like to do is hiding/erasing all users input from a nodejs console app once entered, so that when the user inserts some text and then types enter, he won't be able to read what he just entered in the console anymore (so basically remove the line right after it's been entered).
This should be pretty simple to achieve but I have no idea how to do it =).
Thank you in advance
EDIT: Let's say we have this code:
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.question('How ya doin?\n', input => {
console.log('seems like you\'r doing ' + input.toString())
})

Looks like readline can already handle this for you..
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.question('How ya doin?\n', input => {
readline.moveCursor(process.stdout, 0,-1)
console.log('seems like you\'r doing ' + input.toString())
})
According to Bash HOWTO
Move the cursor up N lines:
\033[<N>A
To overwrite user's 1 line input with your output you should move 1 line up and print your output. It will look like this:
console.log('\033[1A' + 'seems like you\'r doing ' + input.toString());
UPDATE: Found a nice answer :)
How do you edit existing text (and move the cursor around) in the terminal?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With