From 7f1fd7699e9141cbf13d70ff2c7ffdbeb6ffa621 Mon Sep 17 00:00:00 2001 From: Ralf Steube Date: Thu, 25 Jan 2024 15:21:28 +0100 Subject: [PATCH] external completer: support style (#11442) # Description Adds style support. Reverse highlighting is recommended for the [completion-menu](https://www.nushell.sh/book/line_editor.html#completion-menu): ```nushell style: { text: white selected_text: { attr: r } description_text: white_dimmed } ``` needs https://github.com/nushell/reedline/pull/691 related https://github.com/nushell/nushell/issues/5292 fix https://github.com/rsteube/carapace/issues/967 # User-Facing Changes Style support for values during completion: ![image](https://github.com/nushell/nushell/assets/9090290/f5e4440e-61db-4eeb-87b3-f887b6918c50) ![image](https://github.com/nushell/nushell/assets/9090290/e59065a6-58c2-4f5f-82ea-e2b9c2464b9a) # Tests + Formatting # After Submitting --- crates/nu-cli/src/completions/completer.rs | 11 +++++++++++ crates/nu-utils/src/sample_config/default_config.nu | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/nu-cli/src/completions/completer.rs b/crates/nu-cli/src/completions/completer.rs index 290000d56c..87c51eabf6 100644 --- a/crates/nu-cli/src/completions/completer.rs +++ b/crates/nu-cli/src/completions/completer.rs @@ -2,6 +2,7 @@ use crate::completions::{ CommandCompletion, Completer, CompletionOptions, CustomCompletion, DirectoryCompletion, DotNuCompletion, FileCompletion, FlagCompletion, VariableCompletion, }; +use nu_color_config::{color_record_to_nustyle, lookup_ansi_color_style}; use nu_engine::eval_block; use nu_parser::{flatten_expression, parse, FlatShape}; use nu_protocol::{ @@ -508,6 +509,16 @@ pub fn map_value_completions<'a>( suggestion.description = Some(desc_str); } } + + // Match `style` column + if it.0 == "style" { + // Convert the value to string + suggestion.style = match it.1 { + Value::String { val, .. } => Some(lookup_ansi_color_style(val)), + Value::Record { .. } => Some(color_record_to_nustyle(it.1)), + _ => None, + }; + } }); return Some(suggestion); diff --git a/crates/nu-utils/src/sample_config/default_config.nu b/crates/nu-utils/src/sample_config/default_config.nu index 50e8e27c5d..18c9347173 100644 --- a/crates/nu-utils/src/sample_config/default_config.nu +++ b/crates/nu-utils/src/sample_config/default_config.nu @@ -265,7 +265,7 @@ $env.config = { } style: { text: green - selected_text: green_reverse + selected_text: {attr: r} description_text: yellow } }