forked from extern/nushell
* fix #7145 Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Improve fix Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
parent
8e4b85e29b
commit
1784b4bf50
@ -990,11 +990,14 @@ fn convert_to_table2<'a>(
|
||||
}
|
||||
|
||||
if available_width == 0 || available_width <= nessary_space {
|
||||
// we don't do truncate here or anything like it cause we know that
|
||||
// MUST NEVER HAPPEN (ideally)
|
||||
// but it does...
|
||||
|
||||
truncate = true;
|
||||
break;
|
||||
}
|
||||
|
||||
available_width = available_width.saturating_sub(nessary_space);
|
||||
available_width -= nessary_space;
|
||||
|
||||
let mut column_width = string_width(&header);
|
||||
|
||||
@ -1030,11 +1033,12 @@ fn convert_to_table2<'a>(
|
||||
|
||||
let value = NuTable::create_cell(value.0, value.1);
|
||||
|
||||
let row = row + 1;
|
||||
data[row].push(value);
|
||||
data[row + 1].push(value);
|
||||
}
|
||||
|
||||
if column_width >= available_width {
|
||||
if column_width >= available_width
|
||||
|| (!is_last_col && column_width + nessary_space >= available_width)
|
||||
{
|
||||
// so we try to do soft landing
|
||||
// by doing a truncating in case there will be enough space for it.
|
||||
|
||||
@ -1055,8 +1059,7 @@ fn convert_to_table2<'a>(
|
||||
|
||||
let value = NuTable::create_cell(value.0, value.1);
|
||||
|
||||
let row = row + 1;
|
||||
*data[row].last_mut().expect("unwrap") = value;
|
||||
*data[row + 1].last_mut().expect("unwrap") = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1080,22 +1083,28 @@ fn convert_to_table2<'a>(
|
||||
|
||||
let value = NuTable::create_cell(value.0, value.1);
|
||||
|
||||
let row = row + 1;
|
||||
*data[row].last_mut().expect("unwrap") = value;
|
||||
*data[row + 1].last_mut().expect("unwrap") = value;
|
||||
}
|
||||
}
|
||||
|
||||
if column_width > available_width {
|
||||
// remove just added column
|
||||
for row in &mut data {
|
||||
row.pop();
|
||||
}
|
||||
|
||||
available_width += nessary_space;
|
||||
|
||||
truncate = true;
|
||||
break;
|
||||
}
|
||||
|
||||
available_width = available_width.saturating_sub(column_width);
|
||||
available_width -= column_width;
|
||||
widths.push(column_width);
|
||||
}
|
||||
|
||||
if truncate {
|
||||
if available_width > TRUNCATE_CELL_WIDTH + PADDING_SPACE {
|
||||
if available_width <= TRUNCATE_CELL_WIDTH + PADDING_SPACE {
|
||||
// back up by removing last column.
|
||||
// it's ALWAYS MUST has us enough space for a shift column
|
||||
while let Some(width) = widths.pop() {
|
||||
@ -1103,9 +1112,9 @@ fn convert_to_table2<'a>(
|
||||
row.pop();
|
||||
}
|
||||
|
||||
available_width += width;
|
||||
available_width += width + PADDING_SPACE + SPLIT_LINE_SPACE;
|
||||
|
||||
if available_width >= TRUNCATE_CELL_WIDTH + PADDING_SPACE {
|
||||
if available_width > TRUNCATE_CELL_WIDTH + PADDING_SPACE {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user