From 9268df5f3405103214b4e39d82e5ab1b465475a0 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 12 Jan 2024 02:35:55 +0530 Subject: fix(web): use rustyline for prompt (#21893) Workaround until https://github.com/kkawakam/rustyline/pull/759 --- runtime/js/41_prompt.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'runtime/js') diff --git a/runtime/js/41_prompt.js b/runtime/js/41_prompt.js index 4e2f0fffc..e9f10e244 100644 --- a/runtime/js/41_prompt.js +++ b/runtime/js/41_prompt.js @@ -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() { -- cgit v1.2.3