Skip to content

Commit ea27a1f

Browse files
author
InAnYan
committed
Possible fix to format_tools
1 parent 9000678 commit ea27a1f

File tree

1 file changed

+13
-2
lines changed
  • module/core/format_tools/src/format/output_format

1 file changed

+13
-2
lines changed

module/core/format_tools/src/format/output_format/table.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,19 @@ impl TableOutputFormat for Table
248248
write!( c.buf, "{}", cell_prefix )?;
249249

250250
println!( "icol : {icol} | irow : {irow} | width : {width} | cell_width : {cell_width} | slice.len() : {}", slice.len() );
251-
let lspaces = ( width - cell_width ) / 2;
252-
let rspaces = ( width - cell_width + 1 ) / 2 + cell_width - slice.len();
251+
252+
let lspaces = if cell_width > width {
253+
0
254+
} else {
255+
( width - cell_width ) / 2
256+
};
257+
258+
let rspaces = if (cell_width > width) || (slice.len() > cell_width) {
259+
0
260+
} else {
261+
( width - cell_width + 1 ) / 2 + cell_width - slice.len()
262+
};
263+
253264
// println!( "icol : {icol} | irow : {irow} | width : {width} | cell_width : {cell_width} | lspaces : {lspaces} | rspaces : {rspaces}" );
254265

255266
if lspaces > 0

0 commit comments

Comments
 (0)