Skip to content

Commit

Permalink
add match-text style + config setting for ide menu (nushell#11670)
Browse files Browse the repository at this point in the history
the match-text style (nushell/reedline#730) is
now configurable via the config.nu file.
the option ``correct_cursor_pos`` can now also be set in the config.nu
file.
  • Loading branch information
maxomatic458 authored and dmatos2012 committed Feb 20, 2024
1 parent 1fe8a29 commit 7e98f61
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions crates/nu-cli/src/reedline_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion crates/nu-utils/src/sample_config/default_config.nu
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ $env.config = {
text: green
selected_text: {attr: r}
description_text: yellow
match_text: {attr: u}
selected_match_text: {attr: ur}
}
}
{
Expand All @@ -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}
}
}
{
Expand Down

0 comments on commit 7e98f61

Please sign in to comment.