11import process from 'node:process' ;
22import type { Writable } from 'node:stream' ;
33import { stripVTControlCharacters as strip } from 'node:util' ;
4+ import { getColumns } from '@clack/core' ;
45import { wrapAnsi } from 'fast-wrap-ansi' ;
56import color from 'picocolors' ;
67import {
@@ -13,13 +14,14 @@ import {
1314 S_STEP_SUBMIT ,
1415} from './common.js' ;
1516
17+ type FormatFn = ( line : string ) => string ;
1618export interface NoteOptions extends CommonOptions {
17- format ?: ( line : string ) => string ;
19+ format ?: FormatFn ;
1820}
1921
2022const defaultNoteFormatter = ( line : string ) : string => color . dim ( line ) ;
2123
22- const wrapWithFormat = ( message : string , width : number , format : NoteOptions [ 'format' ] ) : string => {
24+ const wrapWithFormat = ( message : string , width : number , format : FormatFn ) : string => {
2325 const wrapMsg = wrapAnsi ( message , width ) . split ( '\n' ) ;
2426 const maxWidthNormal = wrapMsg . reduce ( ( sum , ln ) => Math . max ( strip ( ln ) . length , sum ) , 0 ) ;
2527 const maxWidthFormat = wrapMsg
@@ -32,7 +34,7 @@ const wrapWithFormat = (message: string, width: number, format: NoteOptions['for
3234export const note = ( message = '' , title = '' , opts ?: NoteOptions ) => {
3335 const output : Writable = opts ?. output ?? process . stdout ;
3436 const format = opts ?. format ?? defaultNoteFormatter ;
35- const wrapMsg = wrapWithFormat ( message , output . columns - 6 , format ) ;
37+ const wrapMsg = wrapWithFormat ( message , getColumns ( output ) - 6 , format ) ;
3638 const lines = [ '' , ...wrapMsg . split ( '\n' ) . map ( format ) , '' ] ;
3739 const titleLen = strip ( title ) . length ;
3840 const len =
0 commit comments