mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
table: Show truncated record differently (#6884)
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
parent
8838815737
commit
66c2a36123
2 changed files with 51 additions and 10 deletions
|
@ -443,9 +443,13 @@ fn build_expanded_table(
|
|||
let value = if is_limited {
|
||||
value_to_styled_string(&value, 0, config, &color_hm).0
|
||||
} else {
|
||||
let vals = match value {
|
||||
let mut is_record = false;
|
||||
let mut vals = match value {
|
||||
Value::List { vals, .. } => vals,
|
||||
value => vec![value],
|
||||
value => {
|
||||
is_record = true;
|
||||
vec![value]
|
||||
}
|
||||
};
|
||||
|
||||
let deep = expand_limit.map(|i| i - 1);
|
||||
|
@ -465,15 +469,44 @@ fn build_expanded_table(
|
|||
match table {
|
||||
Some(mut table) => {
|
||||
// controll width via removing table columns.
|
||||
let theme = load_theme_from_config(config);
|
||||
table.truncate(remaining_width, &theme);
|
||||
let count_cols = table.size().1;
|
||||
let is_empty = table.truncate(remaining_width, &theme);
|
||||
let was_left_only_index =
|
||||
table.is_with_index() && table.size().1 == 2 && count_cols != 2;
|
||||
let was_truncated = is_empty || was_left_only_index;
|
||||
|
||||
let result =
|
||||
table.draw_table(config, &color_hm, alignments, &theme, remaining_width);
|
||||
is_expanded = true;
|
||||
match result {
|
||||
Some(result) => result,
|
||||
None => return Ok(None),
|
||||
if is_record && vals.len() == 1 && was_truncated {
|
||||
match vals.remove(0) {
|
||||
Value::Record { cols, vals, .. } => {
|
||||
let t = build_general_table2(
|
||||
cols,
|
||||
vals,
|
||||
ctrlc.clone(),
|
||||
config,
|
||||
remaining_width,
|
||||
)?;
|
||||
|
||||
match t {
|
||||
Some(val) => val,
|
||||
None => return Ok(None),
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
} else {
|
||||
let theme = load_theme_from_config(config);
|
||||
let result = table.draw_table(
|
||||
config,
|
||||
&color_hm,
|
||||
alignments,
|
||||
&theme,
|
||||
remaining_width,
|
||||
);
|
||||
is_expanded = true;
|
||||
match result {
|
||||
Some(result) => result,
|
||||
None => return Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
|
|
@ -71,6 +71,14 @@ impl Table {
|
|||
self.is_empty
|
||||
}
|
||||
|
||||
pub fn size(&self) -> (usize, usize) {
|
||||
(self.data.count_rows(), self.data.count_columns())
|
||||
}
|
||||
|
||||
pub fn is_with_index(&self) -> bool {
|
||||
self.with_index
|
||||
}
|
||||
|
||||
pub fn truncate(&mut self, width: usize, theme: &TableTheme) -> bool {
|
||||
let mut truncated = false;
|
||||
while self.data.count_rows() > 0 && self.data.count_columns() > 0 {
|
||||
|
|
Loading…
Reference in a new issue