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 , type Options as WrapAnsiOptions } 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 opts : WrapAnsiOptions = {
2426 hard : true ,
2527 trim : false ,
@@ -35,9 +37,9 @@ const wrapWithFormat = (message: string, width: number, format: NoteOptions['for
3537
3638export const note = ( message = '' , title = '' , opts ?: NoteOptions ) => {
3739 const output : Writable = opts ?. output ?? process . stdout ;
38- const format = ( ln ) => opts ?. format ?.( ln ) ?? defaultNoteFormatter ( ln ) ;
39- const wrapMsg = wrapWithFormat ( message , output . columns - 6 , format ) ;
40- const lines = [ '' , ...wrapMsg . split ( '\n' ) . map ( format ) , '' ] ;
40+ const format = ( ln ) => opts ?. format ?.( ln ) ?? defaultNoteFormatter ( ln ) ;
41+ const wrapMsg = wrapWithFormat ( message , getColumns ( output ) - 6 , format ) ;
42+ const lines = [ '' , ...wrapMsg . split ( '\n' ) . map ( format ) , '' ] ;
4143 const titleLen = strip ( title ) . length ;
4244 const len =
4345 Math . max (
0 commit comments