mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 00:41:15 -03:00
Move text face/color parsing functions into new module
No other change.
This commit is contained in:
@@ -27,8 +27,8 @@
|
|||||||
parse_util_locate_cmdsubst_range, parse_util_slice_length, MaybeParentheses,
|
parse_util_locate_cmdsubst_range, parse_util_slice_length, MaybeParentheses,
|
||||||
};
|
};
|
||||||
use crate::path::{path_as_implicit_cd, path_get_cdpath, path_get_path, paths_are_same_file};
|
use crate::path::{path_as_implicit_cd, path_get_cdpath, path_get_path, paths_are_same_file};
|
||||||
use crate::terminal::{parse_text_face, Outputter};
|
use crate::terminal::Outputter;
|
||||||
use crate::text_face::{TextFace, TextStyling};
|
use crate::text_face::{parse_text_face, TextFace, TextStyling};
|
||||||
use crate::threads::assert_is_background_thread;
|
use crate::threads::assert_is_background_thread;
|
||||||
use crate::tokenizer::{variable_assignment_equals_pos, PipeOrRedir};
|
use crate::tokenizer::{variable_assignment_equals_pos, PipeOrRedir};
|
||||||
use crate::wchar::{wstr, WString, L};
|
use crate::wchar::{wstr, WString, L};
|
||||||
@@ -195,7 +195,7 @@ pub(crate) fn parse_text_face_for_highlight(
|
|||||||
let Some(var) = maybe_var else {
|
let Some(var) = maybe_var else {
|
||||||
return (Color::Normal, TextStyling::empty());
|
return (Color::Normal, TextStyling::empty());
|
||||||
};
|
};
|
||||||
let (mut color, style) = parse_text_face(var, is_background);
|
let (mut color, style) = parse_text_face(var.as_list(), is_background);
|
||||||
if color.is_none() {
|
if color.is_none() {
|
||||||
color = Color::Normal;
|
color = Color::Normal;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,6 @@
|
|||||||
signal_check_cancel, signal_clear_cancel, signal_reset_handlers, signal_set_handlers,
|
signal_check_cancel, signal_clear_cancel, signal_reset_handlers, signal_set_handlers,
|
||||||
signal_set_handlers_once,
|
signal_set_handlers_once,
|
||||||
};
|
};
|
||||||
use crate::terminal::parse_text_face;
|
|
||||||
use crate::terminal::BufferedOutputter;
|
use crate::terminal::BufferedOutputter;
|
||||||
use crate::terminal::Output;
|
use crate::terminal::Output;
|
||||||
use crate::terminal::Outputter;
|
use crate::terminal::Outputter;
|
||||||
@@ -143,6 +142,7 @@
|
|||||||
SYNCHRONIZED_OUTPUT_SUPPORTED,
|
SYNCHRONIZED_OUTPUT_SUPPORTED,
|
||||||
};
|
};
|
||||||
use crate::termsize::{termsize_invalidate_tty, termsize_last, termsize_update};
|
use crate::termsize::{termsize_invalidate_tty, termsize_last, termsize_update};
|
||||||
|
use crate::text_face::parse_text_face;
|
||||||
use crate::text_face::TextFace;
|
use crate::text_face::TextFace;
|
||||||
use crate::threads::{
|
use crate::threads::{
|
||||||
assert_is_background_thread, assert_is_main_thread, iothread_service_main_with_timeout,
|
assert_is_background_thread, assert_is_main_thread, iothread_service_main_with_timeout,
|
||||||
@@ -1661,7 +1661,7 @@ fn paint_layout(&mut self, reason: &wstr, is_final_rendering: bool) {
|
|||||||
.vars()
|
.vars()
|
||||||
.get_unless_empty(L!("fish_color_search_match"))
|
.get_unless_empty(L!("fish_color_search_match"))
|
||||||
.is_some_and(|var| {
|
.is_some_and(|var| {
|
||||||
let (color, _flags) = parse_text_face(&var, false);
|
let (color, _flags) = parse_text_face(var.as_list(), false);
|
||||||
!color.is_none()
|
!color.is_none()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
use crate::color::{Color, Color24};
|
use crate::color::{Color, Color24};
|
||||||
use crate::common::ToCString;
|
use crate::common::ToCString;
|
||||||
use crate::common::{self, escape_string, wcs2string, wcs2string_appending, EscapeStringStyle};
|
use crate::common::{self, escape_string, wcs2string, wcs2string_appending, EscapeStringStyle};
|
||||||
use crate::env::EnvVar;
|
|
||||||
use crate::future_feature_flags::{self, FeatureFlag};
|
use crate::future_feature_flags::{self, FeatureFlag};
|
||||||
use crate::global_safety::RelaxedAtomicBool;
|
use crate::global_safety::RelaxedAtomicBool;
|
||||||
use crate::screen::{is_dumb, only_grayscale};
|
use crate::screen::{is_dumb, only_grayscale};
|
||||||
use crate::text_face::{TextFace, TextStyling};
|
use crate::text_face::TextFace;
|
||||||
use crate::threads::MainThread;
|
use crate::threads::MainThread;
|
||||||
use crate::wchar::prelude::*;
|
use crate::wchar::prelude::*;
|
||||||
use crate::FLOGF;
|
use crate::FLOGF;
|
||||||
@@ -760,60 +759,6 @@ pub fn best_color(candidates: &[Color], support: ColorSupport) -> Color {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_text_face(var: &EnvVar, is_background: bool) -> (Color, TextStyling) {
|
|
||||||
let mut style = TextStyling::empty();
|
|
||||||
let mut candidates: Vec<Color> = Vec::new();
|
|
||||||
|
|
||||||
let prefix = L!("--background=");
|
|
||||||
|
|
||||||
let mut next_is_background = false;
|
|
||||||
for next in var.as_list() {
|
|
||||||
let mut color_name = None;
|
|
||||||
#[allow(clippy::collapsible_else_if)]
|
|
||||||
if is_background {
|
|
||||||
if next_is_background {
|
|
||||||
color_name = Some(next.as_utfstr());
|
|
||||||
next_is_background = false;
|
|
||||||
} else if next.starts_with(prefix) {
|
|
||||||
// Look for something like "--background=red".
|
|
||||||
color_name = Some(next.slice_from(prefix.char_count()));
|
|
||||||
} else if next == "--background" || next == "-b" {
|
|
||||||
// Without argument attached the next token is the color
|
|
||||||
// - if it's another option it's an error.
|
|
||||||
next_is_background = true;
|
|
||||||
} else if next == "--reverse" || next == "-r" {
|
|
||||||
// Reverse should be meaningful in either context
|
|
||||||
style |= TextStyling::REVERSE;
|
|
||||||
} else if next.starts_with("-b") {
|
|
||||||
// Look for something like "-bred".
|
|
||||||
// Yes, that length is hardcoded.
|
|
||||||
color_name = Some(next.slice_from(2));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if next == "--bold" || next == "-o" {
|
|
||||||
style |= TextStyling::BOLD;
|
|
||||||
} else if next == "--underline" || next == "-u" {
|
|
||||||
style |= TextStyling::UNDERLINE;
|
|
||||||
} else if next == "--italics" || next == "-i" {
|
|
||||||
style |= TextStyling::ITALICS;
|
|
||||||
} else if next == "--dim" || next == "-d" {
|
|
||||||
style |= TextStyling::DIM;
|
|
||||||
} else if next == "--reverse" || next == "-r" {
|
|
||||||
style |= TextStyling::REVERSE;
|
|
||||||
} else {
|
|
||||||
color_name = Some(next.as_utfstr());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(color) = color_name.and_then(Color::from_wstr) {
|
|
||||||
candidates.push(color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let color = best_color(&candidates, get_color_support());
|
|
||||||
(color, style)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The [`Term`] singleton. Initialized via a call to [`setup()`] and surfaced to the outside world via [`term()`].
|
/// The [`Term`] singleton. Initialized via a call to [`setup()`] and surfaced to the outside world via [`term()`].
|
||||||
///
|
///
|
||||||
/// We can't just use an [`AtomicPtr<Arc<Term>>`](std::sync::atomic::AtomicPtr) here because there's a race condition when the old Arc
|
/// We can't just use an [`AtomicPtr<Arc<Term>>`](std::sync::atomic::AtomicPtr) here because there's a race condition when the old Arc
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
|
||||||
use crate::color::Color;
|
use crate::color::Color;
|
||||||
|
use crate::terminal::{best_color, get_color_support};
|
||||||
|
use crate::wchar::prelude::*;
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
||||||
@@ -84,3 +86,57 @@ pub fn set_reverse(&mut self, reverse: bool) {
|
|||||||
self.style.set(TextStyling::REVERSE, reverse)
|
self.style.set(TextStyling::REVERSE, reverse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_text_face(arguments: &[WString], is_background: bool) -> (Color, TextStyling) {
|
||||||
|
let mut style = TextStyling::empty();
|
||||||
|
let mut candidates: Vec<Color> = Vec::new();
|
||||||
|
|
||||||
|
let prefix = L!("--background=");
|
||||||
|
|
||||||
|
let mut next_is_background = false;
|
||||||
|
for arg in arguments {
|
||||||
|
let mut color_name = None;
|
||||||
|
#[allow(clippy::collapsible_else_if)]
|
||||||
|
if is_background {
|
||||||
|
if next_is_background {
|
||||||
|
color_name = Some(arg.as_utfstr());
|
||||||
|
next_is_background = false;
|
||||||
|
} else if arg.starts_with(prefix) {
|
||||||
|
// Look for something like "--background=red".
|
||||||
|
color_name = Some(arg.slice_from(prefix.char_count()));
|
||||||
|
} else if arg == "--background" || arg == "-b" {
|
||||||
|
// Without argument attached the next token is the color
|
||||||
|
// - if it's another option it's an error.
|
||||||
|
next_is_background = true;
|
||||||
|
} else if arg == "--reverse" || arg == "-r" {
|
||||||
|
// Reverse should be meaningful in either context
|
||||||
|
style |= TextStyling::REVERSE;
|
||||||
|
} else if arg.starts_with("-b") {
|
||||||
|
// Look for something like "-bred".
|
||||||
|
// Yes, that length is hardcoded.
|
||||||
|
color_name = Some(arg.slice_from(2));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if arg == "--bold" || arg == "-o" {
|
||||||
|
style |= TextStyling::BOLD;
|
||||||
|
} else if arg == "--underline" || arg == "-u" {
|
||||||
|
style |= TextStyling::UNDERLINE;
|
||||||
|
} else if arg == "--italics" || arg == "-i" {
|
||||||
|
style |= TextStyling::ITALICS;
|
||||||
|
} else if arg == "--dim" || arg == "-d" {
|
||||||
|
style |= TextStyling::DIM;
|
||||||
|
} else if arg == "--reverse" || arg == "-r" {
|
||||||
|
style |= TextStyling::REVERSE;
|
||||||
|
} else {
|
||||||
|
color_name = Some(arg.as_utfstr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(color) = color_name.and_then(Color::from_wstr) {
|
||||||
|
candidates.push(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let color = best_color(&candidates, get_color_support());
|
||||||
|
(color, style)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user