Skip to content

Commit

Permalink
fix: fix note box width with Chinese word bombshell-dev#115
Browse files Browse the repository at this point in the history
  • Loading branch information
zouhangwithsweet committed Apr 11, 2023
1 parent 593f93d commit bf2af4f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/prompts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ export const groupMultiselect = <Options extends Option<Value>[], Value>(
};

const strip = (str: string) => str.replace(ansiRegex(), '');
const strLength = (str: string) => {
let len = 0;
const arr = [...str];
for (const char of arr) {
len += char.charCodeAt(0) > 127 || char.charCodeAt(0) === 94 ? 2 : 1;
}
return len;
};
export const note = (message = '', title = '') => {
const lines = `\n${message}\n`.split('\n');
const len =
Expand All @@ -552,7 +560,7 @@ export const note = (message = '', title = '') => {
.join('\n');
process.stdout.write(
`${color.gray(S_BAR)}\n${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray(
S_BAR_H.repeat(Math.max(len - title.length - 1, 1)) + S_CORNER_TOP_RIGHT
S_BAR_H.repeat(Math.max(len - strLength(title) - 1, 1)) + S_CORNER_TOP_RIGHT
)}\n${msg}\n${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n`
);
};
Expand Down

0 comments on commit bf2af4f

Please sign in to comment.