From b2c29117d986ae34caa9d3c8edd964252e3c73c7 Mon Sep 17 00:00:00 2001 From: Maxim Zhiburt Date: Fri, 21 Oct 2022 14:29:55 +0300 Subject: [PATCH] `table -e` align key to 2nd line (#6842) Signed-off-by: Maxim Zhiburt Signed-off-by: Maxim Zhiburt --- crates/nu-command/src/viewers/table.rs | 10 ++++++++++ crates/nu-table/src/table_theme.rs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 3584dfb495..aad75d18e4 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -439,6 +439,7 @@ fn build_expanded_table( } let is_limited = matches!(expand_limit, Some(0)); + let mut is_expanded = false; let value = if is_limited { value_to_styled_string(&value, 0, config, &color_hm).0 } else { @@ -469,6 +470,7 @@ fn build_expanded_table( let result = table.draw_table(config, &color_hm, alignments, &theme, remaining_width); + is_expanded = true; match result { Some(result) => result, None => return Ok(None), @@ -482,6 +484,14 @@ fn build_expanded_table( } }; + // we want to have a key being aligned to 2nd line, + // we could use Padding for it but, + // the easiest way to do so is just push a new_line char before + let mut key = key; + if !key.is_empty() && is_expanded && theme.has_top_line() { + key.insert(0, '\n'); + } + let key = Value::String { val: key, span: Span::new(0, 0), diff --git a/crates/nu-table/src/table_theme.rs b/crates/nu-table/src/table_theme.rs index 6101a3b8f1..299eb8038c 100644 --- a/crates/nu-table/src/table_theme.rs +++ b/crates/nu-table/src/table_theme.rs @@ -114,4 +114,11 @@ impl TableTheme { theme: Style::blank().into(), } } + + pub fn has_top_line(&self) -> bool { + self.theme.get_top().is_some() + || self.theme.get_top_intersection().is_some() + || self.theme.get_top_left().is_some() + || self.theme.get_top_right().is_some() + } }