From 49318b91f3f17567abd59a84eba0437f54d4f1e5 Mon Sep 17 00:00:00 2001 From: Maxim Zhiburt Date: Tue, 3 Dec 2024 01:35:08 +0300 Subject: [PATCH] update --- crates/nu-table/src/common.rs | 2 + crates/nu-table/src/types/collapse.rs | 21 ++- crates/nu-table/src/types/general.rs | 2 +- crates/nu-table/src/unstructured_table.rs | 189 +++++++++++----------- 4 files changed, 108 insertions(+), 106 deletions(-) diff --git a/crates/nu-table/src/common.rs b/crates/nu-table/src/common.rs index 1fe8eed0c1..e5733b98ba 100644 --- a/crates/nu-table/src/common.rs +++ b/crates/nu-table/src/common.rs @@ -64,6 +64,8 @@ pub fn nu_value_to_string(val: &Value, cfg: &Config, style: &StyleComputer) -> N make_styled_value(text, val, float_precision, style) } +// todo: Expose a method which returns just style + pub fn nu_value_to_string_clean(val: &Value, cfg: &Config, style_comp: &StyleComputer) -> NuText { let (text, style) = nu_value_to_string(val, cfg, style_comp); let mut text = clean_charset(&text); diff --git a/crates/nu-table/src/types/collapse.rs b/crates/nu-table/src/types/collapse.rs index 26102ac9af..9674ea2264 100644 --- a/crates/nu-table/src/types/collapse.rs +++ b/crates/nu-table/src/types/collapse.rs @@ -1,3 +1,4 @@ +use nu_ansi_term::Style; use nu_color_config::StyleComputer; use nu_protocol::{Config, Record, Value}; use nu_utils::SharedCow; @@ -46,10 +47,8 @@ fn colorize_value(value: &mut Value, config: &Config, style_computer: &StyleComp .into_iter() .map(|(mut header, mut val)| { colorize_value(&mut val, config, style_computer); + header = colorize_text(&header, style.color_style).unwrap_or(header); - if let Some(color) = style.color_style { - header = color.paint(header).to_string(); - } (header, val) }) .collect::(), @@ -62,11 +61,19 @@ fn colorize_value(value: &mut Value, config: &Config, style_computer: &StyleComp } value => { let (text, style) = nu_value_to_string_clean(value, config, style_computer); - if let Some(color) = style.color_style { - let text = color.paint(text).to_string(); - let span = value.span(); - *value = Value::string(text, span); + if let Some(text) = colorize_text(&text, style.color_style) { + *value = Value::string(text, value.span()); } } } } + +fn colorize_text(text: &str, color: Option