From 86dd045554c6e73de96b6bd1fcc0f0d5a0f4054b Mon Sep 17 00:00:00 2001 From: maxomatic458 <104733404+maxomatic458@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:59:01 +0100 Subject: [PATCH] add match-text style + config setting for ide menu (#11670) the match-text style (https://github.com/nushell/reedline/pull/730) is now configurable via the config.nu file. the option ``correct_cursor_pos`` can now also be set in the config.nu file. --- Cargo.lock | 2 +- crates/nu-cli/src/reedline_config.rs | 40 +++++++++++++++++++ .../src/sample_config/default_config.nu | 13 +++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 172a983043..49df6b5495 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4650,7 +4650,7 @@ dependencies = [ [[package]] name = "reedline" version = "0.28.0" -source = "git+https://github.com/nushell/reedline?branch=main#c8a52a85f1e166d8ff0a95c6f114da7f40ba0df4" +source = "git+https://github.com/nushell/reedline?branch=main#090af4d323d09d48ca05a2690658759982df11bd" dependencies = [ "arboard", "chrono", diff --git a/crates/nu-cli/src/reedline_config.rs b/crates/nu-cli/src/reedline_config.rs index cb8a2136e1..0f8159ad5f 100644 --- a/crates/nu-cli/src/reedline_config.rs +++ b/crates/nu-cli/src/reedline_config.rs @@ -236,6 +236,22 @@ pub(crate) fn add_columnar_menu( columnar_menu, ColumnarMenu::with_description_text_style ); + add_style!( + "match_text", + val, + span, + config, + columnar_menu, + ColumnarMenu::with_match_text_style + ); + add_style!( + "selected_match_text", + val, + span, + config, + columnar_menu, + ColumnarMenu::with_selected_match_text_style + ); } let marker = menu.marker.into_string("", config); @@ -492,6 +508,14 @@ pub(crate) fn add_ide_menu( } Err(_) => ide_menu, }; + + ide_menu = match extract_value("correct_cursor_pos", val, span) { + Ok(correct_cursor_pos) => { + let correct_cursor_pos = correct_cursor_pos.as_bool()?; + ide_menu.with_correct_cursor_pos(correct_cursor_pos) + } + Err(_) => ide_menu, + }; } let span = menu.style.span(); @@ -520,6 +544,22 @@ pub(crate) fn add_ide_menu( ide_menu, IdeMenu::with_description_text_style ); + add_style!( + "match_text", + val, + span, + config, + ide_menu, + IdeMenu::with_match_text_style + ); + add_style!( + "selected_match_text", + val, + span, + config, + ide_menu, + IdeMenu::with_selected_match_text_style + ); } let marker = menu.marker.into_string("", config); diff --git a/crates/nu-utils/src/sample_config/default_config.nu b/crates/nu-utils/src/sample_config/default_config.nu index 18c9347173..6f132ae1f6 100644 --- a/crates/nu-utils/src/sample_config/default_config.nu +++ b/crates/nu-utils/src/sample_config/default_config.nu @@ -267,6 +267,8 @@ $env.config = { text: green selected_text: {attr: r} description_text: yellow + match_text: {attr: u} + selected_match_text: {attr: ur} } } { @@ -286,11 +288,20 @@ $env.config = { max_description_width: 50 max_description_height: 10 description_offset: 1 + # If true, the cursor pos will be corrected, so the suggestions match up with the typed text + # + # C:\> str + # str join + # str trim + # str split + correct_cursor_pos: false } style: { text: green - selected_text: green_reverse + selected_text: {attr: r} description_text: yellow + match_text: {attr: u} + selected_match_text: {attr: ur} } } {