11import process from 'node:process' ;
22import type { Writable } from 'node:stream' ;
3- import { stripVTControlCharacters as strip } from 'node:util' ;
43import { getColumns } from '@clack/core' ;
54import { type Options as WrapAnsiOptions , wrapAnsi } from 'fast-wrap-ansi' ;
65import color from 'picocolors' ;
@@ -13,6 +12,7 @@ import {
1312 S_CORNER_TOP_RIGHT ,
1413 S_STEP_SUBMIT ,
1514} from './common.js' ;
15+ import stringWidth from "fast-string-width" ;
1616
1717type FormatFn = ( line : string ) => string ;
1818export interface NoteOptions extends CommonOptions {
@@ -27,10 +27,10 @@ const wrapWithFormat = (message: string, width: number, format: FormatFn): strin
2727 trim : false ,
2828 } ;
2929 const wrapMsg = wrapAnsi ( message , width , opts ) . split ( '\n' ) ;
30- const maxWidthNormal = wrapMsg . reduce ( ( sum , ln ) => Math . max ( strip ( ln ) . length , sum ) , 0 ) ;
30+ const maxWidthNormal = wrapMsg . reduce ( ( sum , ln ) => Math . max ( stringWidth ( ln ) , sum ) , 0 ) ;
3131 const maxWidthFormat = wrapMsg
3232 . map ( format )
33- . reduce ( ( sum , ln ) => Math . max ( strip ( ln ) . length , sum ) , 0 ) ;
33+ . reduce ( ( sum , ln ) => Math . max ( stringWidth ( ln ) , sum ) , 0 ) ;
3434 const wrapWidth = width - ( maxWidthFormat - maxWidthNormal ) ;
3535 return wrapAnsi ( message , wrapWidth , opts ) ;
3636} ;
@@ -40,18 +40,18 @@ export const note = (message = '', title = '', opts?: NoteOptions) => {
4040 const format = opts ?. format ?? defaultNoteFormatter ;
4141 const wrapMsg = wrapWithFormat ( message , getColumns ( output ) - 6 , format ) ;
4242 const lines = [ '' , ...wrapMsg . split ( '\n' ) . map ( format ) , '' ] ;
43- const titleLen = strip ( title ) . length ;
43+ const titleLen = stringWidth ( title ) ;
4444 const len =
4545 Math . max (
4646 lines . reduce ( ( sum , ln ) => {
47- const line = strip ( ln ) ;
48- return line . length > sum ? line . length : sum ;
47+ const width = stringWidth ( ln ) ;
48+ return width > sum ? width : sum ;
4949 } , 0 ) ,
5050 titleLen
5151 ) + 2 ;
5252 const msg = lines
5353 . map (
54- ( ln ) => `${ color . gray ( S_BAR ) } ${ ln } ${ ' ' . repeat ( len - strip ( ln ) . length ) } ${ color . gray ( S_BAR ) } `
54+ ( ln ) => `${ color . gray ( S_BAR ) } ${ ln } ${ ' ' . repeat ( len - stringWidth ( ln ) ) } ${ color . gray ( S_BAR ) } `
5555 )
5656 . join ( '\n' ) ;
5757 output . write (
0 commit comments