Skip to content

Commit 4ec67ad

Browse files
fix: fix note box width with Chinese word #115
1 parent 593f93d commit 4ec67ad

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/prompts/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ export const groupMultiselect = <Options extends Option<Value>[], Value>(
532532
};
533533

534534
const strip = (str: string) => str.replace(ansiRegex(), '');
535+
const strLength = (str: string) => {
536+
let len = 0;
537+
const arr = [...str];
538+
for (const char of arr) {
539+
len += char.charCodeAt(0) > 127 || char.charCodeAt(0) === 94 ? 2 : 1;
540+
}
541+
return len;
542+
};
535543
export const note = (message = '', title = '') => {
536544
const lines = `\n${message}\n`.split('\n');
537545
const len =
@@ -540,7 +548,7 @@ export const note = (message = '', title = '') => {
540548
ln = strip(ln);
541549
return ln.length > sum ? ln.length : sum;
542550
}, 0),
543-
strip(title).length
551+
strLength(strip(title))
544552
) + 2;
545553
const msg = lines
546554
.map(
@@ -552,7 +560,7 @@ export const note = (message = '', title = '') => {
552560
.join('\n');
553561
process.stdout.write(
554562
`${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
563+
S_BAR_H.repeat(Math.max(len - strLength(title) - 1, 1)) + S_CORNER_TOP_RIGHT
556564
)}\n${msg}\n${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n`
557565
);
558566
};

0 commit comments

Comments
 (0)