Replace tuple return value with struct

The parent commit got rid of the is_background parameter that determined
the meaning of the return value (fg/bg); since we always return both now,
give them names.
This commit is contained in:
Johannes Altmanninger
2025-04-15 19:50:45 +02:00
parent 9c39cab239
commit d33cc5ea24
3 changed files with 21 additions and 19 deletions

View File

@@ -28,7 +28,7 @@
};
use crate::path::{path_as_implicit_cd, path_get_cdpath, path_get_path, paths_are_same_file};
use crate::terminal::Outputter;
use crate::text_face::{parse_text_face, TextFace, TextStyling};
use crate::text_face::{parse_text_face, SpecifiedTextFace, TextFace, TextStyling};
use crate::threads::assert_is_background_thread;
use crate::tokenizer::{variable_assignment_equals_pos, PipeOrRedir};
use crate::wchar::{wstr, WString, L};
@@ -177,21 +177,22 @@ pub(crate) fn parse_text_face_for_highlight(
) -> TextFace {
let parse_var = |maybe_var: Option<&EnvVar>| {
let Some(var) = maybe_var else {
return (
Some(Color::Normal),
Some(Color::Normal),
TextStyling::default(),
);
return SpecifiedTextFace {
fg: Some(Color::Normal),
bg: Some(Color::Normal),
style: TextStyling::default(),
};
};
parse_text_face(var.as_list())
};
let (fg, _bg, mut style) = parse_var(fg_var);
let (_fg, bg, bg_style) = parse_var(bg_var);
let fg = fg.unwrap_or(Color::Normal);
let bg = bg.unwrap_or(Color::Normal);
let fg_face = parse_var(fg_var);
let bg_face = parse_var(bg_var);
let fg = fg_face.fg.unwrap_or(Color::Normal);
let bg = bg_face.bg.unwrap_or(Color::Normal);
// In case the background role is different from the foreground one, we ignore its style
// except for reverse mode.
style.reverse |= bg_style.reverse;
let mut style = fg_face.style;
style.reverse |= bg_face.style.reverse;
TextFace { fg, bg, style }
}

View File

@@ -1660,10 +1660,7 @@ fn paint_layout(&mut self, reason: &wstr, is_final_rendering: bool) {
let explicit_foreground = self
.vars()
.get_unless_empty(L!("fish_color_search_match"))
.is_some_and(|var| {
let (fg, _bg, _style) = parse_text_face(var.as_list());
!fg.is_none()
});
.is_some_and(|var| parse_text_face(var.as_list()).fg.is_some());
for color in &mut colors[range] {
if explicit_foreground {

View File

@@ -96,9 +96,13 @@ pub fn new(fg: Color, bg: Color, style: TextStyling) -> Self {
}
}
pub(crate) fn parse_text_face(
arguments: &[WString],
) -> (Option<Color>, Option<Color>, TextStyling) {
pub(crate) struct SpecifiedTextFace {
pub(crate) fg: Option<Color>,
pub(crate) bg: Option<Color>,
pub(crate) style: TextStyling,
}
pub(crate) fn parse_text_face(arguments: &[WString]) -> SpecifiedTextFace {
let mut argv: Vec<&wstr> = Some(L!(""))
.into_iter()
.chain(arguments.iter().map(|s| s.as_utfstr()))
@@ -124,7 +128,7 @@ pub(crate) fn parse_text_face(
let bg = bgcolor.and_then(Color::from_wstr);
assert!(fg.map_or(true, |fg| !fg.is_none()));
assert!(bg.map_or(true, |bg| !bg.is_none()));
(fg, bg, style)
SpecifiedTextFace { fg, bg, style }
}
pub(crate) struct TextFaceArgsAndOptions<'a> {