mirror of
https://github.com/nushell/nushell
synced 2025-01-14 06:04: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 {
|
let value = if is_limited {
|
||||||
value_to_styled_string(&value, 0, config, &color_hm).0
|
value_to_styled_string(&value, 0, config, &color_hm).0
|
||||||
} else {
|
} else {
|
||||||
let vals = match value {
|
let mut is_record = false;
|
||||||
|
let mut vals = match value {
|
||||||
Value::List { vals, .. } => vals,
|
Value::List { vals, .. } => vals,
|
||||||
value => vec![value],
|
value => {
|
||||||
|
is_record = true;
|
||||||
|
vec![value]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let deep = expand_limit.map(|i| i - 1);
|
let deep = expand_limit.map(|i| i - 1);
|
||||||
|
@ -465,15 +469,44 @@ fn build_expanded_table(
|
||||||
match table {
|
match table {
|
||||||
Some(mut table) => {
|
Some(mut table) => {
|
||||||
// controll width via removing table columns.
|
// controll width via removing table columns.
|
||||||
let theme = load_theme_from_config(config);
|
let count_cols = table.size().1;
|
||||||
table.truncate(remaining_width, &theme);
|
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 =
|
if is_record && vals.len() == 1 && was_truncated {
|
||||||
table.draw_table(config, &color_hm, alignments, &theme, remaining_width);
|
match vals.remove(0) {
|
||||||
is_expanded = true;
|
Value::Record { cols, vals, .. } => {
|
||||||
match result {
|
let t = build_general_table2(
|
||||||
Some(result) => result,
|
cols,
|
||||||
None => return Ok(None),
|
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 => {
|
None => {
|
||||||
|
|
|
@ -71,6 +71,14 @@ impl Table {
|
||||||
self.is_empty
|
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 {
|
pub fn truncate(&mut self, width: usize, theme: &TableTheme) -> bool {
|
||||||
let mut truncated = false;
|
let mut truncated = false;
|
||||||
while self.data.count_rows() > 0 && self.data.count_columns() > 0 {
|
while self.data.count_rows() > 0 && self.data.count_columns() > 0 {
|
||||||
|
|
Loading…
Reference in a new issue