diff --git a/crates/nu-cmd-lang/src/core_commands/help.rs b/crates/nu-cmd-lang/src/core_commands/help.rs index 92c14c3438..75f0dac4e1 100644 --- a/crates/nu-cmd-lang/src/core_commands/help.rs +++ b/crates/nu-cmd-lang/src/core_commands/help.rs @@ -2,10 +2,7 @@ use crate::help_aliases::help_aliases; use crate::help_commands::help_commands; use crate::help_modules::help_modules; use fancy_regex::Regex; -use nu_ansi_term::{ - Color::{Red, White}, - Style, -}; +use nu_ansi_term::Style; use nu_engine::CallExt; use nu_protocol::{ ast::Call, @@ -141,6 +138,7 @@ pub fn highlight_search_in_table( search_string: &str, searched_cols: &[&str], string_style: &Style, + highlight_style: &Style, ) -> Result, ShellError> { let orig_search_string = search_string; let search_string = search_string.to_lowercase(); @@ -164,7 +162,12 @@ pub fn highlight_search_in_table( if let Value::String { val: s, span } = val { if s.to_lowercase().contains(&search_string) { *val = Value::String { - val: highlight_search_string(s, orig_search_string, string_style)?, + val: highlight_search_string( + s, + orig_search_string, + string_style, + highlight_style, + )?, span: *span, }; Ok(true) @@ -200,6 +203,7 @@ pub fn highlight_search_string( haystack: &str, needle: &str, string_style: &Style, + highlight_style: &Style, ) -> Result { let regex_string = format!("(?i){needle}"); let regex = match Regex::new(®ex_string) { @@ -217,7 +221,6 @@ pub fn highlight_search_string( // strip haystack to remove existing ansi style let stripped_haystack = nu_utils::strip_ansi_likely(haystack); let mut last_match_end = 0; - let style = Style::new().fg(White).on(Red); let mut highlighted = String::new(); for cap in regex.captures_iter(stripped_haystack.as_ref()) { @@ -236,7 +239,11 @@ pub fn highlight_search_string( .paint(&stripped_haystack[last_match_end..start]) .to_string(), ); - highlighted.push_str(&style.paint(&stripped_haystack[start..end]).to_string()); + highlighted.push_str( + &highlight_style + .paint(&stripped_haystack[start..end]) + .to_string(), + ); last_match_end = end; } Err(e) => { diff --git a/crates/nu-cmd-lang/src/core_commands/help_aliases.rs b/crates/nu-cmd-lang/src/core_commands/help_aliases.rs index 455682a16d..860bab9ef1 100644 --- a/crates/nu-cmd-lang/src/core_commands/help_aliases.rs +++ b/crates/nu-cmd-lang/src/core_commands/help_aliases.rs @@ -84,11 +84,18 @@ pub fn help_aliases( // Also note that this sample string is passed into user-written code (the closure that may or may not be // defined for "string"). let string_style = style_computer.compute("string", &Value::string("search result", head)); + let highlight_style = + style_computer.compute("search_result", &Value::string("search result", head)); if let Some(f) = find { let all_cmds_vec = build_help_aliases(engine_state, stack, head); - let found_cmds_vec = - highlight_search_in_table(all_cmds_vec, &f.item, &["name", "usage"], &string_style)?; + let found_cmds_vec = highlight_search_in_table( + all_cmds_vec, + &f.item, + &["name", "usage"], + &string_style, + &highlight_style, + )?; return Ok(found_cmds_vec .into_iter() diff --git a/crates/nu-cmd-lang/src/core_commands/help_commands.rs b/crates/nu-cmd-lang/src/core_commands/help_commands.rs index adf6a27e5a..9fc01f84cb 100644 --- a/crates/nu-cmd-lang/src/core_commands/help_commands.rs +++ b/crates/nu-cmd-lang/src/core_commands/help_commands.rs @@ -65,6 +65,8 @@ pub fn help_commands( // Also note that this sample string is passed into user-written code (the closure that may or may not be // defined for "string"). let string_style = style_computer.compute("string", &Value::string("search result", head)); + let highlight_style = + style_computer.compute("search_result", &Value::string("search result", head)); if let Some(f) = find { let all_cmds_vec = build_help_commands(engine_state, head); @@ -73,6 +75,7 @@ pub fn help_commands( &f.item, &["name", "usage", "search_terms"], &string_style, + &highlight_style, )?; return Ok(found_cmds_vec diff --git a/crates/nu-cmd-lang/src/core_commands/help_externs.rs b/crates/nu-cmd-lang/src/core_commands/help_externs.rs index b465c44f24..b15f39e215 100644 --- a/crates/nu-cmd-lang/src/core_commands/help_externs.rs +++ b/crates/nu-cmd-lang/src/core_commands/help_externs.rs @@ -84,11 +84,18 @@ pub fn help_externs( // Also note that this sample string is passed into user-written code (the closure that may or may not be // defined for "string"). let string_style = style_computer.compute("string", &Value::string("search result", head)); + let highlight_style = + style_computer.compute("search_result", &Value::string("search result", head)); if let Some(f) = find { let all_cmds_vec = build_help_externs(engine_state, stack, head); - let found_cmds_vec = - highlight_search_in_table(all_cmds_vec, &f.item, &["name", "usage"], &string_style)?; + let found_cmds_vec = highlight_search_in_table( + all_cmds_vec, + &f.item, + &["name", "usage"], + &string_style, + &highlight_style, + )?; return Ok(found_cmds_vec .into_iter() diff --git a/crates/nu-cmd-lang/src/core_commands/help_modules.rs b/crates/nu-cmd-lang/src/core_commands/help_modules.rs index f87c870771..e3b8e274ab 100644 --- a/crates/nu-cmd-lang/src/core_commands/help_modules.rs +++ b/crates/nu-cmd-lang/src/core_commands/help_modules.rs @@ -90,11 +90,18 @@ pub fn help_modules( // Also note that this sample string is passed into user-written code (the closure that may or may not be // defined for "string"). let string_style = style_computer.compute("string", &Value::string("search result", head)); + let highlight_style = + style_computer.compute("search_result", &Value::string("search result", head)); if let Some(f) = find { let all_cmds_vec = build_help_modules(engine_state, stack, head); - let found_cmds_vec = - highlight_search_in_table(all_cmds_vec, &f.item, &["name", "usage"], &string_style)?; + let found_cmds_vec = highlight_search_in_table( + all_cmds_vec, + &f.item, + &["name", "usage"], + &string_style, + &highlight_style, + )?; return Ok(found_cmds_vec .into_iter() diff --git a/crates/nu-color-config/src/style_computer.rs b/crates/nu-color-config/src/style_computer.rs index 46746ea3a3..622f688991 100644 --- a/crates/nu-color-config/src/style_computer.rs +++ b/crates/nu-color-config/src/style_computer.rs @@ -163,6 +163,7 @@ impl<'a> StyleComputer<'a> { ("list".to_string(), ComputableStyle::Static(Color::White.normal())), ("block".to_string(), ComputableStyle::Static(Color::White.normal())), ("hints".to_string(), ComputableStyle::Static(Color::DarkGray.normal())), + ("search_result".to_string(), ComputableStyle::Static(Color::White.normal().on(Color::Red))), ]); for (key, value) in &config.color_config { diff --git a/crates/nu-command/src/filters/find.rs b/crates/nu-command/src/filters/find.rs index f5d6c42ff6..c7f0b488d6 100644 --- a/crates/nu-command/src/filters/find.rs +++ b/crates/nu-command/src/filters/find.rs @@ -1,17 +1,15 @@ use nu_cmd_lang::help::highlight_search_string; use fancy_regex::Regex; -use lscolors::{Color as LsColors_Color, LsColors, Style as LsColors_Style}; -use nu_ansi_term::{Color, Style}; +use nu_ansi_term::Style; use nu_color_config::StyleComputer; -use nu_engine::{env_to_string, CallExt}; +use nu_engine::CallExt; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, Category, Config, Example, IntoInterruptiblePipelineData, IntoPipelineData, ListStream, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value, }; -use nu_utils::get_ls_colors; #[derive(Clone)] pub struct Find; @@ -300,7 +298,7 @@ fn highlight_terms_in_record_with_search_columns( config: &Config, terms: &[Value], string_style: Style, - ls_colors: &LsColors, + highlight_style: Style, ) -> Value { let cols_to_search = if search_cols.is_empty() { cols.to_vec() @@ -316,18 +314,11 @@ fn highlight_terms_in_record_with_search_columns( let term_str = term.into_string("", config); let output_value = if contains_ignore_case(&val_str, &term_str) && cols_to_search.contains(cur_col) { - let (value_to_highlight, highlight_string_style) = if config.use_ls_colors { - // Get the original LS_COLORS color - get_colored_value_and_string_style(ls_colors, &val_str, &string_style) - } else { - // No LS_COLORS support, so just use the original value - (val_str.clone(), string_style) - }; - let highlighted_str = match highlight_search_string( - &value_to_highlight, + &val_str, &term_str, - &highlight_string_style, + &string_style, + &highlight_style, ) { Ok(highlighted_str) => highlighted_str, Err(_) => string_style.paint(term_str).to_string(), @@ -350,24 +341,6 @@ fn highlight_terms_in_record_with_search_columns( } } -fn get_colored_value_and_string_style( - ls_colors: &LsColors, - val_str: &str, - string_style: &Style, -) -> (String, Style) { - let style = ls_colors.style_for_path(val_str); - let ansi_style = style - .map(LsColors_Style::to_nu_ansi_term_style) - .unwrap_or_default(); - - let ls_colored_val = ansi_style.paint(val_str).to_string(); - - let ansi_term_style = style - .map(to_nu_ansi_term_style) - .unwrap_or_else(|| *string_style); - (ls_colored_val, ansi_term_style) -} - fn contains_ignore_case(string: &str, substring: &str) -> bool { string.to_lowercase().contains(&substring.to_lowercase()) } @@ -401,12 +374,8 @@ fn find_with_rest_and_highlight( // Also note that this sample string is passed into user-written code (the closure that may or may not be // defined for "string"). let string_style = style_computer.compute("string", &Value::string("search result", span)); - - let ls_colors_env_str = match stack.get_env_var(&engine_state, "LS_COLORS") { - Some(v) => Some(env_to_string("LS_COLORS", &v, &engine_state, stack)?), - None => None, - }; - let ls_colors = get_ls_colors(ls_colors_env_str); + let highlight_style = + style_computer.compute("search_result", &Value::string("search result", span)); let cols_to_search_in_map = match call.get_flag(&engine_state, stack, "columns")? { Some(cols) => cols, @@ -429,7 +398,7 @@ fn find_with_rest_and_highlight( &config, &terms, string_style, - &ls_colors, + highlight_style, ) } _ => x, @@ -461,7 +430,7 @@ fn find_with_rest_and_highlight( &config, &terms, string_style, - &ls_colors, + highlight_style, ) } _ => x, @@ -504,6 +473,7 @@ fn find_with_rest_and_highlight( line, &term_str, &string_style, + &highlight_style, )?, span, }) @@ -622,47 +592,6 @@ fn record_matches_term( }) } -fn to_nu_ansi_term_style(style: &LsColors_Style) -> Style { - fn to_nu_ansi_term_color(color: &LsColors_Color) -> Color { - match *color { - LsColors_Color::Fixed(n) => Color::Fixed(n), - LsColors_Color::RGB(r, g, b) => Color::Rgb(r, g, b), - LsColors_Color::Black => Color::Black, - LsColors_Color::Red => Color::Red, - LsColors_Color::Green => Color::Green, - LsColors_Color::Yellow => Color::Yellow, - LsColors_Color::Blue => Color::Blue, - LsColors_Color::Magenta => Color::Magenta, - LsColors_Color::Cyan => Color::Cyan, - LsColors_Color::White => Color::White, - - // Below items are a rough translations to 256 colors as - // nu-ansi-term do not have bright variants - LsColors_Color::BrightBlack => Color::Fixed(8), - LsColors_Color::BrightRed => Color::Fixed(9), - LsColors_Color::BrightGreen => Color::Fixed(10), - LsColors_Color::BrightYellow => Color::Fixed(11), - LsColors_Color::BrightBlue => Color::Fixed(12), - LsColors_Color::BrightMagenta => Color::Fixed(13), - LsColors_Color::BrightCyan => Color::Fixed(14), - LsColors_Color::BrightWhite => Color::Fixed(15), - } - } - - Style { - foreground: style.foreground.as_ref().map(to_nu_ansi_term_color), - background: style.background.as_ref().map(to_nu_ansi_term_color), - is_bold: style.font_style.bold, - is_dimmed: style.font_style.dimmed, - is_italic: style.font_style.italic, - is_underline: style.font_style.underline, - is_blink: style.font_style.slow_blink || style.font_style.rapid_blink, - is_reverse: style.font_style.reverse, - is_hidden: style.font_style.hidden, - is_strikethrough: style.font_style.strikethrough, - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/nu-command/tests/commands/table.rs b/crates/nu-command/tests/commands/table.rs index c4ddef77fb..d1bbfa54da 100644 --- a/crates/nu-command/tests/commands/table.rs +++ b/crates/nu-command/tests/commands/table.rs @@ -1357,7 +1357,7 @@ fn test_expand_big_0() { #[test] fn table_expande_with_no_header_internally_0() { - let nu_value = r##"{ "config ": { "ls": { "use_ls_colors": true, "clickable_links": false }, "rm": { "always_trash": false }, "cd": { "abbreviations": false }, "table": { "mode": "rounded", "index_mode": "always", "trim": { "methodology": "wrapping", "wrapping_try_keep_words": true, "truncating_suffix": "..." } }, "explore": { "help_banner": true, "exit_esc": true, "command_bar_text": "#C4C9C6", "status_bar_background": { "fg": "#1D1F21", "bg": "#C4C9C6" }, "highlight": { "bg": "yellow", "fg": "black" }, "status": {}, "try": {}, "table": { "split_line": "#404040", "cursor": true, "line_index": true, "line_shift": true, "line_head_top": true, "line_head_bottom": true, "show_head": true, "show_index": true }, "config": { "cursor_color": { "bg": "yellow", "fg": "black" } } }, "history": { "max_size": 10000, "sync_on_enter": true, "file_format": "plaintext" }, "completions": { "case_sensitive": false, "quick": true, "partial": true, "algorithm": "prefix", "external": { "enable": true, "max_results": 100, "completer": null } }, "filesize": { "metric": true, "format": "auto" }, "cursor_shape": { "emacs": "line", "vi_insert": "block", "vi_normal": "underscore" }, "color_config": { "separator": "white", "leading_trailing_space_bg": { "attr": "n" }, "header": "green_bold", "empty": "blue", "bool": null, "int": "white", "filesize": null, "duration": "white", "date": null, "range": "white", "float": "white", "string": "white", "nothing": "white", "binary": "white", "cellpath": "white", "row_index": "green_bold", "record": "white", "list": "white", "block": "white", "hints": "dark_gray", "shape_and": "purple_bold", "shape_binary": "purple_bold", "shape_block": "blue_bold", "shape_bool": "light_cyan", "shape_custom": "green", "shape_datetime": "cyan_bold", "shape_directory": "cyan", "shape_external": "cyan", "shape_externalarg": "green_bold", "shape_filepath": "cyan", "shape_flag": "blue_bold", "shape_float": "purple_bold", "shape_garbage": { "fg": "#FFFFFF", "bg": "#FF0000", "attr": "b" }, "shape_globpattern": "cyan_bold", "shape_int": "purple_bold", "shape_internalcall": "cyan_bold", "shape_list": "cyan_bold", "shape_literal": "blue", "shape_matching_brackets": { "attr": "u" }, "shape_nothing": "light_cyan", "shape_operator": "yellow", "shape_or": "purple_bold", "shape_pipe": "purple_bold", "shape_range": "yellow_bold", "shape_record": "cyan_bold", "shape_redirection": "purple_bold", "shape_signature": "green_bold", "shape_string": "green", "shape_string_interpolation": "cyan_bold", "shape_table": "blue_bold", "shape_variable": "purple" }, "use_grid_icons": true, "footer_mode": "25", "float_precision": 2, "use_ansi_coloring": true, "edit_mode": "emacs", "shell_integration": true, "show_banner": true, "render_right_prompt_on_last_line": false, "hooks": { "pre_prompt": [ null ], "pre_execution": [ null ], "env_change": { "PWD": [ null ] }, "display_output": null }, "menus": [ { "name": "completion_menu", "only_buffer_difference": false, "marker": "| ", "type": { "layout": "columnar", "columns": 4, "col_width": 20, "col_padding": 2 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "history_menu", "only_buffer_difference": true, "marker": "? ", "type": { "layout": "list", "page_size": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "help_menu", "only_buffer_difference": true, "marker": "? ", "type": { "layout": "description", "columns": 4, "col_width": 20, "col_padding": 2, "selection_rows": 4, "description_rows": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "commands_menu", "only_buffer_difference": false, "marker": "# ", "type": { "layout": "columnar", "columns": 4, "col_width": 20, "col_padding": 2 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null }, { "name": "vars_menu", "only_buffer_difference": true, "marker": "# ", "type": { "layout": "list", "page_size": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null }, { "name": "commands_with_description", "only_buffer_difference": true, "marker": "# ", "type": { "layout": "description", "columns": 4, "col_width": 20, "col_padding": 2, "selection_rows": 4, "description_rows": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null } ], "keybindings": [ { "name": "completion_menu", "modifier": "none", "keycode": "tab", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "send": "menu", "name": "completion_menu" }, { "send": "menunext" } ] } }, { "name": "completion_previous", "modifier": "shift", "keycode": "backtab", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menuprevious" } }, { "name": "history_menu", "modifier": "control", "keycode": "char_r", "mode": "emacs", "event": { "send": "menu", "name": "history_menu" } }, { "name": "next_page", "modifier": "control", "keycode": "char_x", "mode": "emacs", "event": { "send": "menupagenext" } }, { "name": "undo_or_previous_page", "modifier": "control", "keycode": "char_z", "mode": "emacs", "event": { "until": [ { "send": "menupageprevious" }, { "edit": "undo" } ] } }, { "name": "yank", "modifier": "control", "keycode": "char_y", "mode": "emacs", "event": { "until": [ { "edit": "pastecutbufferafter" } ] } }, { "name": "unix-line-discard", "modifier": "control", "keycode": "char_u", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "edit": "cutfromlinestart" } ] } }, { "name": "kill-line", "modifier": "control", "keycode": "char_k", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "edit": "cuttolineend" } ] } }, { "name": "commands_menu", "modifier": "control", "keycode": "char_t", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "commands_menu" } }, { "name": "vars_menu", "modifier": "alt", "keycode": "char_o", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "vars_menu" } }, { "name": "commands_with_description", "modifier": "control", "keycode": "char_s", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "commands_with_description" } } ] } }"##; + let nu_value = r##"{ "config ": { "ls": { "use_ls_colors": true, "clickable_links": false }, "rm": { "always_trash": false }, "cd": { "abbreviations": false }, "table": { "mode": "rounded", "index_mode": "always", "trim": { "methodology": "wrapping", "wrapping_try_keep_words": true, "truncating_suffix": "..." } }, "explore": { "help_banner": true, "exit_esc": true, "command_bar_text": "#C4C9C6", "status_bar_background": { "fg": "#1D1F21", "bg": "#C4C9C6" }, "highlight": { "bg": "yellow", "fg": "black" }, "status": {}, "try": {}, "table": { "split_line": "#404040", "cursor": true, "line_index": true, "line_shift": true, "line_head_top": true, "line_head_bottom": true, "show_head": true, "show_index": true }, "config": { "cursor_color": { "bg": "yellow", "fg": "black" } } }, "history": { "max_size": 10000, "sync_on_enter": true, "file_format": "plaintext" }, "completions": { "case_sensitive": false, "quick": true, "partial": true, "algorithm": "prefix", "external": { "enable": true, "max_results": 100, "completer": null } }, "filesize": { "metric": true, "format": "auto" }, "cursor_shape": { "emacs": "line", "vi_insert": "block", "vi_normal": "underscore" }, "color_config": { "separator": "white", "leading_trailing_space_bg": { "attr": "n" }, "header": "green_bold", "empty": "blue", "bool": null, "int": "white", "filesize": null, "duration": "white", "date": null, "range": "white", "float": "white", "string": "white", "nothing": "white", "binary": "white", "cellpath": "white", "row_index": "green_bold", "record": "white", "list": "white", "block": "white", "hints": "dark_gray", "search_result": {"fg": "white", "bg": "red"}, "shape_and": "purple_bold", "shape_binary": "purple_bold", "shape_block": "blue_bold", "shape_bool": "light_cyan", "shape_custom": "green", "shape_datetime": "cyan_bold", "shape_directory": "cyan", "shape_external": "cyan", "shape_externalarg": "green_bold", "shape_filepath": "cyan", "shape_flag": "blue_bold", "shape_float": "purple_bold", "shape_garbage": { "fg": "#FFFFFF", "bg": "#FF0000", "attr": "b" }, "shape_globpattern": "cyan_bold", "shape_int": "purple_bold", "shape_internalcall": "cyan_bold", "shape_list": "cyan_bold", "shape_literal": "blue", "shape_matching_brackets": { "attr": "u" }, "shape_nothing": "light_cyan", "shape_operator": "yellow", "shape_or": "purple_bold", "shape_pipe": "purple_bold", "shape_range": "yellow_bold", "shape_record": "cyan_bold", "shape_redirection": "purple_bold", "shape_signature": "green_bold", "shape_string": "green", "shape_string_interpolation": "cyan_bold", "shape_table": "blue_bold", "shape_variable": "purple" }, "use_grid_icons": true, "footer_mode": "25", "float_precision": 2, "use_ansi_coloring": true, "edit_mode": "emacs", "shell_integration": true, "show_banner": true, "render_right_prompt_on_last_line": false, "hooks": { "pre_prompt": [ null ], "pre_execution": [ null ], "env_change": { "PWD": [ null ] }, "display_output": null }, "menus": [ { "name": "completion_menu", "only_buffer_difference": false, "marker": "| ", "type": { "layout": "columnar", "columns": 4, "col_width": 20, "col_padding": 2 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "history_menu", "only_buffer_difference": true, "marker": "? ", "type": { "layout": "list", "page_size": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "help_menu", "only_buffer_difference": true, "marker": "? ", "type": { "layout": "description", "columns": 4, "col_width": 20, "col_padding": 2, "selection_rows": 4, "description_rows": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "commands_menu", "only_buffer_difference": false, "marker": "# ", "type": { "layout": "columnar", "columns": 4, "col_width": 20, "col_padding": 2 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null }, { "name": "vars_menu", "only_buffer_difference": true, "marker": "# ", "type": { "layout": "list", "page_size": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null }, { "name": "commands_with_description", "only_buffer_difference": true, "marker": "# ", "type": { "layout": "description", "columns": 4, "col_width": 20, "col_padding": 2, "selection_rows": 4, "description_rows": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null } ], "keybindings": [ { "name": "completion_menu", "modifier": "none", "keycode": "tab", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "send": "menu", "name": "completion_menu" }, { "send": "menunext" } ] } }, { "name": "completion_previous", "modifier": "shift", "keycode": "backtab", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menuprevious" } }, { "name": "history_menu", "modifier": "control", "keycode": "char_r", "mode": "emacs", "event": { "send": "menu", "name": "history_menu" } }, { "name": "next_page", "modifier": "control", "keycode": "char_x", "mode": "emacs", "event": { "send": "menupagenext" } }, { "name": "undo_or_previous_page", "modifier": "control", "keycode": "char_z", "mode": "emacs", "event": { "until": [ { "send": "menupageprevious" }, { "edit": "undo" } ] } }, { "name": "yank", "modifier": "control", "keycode": "char_y", "mode": "emacs", "event": { "until": [ { "edit": "pastecutbufferafter" } ] } }, { "name": "unix-line-discard", "modifier": "control", "keycode": "char_u", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "edit": "cutfromlinestart" } ] } }, { "name": "kill-line", "modifier": "control", "keycode": "char_k", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "edit": "cuttolineend" } ] } }, { "name": "commands_menu", "modifier": "control", "keycode": "char_t", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "commands_menu" } }, { "name": "vars_menu", "modifier": "alt", "keycode": "char_o", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "vars_menu" } }, { "name": "commands_with_description", "modifier": "control", "keycode": "char_s", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "commands_with_description" } } ] } }"##; let actual = nu!(format!("{} | table --expand --width 141", nu_value.trim())); @@ -1464,6 +1464,10 @@ fn table_expande_with_no_header_internally_0() { "│ │ │ │ │ list │ white │ │ │", "│ │ │ │ │ block │ white │ │ │", "│ │ │ │ │ hints │ dark_gray │ │ │", + "│ │ │ │ │ │ ╭────┬───────╮ │ │ │", + "│ │ │ │ │ search_result │ │ fg │ white │ │ │ │", + "│ │ │ │ │ │ │ bg │ red │ │ │ │", + "│ │ │ │ │ │ ╰────┴───────╯ │ │ │", "│ │ │ │ │ shape_and │ purple_bold │ │ │", "│ │ │ │ │ shape_binary │ purple_bold │ │ │", "│ │ │ │ │ shape_block │ blue_bold │ │ │", @@ -1599,10 +1603,11 @@ fn table_expande_with_no_header_internally_0() { #[test] fn table_expande_with_no_header_internally_1() { - let nu_value = r##"{ "config ": { "ls": { "use_ls_colors": true, "clickable_links": false }, "rm": { "always_trash": false }, "cd": { "abbreviations": false }, "table": { "mode": "rounded", "index_mode": "always", "trim": { "methodology": "wrapping", "wrapping_try_keep_words": true, "truncating_suffix": "..." } }, "explore": { "help_banner": true, "exit_esc": true, "command_bar_text": "#C4C9C6", "status_bar_background": { "fg": "#1D1F21", "bg": "#C4C9C6" }, "highlight": { "bg": "yellow", "fg": "black" }, "status": {}, "try": {}, "table": { "split_line": "#404040", "cursor": true, "line_index": true, "line_shift": true, "line_head_top": true, "line_head_bottom": true, "show_head": true, "show_index": true }, "config": { "cursor_color": { "bg": "yellow", "fg": "black" } } }, "history": { "max_size": 10000, "sync_on_enter": true, "file_format": "plaintext" }, "completions": { "case_sensitive": false, "quick": true, "partial": true, "algorithm": "prefix", "external": { "enable": true, "max_results": 100, "completer": null } }, "filesize": { "metric": true, "format": "auto" }, "cursor_shape": { "emacs": "line", "vi_insert": "block", "vi_normal": "underscore" }, "color_config": { "separator": "white", "leading_trailing_space_bg": { "attr": "n" }, "header": "green_bold", "empty": "blue", "bool": null, "int": "white", "filesize": null, "duration": "white", "date": null, "range": "white", "float": "white", "string": "white", "nothing": "white", "binary": "white", "cellpath": "white", "row_index": "green_bold", "record": "white", "list": "white", "block": "white", "hints": "dark_gray", "shape_and": "purple_bold", "shape_binary": "purple_bold", "shape_block": "blue_bold", "shape_bool": "light_cyan", "shape_custom": "green", "shape_datetime": "cyan_bold", "shape_directory": "cyan", "shape_external": "cyan", "shape_externalarg": "green_bold", "shape_filepath": "cyan", "shape_flag": "blue_bold", "shape_float": "purple_bold", "shape_garbage": { "fg": "#FFFFFF", "bg": "#FF0000", "attr": "b" }, "shape_globpattern": "cyan_bold", "shape_int": "purple_bold", "shape_internalcall": "cyan_bold", "shape_list": "cyan_bold", "shape_literal": "blue", "shape_matching_brackets": { "attr": "u" }, "shape_nothing": "light_cyan", "shape_operator": "yellow", "shape_or": "purple_bold", "shape_pipe": "purple_bold", "shape_range": "yellow_bold", "shape_record": "cyan_bold", "shape_redirection": "purple_bold", "shape_signature": "green_bold", "shape_string": "green", "shape_string_interpolation": "cyan_bold", "shape_table": "blue_bold", "shape_variable": "purple" }, "use_grid_icons": true, "footer_mode": "25", "float_precision": 2, "use_ansi_coloring": true, "edit_mode": "emacs", "shell_integration": true, "show_banner": true, "render_right_prompt_on_last_line": false, "hooks": { "pre_prompt": [ null ], "pre_execution": [ null ], "env_change": { "PWD": [ null ] }, "display_output": null }, "menus": [ { "name": "completion_menu", "only_buffer_difference": false, "marker": "| ", "type": { "layout": "columnar", "columns": 4, "col_width": 20, "col_padding": 2 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "history_menu", "only_buffer_difference": true, "marker": "? ", "type": { "layout": "list", "page_size": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "help_menu", "only_buffer_difference": true, "marker": "? ", "type": { "layout": "description", "columns": 4, "col_width": 20, "col_padding": 2, "selection_rows": 4, "description_rows": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "commands_menu", "only_buffer_difference": false, "marker": "# ", "type": { "layout": "columnar", "columns": 4, "col_width": 20, "col_padding": 2 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null }, { "name": "vars_menu", "only_buffer_difference": true, "marker": "# ", "type": { "layout": "list", "page_size": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null }, { "name": "commands_with_description", "only_buffer_difference": true, "marker": "# ", "type": { "layout": "description", "columns": 4, "col_width": 20, "col_padding": 2, "selection_rows": 4, "description_rows": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null } ], "keybindings": [ { "name": "completion_menu", "modifier": "none", "keycode": "tab", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "send": "menu", "name": "completion_menu" }, { "send": "menunext" } ] } }, { "name": "completion_previous", "modifier": "shift", "keycode": "backtab", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menuprevious" } }, { "name": "history_menu", "modifier": "control", "keycode": "char_r", "mode": "emacs", "event": { "send": "menu", "name": "history_menu" } }, { "name": "next_page", "modifier": "control", "keycode": "char_x", "mode": "emacs", "event": { "send": "menupagenext" } }, { "name": "undo_or_previous_page", "modifier": "control", "keycode": "char_z", "mode": "emacs", "event": { "until": [ { "send": "menupageprevious" }, { "edit": "undo" } ] } }, { "name": "yank", "modifier": "control", "keycode": "char_y", "mode": "emacs", "event": { "until": [ { "edit": "pastecutbufferafter" } ] } }, { "name": "unix-line-discard", "modifier": "control", "keycode": "char_u", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "edit": "cutfromlinestart" } ] } }, { "name": "kill-line", "modifier": "control", "keycode": "char_k", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "edit": "cuttolineend" } ] } }, { "name": "commands_menu", "modifier": "control", "keycode": "char_t", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "commands_menu" } }, { "name": "vars_menu", "modifier": "alt", "keycode": "char_o", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "vars_menu" } }, { "name": "commands_with_description", "modifier": "control", "keycode": "char_s", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "commands_with_description" } } ] } }"##; + let nu_value = r##"{ "config ": { "ls": { "use_ls_colors": true, "clickable_links": false }, "rm": { "always_trash": false }, "cd": { "abbreviations": false }, "table": { "mode": "rounded", "index_mode": "always", "trim": { "methodology": "wrapping", "wrapping_try_keep_words": true, "truncating_suffix": "..." } }, "explore": { "help_banner": true, "exit_esc": true, "command_bar_text": "#C4C9C6", "status_bar_background": { "fg": "#1D1F21", "bg": "#C4C9C6" }, "highlight": { "bg": "yellow", "fg": "black" }, "status": {}, "try": {}, "table": { "split_line": "#404040", "cursor": true, "line_index": true, "line_shift": true, "line_head_top": true, "line_head_bottom": true, "show_head": true, "show_index": true }, "config": { "cursor_color": { "bg": "yellow", "fg": "black" } } }, "history": { "max_size": 10000, "sync_on_enter": true, "file_format": "plaintext" }, "completions": { "case_sensitive": false, "quick": true, "partial": true, "algorithm": "prefix", "external": { "enable": true, "max_results": 100, "completer": null } }, "filesize": { "metric": true, "format": "auto" }, "cursor_shape": { "emacs": "line", "vi_insert": "block", "vi_normal": "underscore" }, "color_config": { "separator": "white", "leading_trailing_space_bg": { "attr": "n" }, "header": "green_bold", "empty": "blue", "bool": null, "int": "white", "filesize": null, "duration": "white", "date": null, "range": "white", "float": "white", "string": "white", "nothing": "white", "binary": "white", "cellpath": "white", "row_index": "green_bold", "record": "white", "list": "white", "block": "white", "hints": "dark_gray", "search_result": {"fg": "white", "bg": "red"}, "shape_and": "purple_bold", "shape_binary": "purple_bold", "shape_block": "blue_bold", "shape_bool": "light_cyan", "shape_custom": "green", "shape_datetime": "cyan_bold", "shape_directory": "cyan", "shape_external": "cyan", "shape_externalarg": "green_bold", "shape_filepath": "cyan", "shape_flag": "blue_bold", "shape_float": "purple_bold", "shape_garbage": { "fg": "#FFFFFF", "bg": "#FF0000", "attr": "b" }, "shape_globpattern": "cyan_bold", "shape_int": "purple_bold", "shape_internalcall": "cyan_bold", "shape_list": "cyan_bold", "shape_literal": "blue", "shape_matching_brackets": { "attr": "u" }, "shape_nothing": "light_cyan", "shape_operator": "yellow", "shape_or": "purple_bold", "shape_pipe": "purple_bold", "shape_range": "yellow_bold", "shape_record": "cyan_bold", "shape_redirection": "purple_bold", "shape_signature": "green_bold", "shape_string": "green", "shape_string_interpolation": "cyan_bold", "shape_table": "blue_bold", "shape_variable": "purple" }, "use_grid_icons": true, "footer_mode": "25", "float_precision": 2, "use_ansi_coloring": true, "edit_mode": "emacs", "shell_integration": true, "show_banner": true, "render_right_prompt_on_last_line": false, "hooks": { "pre_prompt": [ null ], "pre_execution": [ null ], "env_change": { "PWD": [ null ] }, "display_output": null }, "menus": [ { "name": "completion_menu", "only_buffer_difference": false, "marker": "| ", "type": { "layout": "columnar", "columns": 4, "col_width": 20, "col_padding": 2 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "history_menu", "only_buffer_difference": true, "marker": "? ", "type": { "layout": "list", "page_size": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "help_menu", "only_buffer_difference": true, "marker": "? ", "type": { "layout": "description", "columns": 4, "col_width": 20, "col_padding": 2, "selection_rows": 4, "description_rows": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" } }, { "name": "commands_menu", "only_buffer_difference": false, "marker": "# ", "type": { "layout": "columnar", "columns": 4, "col_width": 20, "col_padding": 2 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null }, { "name": "vars_menu", "only_buffer_difference": true, "marker": "# ", "type": { "layout": "list", "page_size": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null }, { "name": "commands_with_description", "only_buffer_difference": true, "marker": "# ", "type": { "layout": "description", "columns": 4, "col_width": 20, "col_padding": 2, "selection_rows": 4, "description_rows": 10 }, "style": { "text": "green", "selected_text": "green_reverse", "description_text": "yellow" }, "source": null } ], "keybindings": [ { "name": "completion_menu", "modifier": "none", "keycode": "tab", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "send": "menu", "name": "completion_menu" }, { "send": "menunext" } ] } }, { "name": "completion_previous", "modifier": "shift", "keycode": "backtab", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menuprevious" } }, { "name": "history_menu", "modifier": "control", "keycode": "char_r", "mode": "emacs", "event": { "send": "menu", "name": "history_menu" } }, { "name": "next_page", "modifier": "control", "keycode": "char_x", "mode": "emacs", "event": { "send": "menupagenext" } }, { "name": "undo_or_previous_page", "modifier": "control", "keycode": "char_z", "mode": "emacs", "event": { "until": [ { "send": "menupageprevious" }, { "edit": "undo" } ] } }, { "name": "yank", "modifier": "control", "keycode": "char_y", "mode": "emacs", "event": { "until": [ { "edit": "pastecutbufferafter" } ] } }, { "name": "unix-line-discard", "modifier": "control", "keycode": "char_u", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "edit": "cutfromlinestart" } ] } }, { "name": "kill-line", "modifier": "control", "keycode": "char_k", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "until": [ { "edit": "cuttolineend" } ] } }, { "name": "commands_menu", "modifier": "control", "keycode": "char_t", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "commands_menu" } }, { "name": "vars_menu", "modifier": "alt", "keycode": "char_o", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "vars_menu" } }, { "name": "commands_with_description", "modifier": "control", "keycode": "char_s", "mode": [ "emacs", "vi_normal", "vi_insert" ], "event": { "send": "menu", "name": "commands_with_description" } } ] } }"##; let actual = nu!(format!("{} | table --expand --width 136", nu_value.trim())); + println!("{}", actual.out); assert_eq!( actual.out, join_lines([ @@ -1706,6 +1711,10 @@ fn table_expande_with_no_header_internally_1() { "│ │ │ │ │ list │ white │ │ │", "│ │ │ │ │ block │ white │ │ │", "│ │ │ │ │ hints │ dark_gray │ │ │", + "│ │ │ │ │ │ ╭────┬───────╮ │ │ │", + "│ │ │ │ │ search_result │ │ fg │ white │ │ │ │", + "│ │ │ │ │ │ │ bg │ red │ │ │ │", + "│ │ │ │ │ │ ╰────┴───────╯ │ │ │", "│ │ │ │ │ shape_and │ purple_bold │ │ │", "│ │ │ │ │ shape_binary │ purple_bold │ │ │", "│ │ │ │ │ shape_block │ blue_bold │ │ │", diff --git a/crates/nu-utils/src/sample_config/default_config.nu b/crates/nu-utils/src/sample_config/default_config.nu index 138534f37b..6f6794445a 100644 --- a/crates/nu-utils/src/sample_config/default_config.nu +++ b/crates/nu-utils/src/sample_config/default_config.nu @@ -52,6 +52,7 @@ let dark_theme = { list: white block: white hints: dark_gray + search_result: {bg: red fg: white} shape_and: purple_bold shape_binary: purple_bold @@ -136,6 +137,7 @@ let light_theme = { list: white block: white hints: dark_gray + search_result: {fg: white bg: red} shape_and: purple_bold shape_binary: purple_bold