Hacky fix for weird behaviour when calling prompt('some text\n');. I don't understand how the prompt() function works entirely, but if the ask variable includes a newline character, weird behaviour can occur, with each keystroke the prompt is printed again.
Reproduce:
const prompt = require('prompt-sync')();
const in = prompt('this is a test: \n');
console.log(in);
With this code, each keystroke will cause the prompt() text to be printed again, until a return keystroke is sent. This patch checks for \n within the ask variable inside the prompt() function prints it separately, then strips it from the string.
Hacky fix for weird behaviour when calling
prompt('some text\n');
. I don't understand how theprompt()
function works entirely, but if theask
variable includes a newline character, weird behaviour can occur, with each keystroke the prompt is printed again.Reproduce:
With this code, each keystroke will cause the
prompt()
text to be printed again, until a return keystroke is sent. This patch checks for\n
within theask
variable inside theprompt()
function prints it separately, then strips it from the string.Before change:
After change: