diff options
-rw-r--r-- | cli/rt/41_prompt.js | 16 | ||||
-rw-r--r-- | cli/tests/066_prompt.ts | 4 | ||||
-rw-r--r-- | cli/tests/066_prompt.ts.out | 2 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 2 |
4 files changed, 22 insertions, 2 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]); diff --git a/cli/tests/066_prompt.ts b/cli/tests/066_prompt.ts index 1c4a11f98..e3daa7ac0 100644 --- a/cli/tests/066_prompt.ts +++ b/cli/tests/066_prompt.ts @@ -12,6 +12,10 @@ const answer2 = confirm("Question 2"); // Answer with yes (returns false) console.log(`Your answer is ${answer2}`); const answer3 = confirm(); // Answer with default console.log(`Your answer is ${answer3}`); +const windows = prompt("What is Windows EOL?"); +console.log(`Your answer is ${JSON.stringify(windows)}`); alert("Hi"); alert(); console.log("The end of test"); +const eof = prompt("What is EOF?"); +console.log(`Your answer is ${JSON.stringify(eof)}`); diff --git a/cli/tests/066_prompt.ts.out b/cli/tests/066_prompt.ts.out index 88d73f34f..7defc51e5 100644 --- a/cli/tests/066_prompt.ts.out +++ b/cli/tests/066_prompt.ts.out @@ -5,4 +5,6 @@ Question 0 [y/N] Your answer is true Question 1 [y/N] Your answer is false Question 2 [y/N] Your answer is false Confirm [y/N] Your answer is false +What is Windows EOL? Your answer is "windows" Hi [Enter] Alert [Enter] The end of test +What is EOF? Your answer is null diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 0bba369fe..895c64098 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2185,7 +2185,7 @@ fn _066_prompt() { let args = "run --unstable 066_prompt.ts"; let output = "066_prompt.ts.out"; // These are answers to prompt, confirm, and alert calls. - let input = b"John Doe\n\nfoo\nY\nN\nyes\n\n\n\n"; + let input = b"John Doe\n\nfoo\nY\nN\nyes\n\nwindows\r\n\n\n"; util::test_pty(args, output, input); } |