From 1854c6f73be9d4439807911ce9cba1125af93dd4 Mon Sep 17 00:00:00 2001 From: Sander Hahn Date: Thu, 29 Oct 2020 18:35:58 +0100 Subject: fix(cli): prompt works with windows eol and eof (#8149) --- cli/rt/41_prompt.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'cli/rt') diff --git a/cli/rt/41_prompt.js b/cli/rt/41_prompt.js index 5a588def1..0adc6081a 100644 --- a/cli/rt/41_prompt.js +++ b/cli/rt/41_prompt.js @@ -3,6 +3,7 @@ const { stdin, stdout } = window.__bootstrap.files; const { isatty } = window.__bootstrap.tty; const LF = "\n".charCodeAt(0); + const CR = "\r".charCodeAt(0); const encoder = new TextEncoder(); const decoder = new TextDecoder(); @@ -50,7 +51,20 @@ while (true) { const n = stdin.readSync(c); - if (n === 0 || c[0] === LF) { + if (n === null || n === 0) { + break; + } + if (c[0] === CR) { + const n = stdin.readSync(c); + if (c[0] === LF) { + break; + } + buf.push(CR); + if (n === null || n === 0) { + break; + } + } + if (c[0] === LF) { break; } buf.push(c[0]); -- cgit v1.2.3