mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Fix some issues with table wrapping of lists (#7598)
close #7591 I tend to think it must be addressed. But I'd verify it @rgwood. PS: I've noticed how `table -e` and `table` with the same width wraps a bit differently sometimes. (I guess it also must be addressed......) Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
@ -550,13 +550,13 @@ fn build_expanded_table(
|
||||
style_computer,
|
||||
);
|
||||
|
||||
nu_table::wrap_string(&failed_value.0, remaining_width)
|
||||
wrap_text(failed_value.0, remaining_width)
|
||||
}
|
||||
}
|
||||
}
|
||||
val => {
|
||||
let text = value_to_styled_string(&val, config, style_computer).0;
|
||||
nu_table::wrap_string(&text, remaining_width)
|
||||
wrap_text(text, remaining_width)
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -1321,10 +1321,22 @@ fn error_sign(style_computer: &StyleComputer) -> (String, TextStyle) {
|
||||
}
|
||||
|
||||
fn wrap_nu_text(mut text: NuText, width: usize) -> NuText {
|
||||
if string_width(&text.0) <= width {
|
||||
return text;
|
||||
}
|
||||
|
||||
text.0 = nu_table::wrap_string(&text.0, width);
|
||||
text
|
||||
}
|
||||
|
||||
fn wrap_text(text: String, width: usize) -> String {
|
||||
if string_width(&text) <= width {
|
||||
return text;
|
||||
}
|
||||
|
||||
nu_table::wrap_string(&text, width)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn convert_to_table2_entry(
|
||||
item: &Value,
|
||||
@ -1432,7 +1444,10 @@ fn convert_to_table2_entry(
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => wrap_nu_text(value_to_styled_string(item, config, style_computer), width), // unknown type.
|
||||
_ => {
|
||||
let text = value_to_styled_string(item, config, style_computer);
|
||||
wrap_nu_text(text, width)
|
||||
} // unknown type.
|
||||
}
|
||||
}
|
||||
|
||||
@ -1551,7 +1566,6 @@ impl PagingTableCreator {
|
||||
let config = self.engine_state.get_config();
|
||||
let style_computer = StyleComputer::from_config(&self.engine_state, &self.stack);
|
||||
let term_width = get_width_param(self.width_param);
|
||||
let theme = load_theme_from_config(config);
|
||||
|
||||
let table = convert_to_table2(
|
||||
self.row_offset,
|
||||
@ -1566,13 +1580,11 @@ impl PagingTableCreator {
|
||||
term_width,
|
||||
)?;
|
||||
|
||||
let (mut table, with_header, with_index) = match table {
|
||||
let (table, with_header, with_index) = match table {
|
||||
Some(table) => table,
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
table.truncate(term_width, &theme);
|
||||
|
||||
let table_config = create_table_config(
|
||||
config,
|
||||
&style_computer,
|
||||
|
Reference in New Issue
Block a user