mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 11:21:15 -03:00
Small refactor of HighlightSpec
This commit is contained in:
committed by
Johannes Altmanninger
parent
db546da3ca
commit
3fdd2d3fc2
@@ -42,9 +42,6 @@ impl HighlightSpec {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
pub fn with_fg(fg: HighlightRole) -> Self {
|
||||
Self::with_fg_bg(fg, HighlightRole::normal)
|
||||
}
|
||||
pub fn with_fg_bg(fg: HighlightRole, bg: HighlightRole) -> Self {
|
||||
Self {
|
||||
foreground: fg,
|
||||
@@ -52,9 +49,15 @@ pub fn with_fg_bg(fg: HighlightRole, bg: HighlightRole) -> Self {
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
pub fn with_fg(fg: HighlightRole) -> Self {
|
||||
Self::with_fg_bg(fg, HighlightRole::normal)
|
||||
}
|
||||
pub fn with_bg(bg: HighlightRole) -> Self {
|
||||
Self::with_fg_bg(HighlightRole::normal, bg)
|
||||
}
|
||||
pub fn with_both(role: HighlightRole) -> Self {
|
||||
Self::with_fg_bg(role, role)
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a string and list of colors of the same size, return the string with ANSI escape sequences
|
||||
|
||||
@@ -293,10 +293,7 @@ fn completion_try_print(
|
||||
|
||||
if !progress_text.is_empty() {
|
||||
let line = rendering.screen_data.add_line();
|
||||
let spec = HighlightSpec::with_fg_bg(
|
||||
HighlightRole::pager_progress,
|
||||
HighlightRole::pager_progress,
|
||||
);
|
||||
let spec = HighlightSpec::with_both(HighlightRole::pager_progress);
|
||||
print_max(
|
||||
CharOffset::None,
|
||||
&progress_text,
|
||||
|
||||
@@ -1621,8 +1621,7 @@ fn paint_layout(&mut self, reason: &wstr, is_final_rendering: bool) {
|
||||
|
||||
// Apply any selection.
|
||||
if let Some(selection) = data.selection {
|
||||
let selection_color =
|
||||
HighlightSpec::with_fg_bg(HighlightRole::selection, HighlightRole::selection);
|
||||
let selection_color = HighlightSpec::with_both(HighlightRole::selection);
|
||||
let end = std::cmp::min(selection.stop, colors.len());
|
||||
for color in &mut colors[selection.start.min(end)..end] {
|
||||
*color = selection_color;
|
||||
@@ -1637,10 +1636,7 @@ fn paint_layout(&mut self, reason: &wstr, is_final_rendering: bool) {
|
||||
pos..pos,
|
||||
vec![
|
||||
if self.flash_autosuggestion {
|
||||
HighlightSpec::with_fg_bg(
|
||||
HighlightRole::search_match,
|
||||
HighlightRole::search_match,
|
||||
)
|
||||
HighlightSpec::with_both(HighlightRole::search_match)
|
||||
} else {
|
||||
HighlightSpec::with_fg(HighlightRole::autosuggestion)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user