From f94a3e15f574956ad32e3dfd560d88bebdacd1e6 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Sat, 30 Oct 2021 19:59:19 +0200 Subject: [PATCH] Get rid of header bold option (#4076) * refactor(options): get rid of 'header_bold' option * docs(config): remove 'header_bold' from docs * fix(options): replicate logic to apply true/false in bold * style(options): apply lint fixes --- crates/nu-command/src/commands/config/set.rs | 2 +- .../src/commands/viewers/table/options.rs | 17 ++++----- crates/nu-data/src/primitive.rs | 14 +------ docs/commands/config-set.md | 38 +++++++++++-------- docs/sample_config/config.toml | 1 - 5 files changed, 32 insertions(+), 40 deletions(-) diff --git a/crates/nu-command/src/commands/config/set.rs b/crates/nu-command/src/commands/config/set.rs index 468fba3aa2..b6bd986e4c 100644 --- a/crates/nu-command/src/commands/config/set.rs +++ b/crates/nu-command/src/commands/config/set.rs @@ -38,7 +38,7 @@ impl WholeStreamCommand for SubCommand { }, Example { description: "Set coloring options", - example: "config set color_config [[header_align header_bold]; [left $true]]", + example: "config set color_config [[header_align header_color]; [left white_bold]]", result: None, }, Example { diff --git a/crates/nu-command/src/commands/viewers/table/options.rs b/crates/nu-command/src/commands/viewers/table/options.rs index 0cd408b985..cafb349516 100644 --- a/crates/nu-command/src/commands/viewers/table/options.rs +++ b/crates/nu-command/src/commands/viewers/table/options.rs @@ -76,17 +76,14 @@ impl ConfigExtensions for NuConfig { fn header_style(&self) -> TextStyle { // FIXME: I agree, this is the long way around, please suggest and alternative. let head_color = get_color_from_key_and_subkey(self, "color_config", "header_color"); - let head_color_style = match head_color { - Some(s) => { - lookup_ansi_color_style(s.as_string().unwrap_or_else(|_| "green".to_string())) - } - None => nu_ansi_term::Color::Green.normal(), - }; - let head_bold = get_color_from_key_and_subkey(self, "color_config", "header_bold"); - let head_bold_bool = match head_bold { - Some(b) => header_bold_from_value(Some(&b)), - None => true, + let (head_color_style, head_bold_bool) = match head_color { + Some(s) => ( + lookup_ansi_color_style(s.as_string().unwrap_or_else(|_| "green".to_string())), + header_bold_from_value(Some(&s)), + ), + None => (nu_ansi_term::Color::Green.normal(), true), }; + let head_align = get_color_from_key_and_subkey(self, "color_config", "header_align"); let head_alignment = match head_align { Some(a) => header_alignment_from_value(Some(&a)), diff --git a/crates/nu-data/src/primitive.rs b/crates/nu-data/src/primitive.rs index 48f155fcfd..3d0ad340c6 100644 --- a/crates/nu-data/src/primitive.rs +++ b/crates/nu-data/src/primitive.rs @@ -102,7 +102,6 @@ pub fn string_to_lookup_value(str_prim: &str) -> String { "separator_color" => "separator_color".to_string(), "header_align" => "header_align".to_string(), "header_color" => "header_color".to_string(), - "header_bold" => "header_bold".to_string(), "header_style" => "header_style".to_string(), "index_color" => "index_color".to_string(), "leading_trailing_space_bg" => "leading_trailing_space_bg".to_string(), @@ -144,7 +143,6 @@ pub fn get_color_config(config: &NuConfig) -> HashMap { hm.insert("separator_color".to_string(), Color::White.normal()); hm.insert("header_align".to_string(), Color::Green.bold()); hm.insert("header_color".to_string(), Color::Green.bold()); - hm.insert("header_bold".to_string(), Color::Green.bold()); hm.insert("header_style".to_string(), Style::default()); hm.insert("index_color".to_string(), Color::Green.bold()); hm.insert( @@ -204,9 +202,6 @@ pub fn get_color_config(config: &NuConfig) -> HashMap { "header_color" => { update_hashmap(key, value, &mut hm); } - "header_bold" => { - update_hashmap(key, value, &mut hm); - } "header_style" => { update_hashmap(key, value, &mut hm); } @@ -358,14 +353,7 @@ pub fn style_primitive(primitive: &str, color_hm: &HashMap) -> Te let style = color_hm.get("header_color"); match style { Some(s) => TextStyle::with_style(Alignment::Center, *s), - None => TextStyle::default_header(), - } - } - "header_bold" => { - let style = color_hm.get("header_bold"); - match style { - Some(s) => TextStyle::with_style(Alignment::Center, *s), - None => TextStyle::default_header(), + None => TextStyle::default_header().bold(Some(true)), } } "header_style" => { diff --git a/docs/commands/config-set.md b/docs/commands/config-set.md index 75e8505e39..f1ff89e818 100644 --- a/docs/commands/config-set.md +++ b/docs/commands/config-set.md @@ -1,36 +1,44 @@ # config set + Sets a value in the config ## Usage + ```shell -> config set {flags} - ``` +> config set {flags} +``` ## Parameters -* `` variable name to set -* `` value to use + +- `` variable name to set +- `` value to use ## Flags -* -h, --help: Display this help message + +- -h, --help: Display this help message ## Examples - Set auto pivoting + +Set auto pivoting + ```shell > config set pivot_mode always - ``` +``` + +Set line editor options - Set line editor options ```shell > config set line_editor [[edit_mode, completion_type]; [emacs circular]] - ``` +``` + +Set coloring options - Set coloring options ```shell -> config set color_config [[header_align header_bold]; [left $true]] - ``` +> config set color_config [[header_align header_color]; [left white_bold]] +``` + +Set nested options - Set nested options ```shell > config set color_config.header_color white - ``` - +``` diff --git a/docs/sample_config/config.toml b/docs/sample_config/config.toml index e6062bbd9a..c475acb88d 100644 --- a/docs/sample_config/config.toml +++ b/docs/sample_config/config.toml @@ -53,7 +53,6 @@ primitive_binary = "cyan" separator_color = "purple" header_align = "l" # left|l, right|r, center|c header_color = "c" # green|g, red|r, blue|u, black|b, yellow|y, purple|p, cyan|c, white|w -header_bold = true index_color = "rd" leading_trailing_space_bg = "white"