fix(web): use rustyline for prompt (#21893)

Workaround until https://github.com/kkawakam/rustyline/pull/759
This commit is contained in:
Divy Srivastava 2024-01-12 02:35:55 +05:30 committed by GitHub
parent d8f86c8b9c
commit 9268df5f34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 24 deletions

View file

@ -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() {