Open davidrbright opened 7 years ago
+1
👍
PR welcome
On Node v12.14.1 , this is happening for me for all multi-line strings, even without template literals.
One easy workaround for this -- print your multi-line prompt using console.log
and only print the very last line of the prompt using prompt-sync
. Problem solved.
Why was this issue closed when it's still a problem as sorousjp reported? Why has a serious bug like this been left unfixed for 6 months? Should I look for a replacement package that's maintained?
This is still an issue.
It was really hard to find this issue since I didn't know why my prompts were being repeated, so I wonder if there are more folks having this issue who haven't realized it's due to multi-line literals. Taking @soroushjp suggestion, I've put together this script which helps demonstrate the problem, and solves the prompt issue by wrapping up the console logging and prompting automatically:
const prompt = require('prompt-sync')({sigint: true});
const multiLinePrompt = ask => {
const lines = ask.split(/\r?\n/);
const promptLine = lines.pop();
console.log(lines.join('\n'));
return prompt(promptLine);
};
let response = ''
// Test 1: Basic Prompt on One Line
response = prompt(`This prompt uses a single line literal and WON'T have print errors: `);
console.log(`The prompt captured: ${response}`);
// Test 2: Reproduction of issue with multi-line literal prompts
response = prompt(`This prompt uses a multi line literal and
WILL
have print errors: `);
console.log(`The prompt captured: ${response}`);
// Test 3: Demonstration of helper function to mitigate the issue
response = multiLinePrompt(`This prompt uses the above multi-line helper and
WON'T
have print errors: `);
console.log(`The prompt captured: ${response}`);
Whoops, sorry for the notification spam on this issue, I was polishing the PR commit in my fork.
My PR Should solve this issue. It just sets ask
to be only the final line of the user's supplied input during redraw. Pinging @heapwolf for attention to the PR.
Thanks for this module, Paolo! Let me know if there's something I missed with regards to the fix.
This repo seems to be inactive at this time. I wrote a modern port of it called prompt-sync-plus intended to be mostly a drop-in replacement for this (with some exceptions); multi-line prompts, and multi-line input in general was one of the issues addressed.
Used prompt with a multi-line template literal, and the stdout would repeat itself on a newline with each keypress. User input worked fine though.
The problem was fixed by going to es5 syntax.