diff options
author | Sander Hahn <sanderhahn@gmail.com> | 2020-10-29 18:35:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-29 18:35:58 +0100 |
commit | 1854c6f73be9d4439807911ce9cba1125af93dd4 (patch) | |
tree | 7c428c5a82bfb6982d10424fa395f14a678125d2 /cli/rt/41_prompt.js | |
parent | 8d99adb6c481d1450b4b01dba5d7a193c51d71d1 (diff) |
fix(cli): prompt works with windows eol and eof (#8149)
Diffstat (limited to 'cli/rt/41_prompt.js')
-rw-r--r-- | cli/rt/41_prompt.js | 16 |
1 files changed, 15 insertions, 1 deletions
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]); |