From 4c9294cebdc0c7e071f2ffee92fb4c86645eb9ac Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Mon, 30 Dec 2024 14:10:13 -0500 Subject: [PATCH] improve multiline --- cli/prompt_secret.ts | 14 ++++++++------ cli/prompt_secret_test.ts | 2 -- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/prompt_secret.ts b/cli/prompt_secret.ts index 2e9fbfa4c9cb..65bec9380537 100644 --- a/cli/prompt_secret.ts +++ b/cli/prompt_secret.ts @@ -59,15 +59,17 @@ export function promptSecret( const callback = !mask ? undefined : (n: number) => { let line = `${message}${mask.repeat(n)}`; - let charsPastLineLength = line.length % columns; + const charsPastLineLength = line.length % columns; if (line.length > columns) { - if (charsPastLineLength === 0) { - charsPastLineLength = columns; - } - line = line.slice(-1 * charsPastLineLength); + line = line.slice( + -1 * (charsPastLineLength === 0 ? columns : charsPastLineLength), + ); + } + // Always jump the cursor back to the beginning of the line unless it's the first character. + if (charsPastLineLength !== 1) { + output.writeSync(CLR); } - output.writeSync(CLR); output.writeSync(encoder.encode(line)); }; diff --git a/cli/prompt_secret_test.ts b/cli/prompt_secret_test.ts index ba362aafcc67..1b566384ca7b 100644 --- a/cli/prompt_secret_test.ts +++ b/cli/prompt_secret_test.ts @@ -572,7 +572,6 @@ Deno.test("promptSecret() wraps characters wider than console columns", () => { "? **", "\r\x1b[K", "? ***", - "\r\x1b[K", "*", "\r\x1b[K", "**", @@ -582,7 +581,6 @@ Deno.test("promptSecret() wraps characters wider than console columns", () => { "****", "\r\x1b[K", "*****", - "\r\x1b[K", "*", "\r\x1b[K", "**",