Skip to content

Commit 9d9828b

Browse files
authored
fix(@clack/prompts): note title correctly evaluates title length with ansi (#119)
2 parents 8eff6ce + ab51d29 commit 9d9828b

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
@@ -566,13 +566,14 @@ export const groupMultiselect = <Options extends Option<Value>[], Value>(
566566
const strip = (str: string) => str.replace(ansiRegex(), '');
567567
export const note = (message = '', title = '') => {
568568
const lines = `\n${message}\n`.split('\n');
569+
const titleLen = strip(title).length;
569570
const len =
570571
Math.max(
571572
lines.reduce((sum, ln) => {
572573
ln = strip(ln);
573574
return ln.length > sum ? ln.length : sum;
574575
}, 0),
575-
strip(title).length
576+
titleLen
576577
) + 2;
577578
const msg = lines
578579
.map(
@@ -584,7 +585,7 @@ export const note = (message = '', title = '') => {
584585
.join('\n');
585586
process.stdout.write(
586587
`${color.gray(S_BAR)}\n${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray(
587-
S_BAR_H.repeat(Math.max(len - title.length - 1, 1)) + S_CORNER_TOP_RIGHT
588+
S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT
588589
)}\n${msg}\n${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n`
589590
);
590591
};

0 commit comments

Comments
 (0)