diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-01-12 02:35:55 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-11 22:05:55 +0100 |
commit | 9268df5f3405103214b4e39d82e5ab1b465475a0 (patch) | |
tree | 76336155130a2e751a9509df370d0060020473ac /runtime/js | |
parent | d8f86c8b9cf327db4d246c20cf60467cafe2ba64 (diff) |
fix(web): use rustyline for prompt (#21893)
Workaround until https://github.com/kkawakam/rustyline/pull/759
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/41_prompt.js | 18 |
1 files changed, 7 insertions, 11 deletions
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() { |