mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
fix(web): use rustyline for prompt (#21893)
Workaround until https://github.com/kkawakam/rustyline/pull/759
This commit is contained in:
parent
d8f86c8b9c
commit
9268df5f34
8 changed files with 56 additions and 24 deletions
|
@ -9,6 +9,8 @@ const {
|
|||
import { isatty } from "ext:runtime/40_tty.js";
|
||||
import { stdin } from "ext:deno_io/12_io.js";
|
||||
|
||||
const ops = core.ops;
|
||||
|
||||
const LF = StringPrototypeCharCodeAt("\n", 0);
|
||||
const CR = StringPrototypeCharCodeAt("\r", 0);
|
||||
|
||||
|
@ -35,22 +37,16 @@ function confirm(message = "Confirm") {
|
|||
}
|
||||
|
||||
function prompt(message = "Prompt", defaultValue) {
|
||||
defaultValue ??= null;
|
||||
defaultValue ??= "";
|
||||
|
||||
if (!isatty(stdin.rid)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (defaultValue) {
|
||||
message += ` [${defaultValue}]`;
|
||||
}
|
||||
|
||||
message += " ";
|
||||
|
||||
// output in one shot to make the tests more reliable
|
||||
core.print(message, false);
|
||||
|
||||
return readLineFromStdinSync() || defaultValue;
|
||||
return ops.op_read_line_prompt(
|
||||
`${message} `,
|
||||
`${defaultValue}`,
|
||||
);
|
||||
}
|
||||
|
||||
function readLineFromStdinSync() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue