@@ -33,30 +33,29 @@ where
3333 }
3434 }
3535
36- for ( index, header) in headers. iter ( ) . enumerate ( ) {
36+ for ( index, ( header, width ) ) in headers. iter ( ) . zip ( column_widths . iter ( ) ) . enumerate ( ) {
3737 if index > 0 {
3838 output. push_str ( " " ) ;
3939 }
4040 let header = header. as_ref ( ) ;
4141 output. push_str ( header) ;
42- // Add padding only if this is NOT the final column
4342 if index < headers. len ( ) - 1 {
44- let padding = column_widths [ index ] - header. len ( ) ;
43+ let padding = width - header. len ( ) ;
4544 if padding > 0 {
4645 output. push_str ( & " " . repeat ( padding) ) ;
4746 }
4847 }
4948 }
5049 output. push ( '\n' ) ;
5150
52- for ( index, header) in headers. iter ( ) . enumerate ( ) {
51+ for ( index, ( header, width ) ) in headers. iter ( ) . zip ( column_widths . iter ( ) ) . enumerate ( ) {
5352 if index > 0 {
5453 output. push_str ( " " ) ;
5554 }
5655 let header = header. as_ref ( ) ;
5756 output. push_str ( & "-" . repeat ( header. len ( ) ) ) ;
5857 if index < headers. len ( ) - 1 {
59- let padding = column_widths [ index ] - header. len ( ) ;
58+ let padding = width - header. len ( ) ;
6059 if padding > 0 {
6160 output. push_str ( & " " . repeat ( padding) ) ;
6261 }
@@ -65,14 +64,14 @@ where
6564 output. push ( '\n' ) ;
6665
6766 for row in data. as_ref ( ) {
68- for ( index, cell) in row. as_ref ( ) . iter ( ) . enumerate ( ) {
67+ for ( index, ( cell, width ) ) in row. as_ref ( ) . iter ( ) . zip ( column_widths . iter ( ) ) . enumerate ( ) {
6968 if index > 0 {
7069 output. push_str ( " " ) ;
7170 }
7271 let cell = cell. as_ref ( ) ;
7372 output. push_str ( cell) ;
7473 if index < headers. len ( ) - 1 {
75- let padding = column_widths [ index ] - cell. len ( ) ;
74+ let padding = width - cell. len ( ) ;
7675 if padding > 0 {
7776 output. push_str ( & " " . repeat ( padding) ) ;
7877 }
0 commit comments