in crates/alacritty_terminal/src/term/mod.rs [1440:1540]
fn terminal_attribute(&mut self, attr: Attr) {
trace!("Setting attribute: {:?}", attr);
let cursor = &mut self.grid.cursor;
let color_match = |color: Color, vtermcolor: shell_color::VTermColor| match (color, vtermcolor) {
(Color::Named(name), shell_color::VTermColor::Indexed { idx }) => (name as usize % 256) == idx as usize,
(Color::Indexed(i), shell_color::VTermColor::Indexed { idx }) => i == idx,
(Color::Spec(rgb), shell_color::VTermColor::Rgb { red, green, blue }) => {
rgb.r == red && rgb.g == green && rgb.b == blue
},
_ => false,
};
macro_rules! set_in_suggestion {
() => {
let fg = cursor.template.fg;
let bg = cursor.template.bg;
let mut in_suggestion = false;
if let Some(suggestion_color) = match self.shell_state.get_context().shell.as_deref() {
Some("fish") => Some(self.shell_state().fish_suggestion_color.as_ref()),
Some("zsh") => Some(match self.shell_state().fig_autosuggestion_color {
Some(ref color) => Some(color),
None => self.shell_state().zsh_autosuggestion_color.as_ref(),
}),
Some("nu") => Some(self.shell_state().nu_hint_color.as_ref()),
_ => None,
}
.flatten()
{
let fg_matches = match suggestion_color.fg() {
Some(suggestion_fg) => color_match(fg, suggestion_fg),
None => true,
};
let bg_matches = match suggestion_color.bg() {
Some(suggestion_bg) => color_match(bg, suggestion_bg),
None => true,
};
if fg_matches && bg_matches {
in_suggestion = true;
}
};
self.grid
.cursor
.template
.fig_flags
.set(FigFlags::IN_SUGGESTION, in_suggestion);
};
}
match attr {
Attr::Foreground(color) => {
cursor.template.fg = color;
set_in_suggestion!();
},
Attr::Background(color) => {
cursor.template.bg = color;
set_in_suggestion!();
},
Attr::Reset => {
cursor.template.fg = Color::Named(NamedColor::Foreground);
cursor.template.bg = Color::Named(NamedColor::Background);
cursor.template.flags = ShellFlags::empty();
set_in_suggestion!();
},
Attr::Reverse => cursor.template.flags.insert(ShellFlags::INVERSE),
Attr::CancelReverse => cursor.template.flags.remove(ShellFlags::INVERSE),
Attr::Bold => cursor.template.flags.insert(ShellFlags::BOLD),
Attr::CancelBold => cursor.template.flags.remove(ShellFlags::BOLD),
Attr::Dim => cursor.template.flags.insert(ShellFlags::DIM),
Attr::CancelBoldDim => cursor.template.flags.remove(ShellFlags::BOLD | ShellFlags::DIM),
Attr::Italic => cursor.template.flags.insert(ShellFlags::ITALIC),
Attr::CancelItalic => cursor.template.flags.remove(ShellFlags::ITALIC),
Attr::Underline => {
cursor.template.flags.remove(ShellFlags::DOUBLE_UNDERLINE);
cursor.template.flags.insert(ShellFlags::UNDERLINE);
},
Attr::DoubleUnderline => {
cursor.template.flags.remove(ShellFlags::UNDERLINE);
cursor.template.flags.insert(ShellFlags::DOUBLE_UNDERLINE);
},
Attr::CancelUnderline => {
cursor
.template
.flags
.remove(ShellFlags::UNDERLINE | ShellFlags::DOUBLE_UNDERLINE);
},
Attr::Hidden => cursor.template.flags.insert(ShellFlags::HIDDEN),
Attr::CancelHidden => cursor.template.flags.remove(ShellFlags::HIDDEN),
Attr::Strike => cursor.template.flags.insert(ShellFlags::STRIKEOUT),
Attr::CancelStrike => cursor.template.flags.remove(ShellFlags::STRIKEOUT),
_ => {
trace!("Term got unhandled attr: {:?}", attr);
},
}
}