Reputation: 40886
I'm using the readline
module in Node (12) to accept user input as such:
import * as readline from "readline";
process.stdin.setEncoding('utf-8');
console.log("input is a TTY?",process.stdin.isTTY);
const rl = readline.createInterface({input: process.stdin, output: process.stdout, prompt: '> '});
rl.prompt();
rl.on('line' ,inputLine => { inputStringLines.push(inputLine); rl.prompt(); });
rl.on('close',() => { console.log('input has closed'); main(); });
The lines are correctly captured into my inputStringLines
array but annoyingly, the process is printing out every line just read:
How can I get rid of the extra lines (the ones without the >
prompt)
Upvotes: 2
Views: 728
Reputation: 40886
I fixed it by changing how run my script. Before, I used nodemon
with node's -r ts-node/register
option. The issue went away when I switched to using ts-node-dev
to execute the script.
Note also that process.stdin.isTTY
is now correctly set whereas it was undefined before (look at the first line in the image below, vs in the original post)
Still don't know the root cause, but I'm happy to move on.
Upvotes: 2