@@ -10,6 +10,8 @@ import {
1010 S_CORNER_TOP_RIGHT ,
1111 S_STEP_SUBMIT ,
1212} from './common.js' ;
13+ import { wrapAnsi } from "fast-wrap-ansi" ;
14+ import process from "node:process" ;
1315
1416export interface NoteOptions extends CommonOptions {
1517 format ?: ( line : string ) => string ;
@@ -18,26 +20,23 @@ export interface NoteOptions extends CommonOptions {
1820const defaultNoteFormatter = ( line : string ) : string => color . dim ( line ) ;
1921
2022export const note = ( message = '' , title = '' , opts ?: NoteOptions ) => {
21- const format = opts ?. format ?? defaultNoteFormatter ;
22- const lines = [ '' , ...message . split ( '\n' ) . map ( format ) , '' ] ;
23- const titleLen = strip ( title ) . length ;
24- const output : Writable = opts ?. output ?? process . stdout ;
25- const len =
26- Math . max (
27- lines . reduce ( ( sum , ln ) => {
28- const line = strip ( ln ) ;
29- return line . length > sum ? line . length : sum ;
30- } , 0 ) ,
31- titleLen
32- ) + 2 ;
33- const msg = lines
34- . map (
35- ( ln ) => `${ color . gray ( S_BAR ) } ${ ln } ${ ' ' . repeat ( len - strip ( ln ) . length ) } ${ color . gray ( S_BAR ) } `
36- )
37- . join ( '\n' ) ;
38- output . write (
39- `${ color . gray ( S_BAR ) } \n${ color . green ( S_STEP_SUBMIT ) } ${ color . reset ( title ) } ${ color . gray (
40- S_BAR_H . repeat ( Math . max ( len - titleLen - 1 , 1 ) ) + S_CORNER_TOP_RIGHT
41- ) } \n${ msg } \n${ color . gray ( S_CONNECT_LEFT + S_BAR_H . repeat ( len + 2 ) + S_CORNER_BOTTOM_RIGHT ) } \n`
42- ) ;
23+ const output : Writable = opts ?. output ?? process . stdout ;
24+ const format = opts ?. format ?? defaultNoteFormatter ;
25+ const wrapMsg = wrapAnsi ( `\n${ message } \n` , process . stdout . columns - 6 ) ;
26+ const titleLen = strip ( title ) . length ;
27+ const lines = wrapMsg . split ( '\n' ) ;
28+ const len = Math . max (
29+ lines . reduce ( ( sum , ln ) => {
30+ const line = strip ( ln ) ;
31+ return line . length > sum ? line . length : sum ;
32+ } , 0 ) ,
33+ titleLen
34+ ) ;
35+ const header = `${ color . green ( S_STEP_SUBMIT ) } ${ color . reset ( title ) } ${ color . gray ( S_BAR_H . repeat ( len - titleLen + 1 ) + S_CORNER_TOP_RIGHT ) } ` ;
36+ const noteLines = lines . map (
37+ ( line ) =>
38+ `${ color . gray ( S_BAR ) } ${ format ( line ) } ${ ' ' . repeat ( len - strip ( line ) . length + 2 ) } ${ color . gray ( S_BAR ) } `
39+ ) ;
40+ const footer = `${ color . gray ( S_CONNECT_LEFT + S_BAR_H . repeat ( len + 4 ) + S_CORNER_BOTTOM_RIGHT ) } ` ;
41+ output . write ( `${ color . gray ( S_BAR ) } \n${ header } \n${ noteLines . join ( '\n' ) } \n${ footer } \n` ) ;
4342} ;
0 commit comments