@@ -287,6 +287,14 @@ impl<'a> InteractivePrinter<'a> {
287287 }
288288 }
289289
290+ fn get_header_component_indent_length ( & self ) -> usize {
291+ if self . config . style_components . grid ( ) && self . panel_width > 0 {
292+ self . panel_width + 2
293+ } else {
294+ self . panel_width
295+ }
296+ }
297+
290298 fn print_header_component_indent ( & mut self , handle : & mut OutputHandle ) -> Result < ( ) > {
291299 if self . config . style_components . grid ( ) {
292300 write ! (
@@ -302,6 +310,30 @@ impl<'a> InteractivePrinter<'a> {
302310 }
303311 }
304312
313+ fn print_header_component_with_indent (
314+ & mut self ,
315+ handle : & mut OutputHandle ,
316+ content : & str ,
317+ ) -> Result < ( ) > {
318+ self . print_header_component_indent ( handle) ?;
319+ writeln ! ( handle, "{}" , content)
320+ }
321+
322+ fn print_header_multiline_component (
323+ & mut self ,
324+ handle : & mut OutputHandle ,
325+ content : & str ,
326+ ) -> Result < ( ) > {
327+ let mut content = content;
328+ let content_width = self . config . term_width - self . get_header_component_indent_length ( ) ;
329+ while content. len ( ) > content_width {
330+ let ( content_line, remaining) = content. split_at ( content_width) ;
331+ self . print_header_component_with_indent ( handle, content_line) ?;
332+ content = remaining;
333+ }
334+ self . print_header_component_with_indent ( handle, content)
335+ }
336+
305337 fn preprocess ( & self , text : & str , cursor : & mut usize ) -> String {
306338 if self . config . tab_width > 0 {
307339 return expand_tabs ( text, self . config . tab_width , cursor) ;
@@ -377,31 +409,32 @@ impl<'a> Printer for InteractivePrinter<'a> {
377409 }
378410 }
379411
380- header_components. iter ( ) . try_for_each ( |component| {
381- self . print_header_component_indent ( handle ) ? ;
382-
383- match component {
384- StyleComponent :: HeaderFilename => writeln ! (
385- handle ,
386- "{}{}{}" ,
387- description
388- . kind( )
389- . map ( |kind| format! ( "{}: " , kind ) )
390- . unwrap_or_else ( || "" . into ( ) ) ,
391- self . colors . header_value . paint ( description . title ( ) ) ,
392- mode
393- ) ,
394-
412+ header_components
413+ . iter ( )
414+ . try_for_each ( |component| match component {
415+ StyleComponent :: HeaderFilename => {
416+ let header_filename = format ! (
417+ "{}{}{}" ,
418+ description
419+ . kind ( )
420+ . map ( | kind| format! ( "{}: " , kind ) )
421+ . unwrap_or_else ( || "" . into ( ) ) ,
422+ self . colors . header_value . paint ( description . title ( ) ) ,
423+ mode
424+ ) ;
425+ self . print_header_multiline_component ( handle , & header_filename )
426+ }
395427 StyleComponent :: HeaderFilesize => {
396428 let bsize = metadata
397429 . size
398430 . map ( |s| format ! ( "{}" , ByteSize ( s) ) )
399431 . unwrap_or_else ( || "-" . into ( ) ) ;
400- writeln ! ( handle, "Size: {}" , self . colors. header_value. paint( bsize) )
432+ let header_filesize =
433+ format ! ( "Size: {}" , self . colors. header_value. paint( bsize) ) ;
434+ self . print_header_multiline_component ( handle, & header_filesize)
401435 }
402436 _ => Ok ( ( ) ) ,
403- }
404- } ) ?;
437+ } ) ?;
405438
406439 if self . config . style_components . grid ( ) {
407440 if self . content_type . map_or ( false , |c| c. is_text ( ) ) || self . config . show_nonprintable {
0 commit comments