11import process from 'node:process' ;
22import type { Writable } from 'node:stream' ;
33import { stripVTControlCharacters as strip } from 'node:util' ;
4- import { wrapAnsi } from 'fast-wrap-ansi' ;
4+ import { wrapAnsi , type Options as WrapAnsiOptions } from 'fast-wrap-ansi' ;
55import color from 'picocolors' ;
66import {
77 type CommonOptions ,
@@ -20,18 +20,22 @@ export interface NoteOptions extends CommonOptions {
2020const defaultNoteFormatter = ( line : string ) : string => color . dim ( line ) ;
2121
2222const wrapWithFormat = ( message : string , width : number , format : NoteOptions [ 'format' ] ) : string => {
23- const wrapMsg = wrapAnsi ( message , width ) . split ( '\n' ) ;
23+ const opts : WrapAnsiOptions = {
24+ hard : true ,
25+ trim : false ,
26+ } ;
27+ const wrapMsg = wrapAnsi ( message , width , opts ) . split ( '\n' ) ;
2428 const maxWidthNormal = wrapMsg . reduce ( ( sum , ln ) => Math . max ( strip ( ln ) . length , sum ) , 0 ) ;
2529 const maxWidthFormat = wrapMsg
2630 . map ( format )
2731 . reduce ( ( sum , ln ) => Math . max ( strip ( ln ) . length , sum ) , 0 ) ;
2832 const wrapWidth = width - ( maxWidthFormat - maxWidthNormal ) ;
29- return wrapAnsi ( message , wrapWidth ) ;
33+ return wrapAnsi ( message , wrapWidth , opts ) ;
3034} ;
3135
3236export const note = ( message = '' , title = '' , opts ?: NoteOptions ) => {
3337 const output : Writable = opts ?. output ?? process . stdout ;
34- const format = opts ?. format ?? defaultNoteFormatter ;
38+ const format = ( ln ) => opts ?. format ?. ( ln ) ?? defaultNoteFormatter ( ln ) ;
3539 const wrapMsg = wrapWithFormat ( message , output . columns - 6 , format ) ;
3640 const lines = [ '' , ...wrapMsg . split ( '\n' ) . map ( format ) , '' ] ;
3741 const titleLen = strip ( title ) . length ;
0 commit comments