@@ -142,7 +142,7 @@ function wrapRow(cells: TableCell[], columnWidths: number[]): TableCell[][] {
142142 const wrapped : string = wrapText ( cell . text , columnWidths [ colIndex ] ) ;
143143 const lines = wrapped . split ( '\n' ) . filter ( Boolean ) ;
144144
145- const rowCount = Math . max ( acc . length , lines . length ) ;
145+ const rowCount = Math . max ( acc . length , lines . length , 1 ) ;
146146
147147 return Array . from ( { length : rowCount } ) . map ( ( _ , rowIndex ) => {
148148 const prevCols =
@@ -154,7 +154,7 @@ function wrapRow(cells: TableCell[], columnWidths: number[]): TableCell[][] {
154154}
155155
156156function wrapText ( text : string , width : number | undefined ) : string {
157- if ( ! width || stringWidth ( text ) <= width ) {
157+ if ( ! width || getTextWidth ( text ) <= width ) {
158158 return text ;
159159 }
160160 const words = extractWords ( text ) ;
@@ -173,6 +173,10 @@ function wrapText(text: string, width: number | undefined): string {
173173 return wrapAnsi ( textWithSplitLongWords , width ) ;
174174}
175175
176+ function getTextWidth ( text : string ) : number {
177+ return Math . max ( ...text . split ( '\n' ) . map ( line => stringWidth ( line ) ) ) ;
178+ }
179+
176180function extractWords ( text : string ) : string [ ] {
177181 return ansis
178182 . strip ( text )
@@ -234,7 +238,7 @@ function getColumnTexts(table: NormalizedTable): string[][] {
234238
235239function aggregateColumnsStats ( columnTexts : string [ ] [ ] ) : ColumnStats [ ] {
236240 return columnTexts . map ( texts => {
237- const widths = texts . map ( text => stringWidth ( text ) ) ;
241+ const widths = texts . map ( getTextWidth ) ;
238242 const longestWords = texts
239243 . flatMap ( extractWords )
240244 . toSorted ( ( a , b ) => b . length - a . length ) ;
0 commit comments