Skip to content

Commit

Permalink
improve multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech committed Dec 30, 2024
1 parent d77c516 commit 4c9294c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 8 additions & 6 deletions cli/prompt_secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

Expand Down
2 changes: 0 additions & 2 deletions cli/prompt_secret_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ Deno.test("promptSecret() wraps characters wider than console columns", () => {
"? **",
"\r\x1b[K",
"? ***",
"\r\x1b[K",
"*",
"\r\x1b[K",
"**",
Expand All @@ -582,7 +581,6 @@ Deno.test("promptSecret() wraps characters wider than console columns", () => {
"****",
"\r\x1b[K",
"*****",
"\r\x1b[K",
"*",
"\r\x1b[K",
"**",
Expand Down

0 comments on commit 4c9294c

Please sign in to comment.