nu-table/ Fix table --expand issue when table with no header involved (#8045)

close #8029

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt 2023-02-13 02:28:42 +03:00 committed by GitHub
parent 0f5ea16605
commit ccbdc9f6d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 499 additions and 21 deletions

View File

@ -1040,8 +1040,13 @@ fn convert_to_table2<'a>(
}
if !with_header {
if available_width >= ADDITIONAL_CELL_SPACE {
if available_width > ADDITIONAL_CELL_SPACE {
available_width -= PADDING_SPACE;
} else {
// it means we have no space left for actual content;
// which means there's no point in index itself if it was even used.
// so we do not print it.
return Ok(None);
}
for (row, item) in input.into_iter().enumerate() {
@ -1053,7 +1058,7 @@ fn convert_to_table2<'a>(
return Err(error.clone());
}
let value = convert_to_table2_entry(
let mut value = convert_to_table2_entry(
item,
config,
&ctrlc,
@ -1064,6 +1069,16 @@ fn convert_to_table2<'a>(
available_width,
);
let value_width = string_width(&value.0);
if value_width > available_width {
// it must only happen when a string is produced, so we can safely wrap it.
// (it might be string table representation as well) (I guess I mean default { table ...} { list ...})
//
// todo: Maybe convert_to_table2_entry could do for strings to not mess caller code?
value.0 = wrap_text(&value.0, available_width, config);
}
let value = NuTable::create_cell(value.0, value.1);
data[row].push(value);
}

File diff suppressed because one or more lines are too long