[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

fix(@clack/prompts): note title correctly evaluates title length with ansi (#119)

authored by

Christian Preston and committed by
GitHub
(Aug 9, 2023, 9:34 AM EDT) 9d9828b0 8eff6ced

+8 -2
+5
.changeset/odd-avocados-smile.md
··· 1 + --- 2 + '@clack/prompts': patch 3 + --- 4 + 5 + Fixes cases where the note title length was miscalculated due to ansi characters
+3 -2
packages/prompts/src/index.ts
··· 566 566 const strip = (str: string) => str.replace(ansiRegex(), ''); 567 567 export const note = (message = '', title = '') => { 568 568 const lines = `\n${message}\n`.split('\n'); 569 + const titleLen = strip(title).length; 569 570 const len = 570 571 Math.max( 571 572 lines.reduce((sum, ln) => { 572 573 ln = strip(ln); 573 574 return ln.length > sum ? ln.length : sum; 574 575 }, 0), 575 - strip(title).length 576 + titleLen 576 577 ) + 2; 577 578 const msg = lines 578 579 .map( ··· 584 585 .join('\n'); 585 586 process.stdout.write( 586 587 `${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 588 589 )}\n${msg}\n${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n` 589 590 ); 590 591 };