@@ -26,8 +26,8 @@ pub fn one_line(metas: Vec<Meta>, flags: Flags, colors: &Colors, icons: &Icons)
2626
2727pub fn grid ( metas : Vec < Meta > , flags : Flags , colors : & Colors , icons : & Icons ) -> String {
2828 let term_width = match terminal_size ( ) {
29- Some ( ( w, _) ) => w. 0 as usize ,
30- None => panic ! ( "failed to retrieve terminal size" ) ,
29+ Some ( ( w, _) ) => Some ( w. 0 as usize ) ,
30+ None => None ,
3131 } ;
3232
3333 inner_display_grid ( metas, flags, colors, icons, 0 , term_width)
@@ -99,7 +99,7 @@ fn inner_display_grid(
9999 colors : & Colors ,
100100 icons : & Icons ,
101101 depth : usize ,
102- term_width : usize ,
102+ term_width : Option < usize > ,
103103) -> String {
104104 let mut output = String :: new ( ) ;
105105
@@ -124,12 +124,16 @@ fn inner_display_grid(
124124 } ) ;
125125 }
126126
127- if let Some ( gridded_output) = grid. fit_into_width ( term_width) {
128- output += & gridded_output. to_string ( ) ;
127+ if let Some ( tw) = term_width {
128+ if let Some ( gridded_output) = grid. fit_into_width ( tw) {
129+ output += & gridded_output. to_string ( ) ;
130+ } else {
131+ //does not fit into grid, usually because (some) filename(s)
132+ //are longer or almost as long as term_width
133+ //print line by line instead!
134+ output += & grid. fit_into_columns ( 1 ) . to_string ( ) ;
135+ }
129136 } else {
130- //does not fit into grid, usually because (some) filename(s)
131- //are longer or almost as long as term_width
132- //print line by line instead!
133137 output += & grid. fit_into_columns ( 1 ) . to_string ( ) ;
134138 }
135139
0 commit comments