@@ -26,13 +26,14 @@ export function formatTasks(format: TaskFormat, tasks: Iterable<Task>, defaultTa
2626 } ) ;
2727
2828 // There's a 2 space indent plus 3 spaces between columns, hence take away 5
29- // padding spaces from the available width
30- const maxTotalWidth = columns - 5 ;
31- const maxNameWidth = Math . max ( ...names . map ( visibleLength ) ) ;
29+ // padding spaces from the available width. Keep widths positive so narrow
30+ // terminals still wrap safely.
31+ const maxTotalWidth = Math . max ( 1 , columns - 5 ) ;
32+ const maxNameWidth = Math . max ( 1 , ...names . map ( visibleLength ) ) ;
3233
3334 // Check the name doesn't take up more than half the space
34- const nameWidth = Math . min ( maxNameWidth , maxTotalWidth >> 1 ) ;
35- const descriptionWidth = maxTotalWidth - nameWidth ;
35+ const nameWidth = Math . min ( maxNameWidth , Math . max ( 1 , maxTotalWidth >> 1 ) ) ;
36+ const descriptionWidth = Math . max ( 1 , maxTotalWidth - nameWidth ) ;
3637 const formatted = names . map ( ( name , i ) => formatAsColumns ( " " , name , nameWidth , descriptions [ i ] , descriptionWidth ) ) ;
3738
3839 return `
@@ -76,6 +77,7 @@ const TOKEN_REGEX = /[^\s-]+?-\b|\S+|\s+/g;
7677
7778function wrapText ( text : string , maxWidth : number ) : string [ ] {
7879 const result : string [ ] = [ ] ;
80+ maxWidth = Math . max ( 1 , maxWidth ) ;
7981 for ( const line of text . split ( / \r ? \n / ) ) {
8082 let current = "" ;
8183 for ( const token of line . match ( TOKEN_REGEX ) ?? [ ] ) {
0 commit comments