From e62a77a8851b89a0f7d5156a65c90cc302b7e2ff Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Fri, 8 Sep 2023 07:34:47 -0700 Subject: [PATCH] Start removing colour config from `explore` (#10270) This PR removes the `explore.try.border_color` config item, and instead always uses the `separator` colour (the one used for regular table borders) from the current theme. The PR also removes some unused `explore.config` bits from the default config (I missed this in https://github.com/nushell/nushell/pull/10259). ### Future Work This PR is intentionally small, I want to confirm that I'm on the right track before I rip out more colour config from `explore`. If all goes well, expect more PRs like this soon. ### Testing I confirmed that this works by changing my `separator` colour in `config.nu`, and also confirmed that nothing breaks if a user still has `explore.try.border_color` in their config. --- crates/nu-explore/src/commands/try.rs | 1 - crates/nu-explore/src/explore.rs | 22 ------------------- crates/nu-explore/src/views/interactive.rs | 8 +++---- crates/nu-explore/src/views/util.rs | 5 +++++ .../src/sample_config/default_config.nu | 7 ------ 5 files changed, 8 insertions(+), 35 deletions(-) diff --git a/crates/nu-explore/src/commands/try.rs b/crates/nu-explore/src/commands/try.rs index 5d8016831a..feaa468d49 100644 --- a/crates/nu-explore/src/commands/try.rs +++ b/crates/nu-explore/src/commands/try.rs @@ -47,7 +47,6 @@ impl ViewCommand for TryCmd { #[rustfmt::skip] let config_options = vec![ ConfigOption::boolean(":try options", "In the `:try` REPL, attempt to run the command on every keypress", "try.reactive"), - ConfigOption::new(":try options", "Change a border color of the menus", "try.border_color", default_color_list()), ConfigOption::new(":try options", "Change a highlighted menu color", "try.highlighted_color", default_color_list()), ]; diff --git a/crates/nu-explore/src/explore.rs b/crates/nu-explore/src/explore.rs index 78b2936eaa..988227e3cc 100644 --- a/crates/nu-explore/src/explore.rs +++ b/crates/nu-explore/src/explore.rs @@ -219,8 +219,6 @@ fn prepare_default_config(config: &mut HashMap) { const TABLE_SELECT_COLUMN: Style = color(None, None); - const TRY_BORDER_COLOR: Style = color(None, None); - const CONFIG_CURSOR_COLOR: Style = color(Some(Color::Black), Some(Color::LightYellow)); insert_style(config, "status_bar_background", STATUS_BAR); @@ -262,17 +260,6 @@ fn prepare_default_config(config: &mut HashMap) { config.insert(String::from("table"), map_into_value(hm)); } - { - let mut hm = config - .get("try") - .and_then(parse_hash_map) - .unwrap_or_default(); - - insert_style(&mut hm, "border_color", TRY_BORDER_COLOR); - - config.insert(String::from("try"), map_into_value(hm)); - } - { let mut hm = config .get("config") @@ -344,15 +331,6 @@ fn include_nu_config(config: &mut HashMap, style_computer: &Style config.insert(String::from("table"), map_into_value(map)); } - { - let mut map = config - .get("try") - .and_then(parse_hash_map) - .unwrap_or_default(); - insert_style(&mut map, "border_color", line_color); - config.insert(String::from("try"), map_into_value(map)); - } - { let mut map = config .get("config") diff --git a/crates/nu-explore/src/views/interactive.rs b/crates/nu-explore/src/views/interactive.rs index 3ddfeb8c23..6feb565ae8 100644 --- a/crates/nu-explore/src/views/interactive.rs +++ b/crates/nu-explore/src/views/interactive.rs @@ -20,7 +20,7 @@ use crate::{ use super::{ record::{RecordView, TableTheme}, - util::nu_style_to_tui, + util::{lookup_tui_color, nu_style_to_tui}, Layout, Orientation, View, ViewConfig, }; @@ -248,13 +248,11 @@ impl View for InteractiveView<'_> { } fn setup(&mut self, config: ViewConfig<'_>) { + self.border_color = lookup_tui_color(config.style_computer, "separator"); + if let Some(hm) = config.config.get("try").and_then(create_map) { let colors = get_color_map(&hm); - if let Some(color) = colors.get("border_color").copied() { - self.border_color = nu_style_to_tui(color); - } - if let Some(color) = colors.get("highlighted_color").copied() { self.highlighted_color = nu_style_to_tui(color); } diff --git a/crates/nu-explore/src/views/util.rs b/crates/nu-explore/src/views/util.rs index 5e46acdc2a..47d5e8c475 100644 --- a/crates/nu-explore/src/views/util.rs +++ b/crates/nu-explore/src/views/util.rs @@ -33,6 +33,11 @@ pub fn set_span( text_width as u16 } +pub fn lookup_tui_color(style_computer: &StyleComputer, key: &str) -> Style { + let nu_style = style_computer.compute(key, &Value::nothing(nu_protocol::Span::unknown())); + nu_style_to_tui(nu_style) +} + pub fn nu_style_to_tui(style: NuStyle) -> ratatui::style::Style { let mut out = ratatui::style::Style::default(); if let Some(clr) = style.background { diff --git a/crates/nu-utils/src/sample_config/default_config.nu b/crates/nu-utils/src/sample_config/default_config.nu index c4946a92bc..75a19cece4 100644 --- a/crates/nu-utils/src/sample_config/default_config.nu +++ b/crates/nu-utils/src/sample_config/default_config.nu @@ -178,9 +178,6 @@ $env.config = { } explore: { - try: { - border_color: {fg: "white"} - }, status_bar_background: {fg: "#1D1F21", bg: "#C4C9C6"}, command_bar_text: {fg: "#C4C9C6"}, highlight: {fg: "black", bg: "yellow"}, @@ -200,10 +197,6 @@ $env.config = { line_shift: true, line_index: true, }, - config: { - border_color: {fg: "white"} - cursor_color: {fg: "black", bg: "light_yellow"} - }, } history: {