* 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:
Maxim Zhiburt 2022-11-17 16:51:04 +03:00 committed by GitHub
parent 8e4b85e29b
commit 1784b4bf50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -990,11 +990,14 @@ fn convert_to_table2<'a>(
} }
if available_width == 0 || available_width <= nessary_space { 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; break;
} }
available_width = available_width.saturating_sub(nessary_space); available_width -= nessary_space;
let mut column_width = string_width(&header); 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 value = NuTable::create_cell(value.0, value.1);
let row = row + 1; data[row + 1].push(value);
data[row].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 // so we try to do soft landing
// by doing a truncating in case there will be enough space for it. // 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 value = NuTable::create_cell(value.0, value.1);
let row = row + 1; *data[row + 1].last_mut().expect("unwrap") = value;
*data[row].last_mut().expect("unwrap") = value;
} }
} }
@ -1080,22 +1083,28 @@ fn convert_to_table2<'a>(
let value = NuTable::create_cell(value.0, value.1); let value = NuTable::create_cell(value.0, value.1);
let row = row + 1; *data[row + 1].last_mut().expect("unwrap") = value;
*data[row].last_mut().expect("unwrap") = value;
} }
} }
if column_width > available_width { if column_width > available_width {
// remove just added column
for row in &mut data {
row.pop();
}
available_width += nessary_space;
truncate = true; truncate = true;
break; break;
} }
available_width = available_width.saturating_sub(column_width); available_width -= column_width;
widths.push(column_width); widths.push(column_width);
} }
if truncate { if truncate {
if available_width > TRUNCATE_CELL_WIDTH + PADDING_SPACE { if available_width <= TRUNCATE_CELL_WIDTH + PADDING_SPACE {
// back up by removing last column. // back up by removing last column.
// it's ALWAYS MUST has us enough space for a shift column // it's ALWAYS MUST has us enough space for a shift column
while let Some(width) = widths.pop() { while let Some(width) = widths.pop() {
@ -1103,9 +1112,9 @@ fn convert_to_table2<'a>(
row.pop(); 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; break;
} }
} }