diff --git a/src/output.rs b/src/output.rs index 8833df4a0..740e5ba84 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,5 +1,5 @@ // Generic output functions. -use crate::color::RgbColor; +use crate::color::{self, RgbColor}; use crate::common::{self, wcs2string_appending}; use crate::curses::{self, tparm1, Term}; use crate::env::EnvVar; @@ -493,6 +493,14 @@ pub fn best_color(candidates: &[RgbColor], support: ColorSupport) -> RgbColor { /// In particular, the argument parsing still isn't fully capable. #[allow(clippy::collapsible_else_if)] pub fn parse_color(var: &EnvVar, is_background: bool) -> RgbColor { + let mut result = parse_color_maybe_none(var, is_background); + if result.is_none() { + result.typ = color::Type::Normal; + } + result +} + +pub fn parse_color_maybe_none(var: &EnvVar, is_background: bool) -> RgbColor { let mut is_bold = false; let mut is_underline = false; let mut is_italics = false; @@ -551,9 +559,6 @@ pub fn parse_color(var: &EnvVar, is_background: bool) -> RgbColor { } let mut result = best_color(&candidates, get_color_support()); - if result.is_none() { - result = RgbColor::NORMAL; - } result.set_bold(is_bold); result.set_underline(is_underline); result.set_italics(is_italics); diff --git a/src/reader.rs b/src/reader.rs index ea8e4356c..324c9e71f 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -88,6 +88,7 @@ use crate::nix::isatty; use crate::operation_context::{get_bg_context, OperationContext}; use crate::output::parse_color; +use crate::output::parse_color_maybe_none; use crate::output::Outputter; use crate::pager::{PageRendering, Pager, SelectionMotion}; use crate::panic::AT_EXIT; @@ -1499,8 +1500,15 @@ fn paint_layout(&mut self, reason: &wstr, is_final_rendering: bool) { range.end = colors.len(); } + let explicit_foreground = self + .vars() + .get_unless_empty(L!("fish_color_search_match")) + .is_some_and(|var| !parse_color_maybe_none(&var, false).is_none()); + for color in &mut colors[range] { - color.foreground = HighlightRole::search_match; + if explicit_foreground { + color.foreground = HighlightRole::search_match; + } color.background = HighlightRole::search_match; } }