mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
fix(cli): prompt works with windows eol and eof (#8149)
This commit is contained in:
parent
8d99adb6c4
commit
1854c6f73b
4 changed files with 22 additions and 2 deletions
|
@ -3,6 +3,7 @@
|
||||||
const { stdin, stdout } = window.__bootstrap.files;
|
const { stdin, stdout } = window.__bootstrap.files;
|
||||||
const { isatty } = window.__bootstrap.tty;
|
const { isatty } = window.__bootstrap.tty;
|
||||||
const LF = "\n".charCodeAt(0);
|
const LF = "\n".charCodeAt(0);
|
||||||
|
const CR = "\r".charCodeAt(0);
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
|
||||||
|
@ -50,7 +51,20 @@
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const n = stdin.readSync(c);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
buf.push(c[0]);
|
buf.push(c[0]);
|
||||||
|
|
|
@ -12,6 +12,10 @@ const answer2 = confirm("Question 2"); // Answer with yes (returns false)
|
||||||
console.log(`Your answer is ${answer2}`);
|
console.log(`Your answer is ${answer2}`);
|
||||||
const answer3 = confirm(); // Answer with default
|
const answer3 = confirm(); // Answer with default
|
||||||
console.log(`Your answer is ${answer3}`);
|
console.log(`Your answer is ${answer3}`);
|
||||||
|
const windows = prompt("What is Windows EOL?");
|
||||||
|
console.log(`Your answer is ${JSON.stringify(windows)}`);
|
||||||
alert("Hi");
|
alert("Hi");
|
||||||
alert();
|
alert();
|
||||||
console.log("The end of test");
|
console.log("The end of test");
|
||||||
|
const eof = prompt("What is EOF?");
|
||||||
|
console.log(`Your answer is ${JSON.stringify(eof)}`);
|
||||||
|
|
|
@ -5,4 +5,6 @@ Question 0 [y/N] Your answer is true
|
||||||
Question 1 [y/N] Your answer is false
|
Question 1 [y/N] Your answer is false
|
||||||
Question 2 [y/N] Your answer is false
|
Question 2 [y/N] Your answer is false
|
||||||
Confirm [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
|
Hi [Enter] Alert [Enter] The end of test
|
||||||
|
What is EOF? Your answer is null
|
||||||
|
|
|
@ -2185,7 +2185,7 @@ fn _066_prompt() {
|
||||||
let args = "run --unstable 066_prompt.ts";
|
let args = "run --unstable 066_prompt.ts";
|
||||||
let output = "066_prompt.ts.out";
|
let output = "066_prompt.ts.out";
|
||||||
// These are answers to prompt, confirm, and alert calls.
|
// 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);
|
util::test_pty(args, output, input);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue