Skip to content

Commit ab51d29

Browse files
authored
fix: note title correctly evaluates title length with ansi
1 parent 593f93d commit ab51d29

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changeset/odd-avocados-smile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clack/prompts': patch
3+
---
4+
5+
Fixes cases where the note title length was miscalculated due to ansi characters

packages/prompts/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,14 @@ export const groupMultiselect = <Options extends Option<Value>[], Value>(
534534
const strip = (str: string) => str.replace(ansiRegex(), '');
535535
export const note = (message = '', title = '') => {
536536
const lines = `\n${message}\n`.split('\n');
537+
const titleLen = strip(title).length;
537538
const len =
538539
Math.max(
539540
lines.reduce((sum, ln) => {
540541
ln = strip(ln);
541542
return ln.length > sum ? ln.length : sum;
542543
}, 0),
543-
strip(title).length
544+
titleLen
544545
) + 2;
545546
const msg = lines
546547
.map(
@@ -552,7 +553,7 @@ export const note = (message = '', title = '') => {
552553
.join('\n');
553554
process.stdout.write(
554555
`${color.gray(S_BAR)}\n${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray(
555-
S_BAR_H.repeat(Math.max(len - title.length - 1, 1)) + S_CORNER_TOP_RIGHT
556+
S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT
556557
)}\n${msg}\n${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n`
557558
);
558559
};

0 commit comments

Comments
 (0)