1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-11 13:51:01 -05:00

Show same fg/bg text when inversed

If a cell has a matching foreground and background and is inversed
through the escape or selection, it will now fall back to the default
background on top of the default foreground.

This makes it possible to show invisible text like this by selecting it.

Hidden text is unaffected by this change.

This fixes #2315.
This commit is contained in:
Christian Duerr 2019-04-25 16:51:45 +00:00 committed by GitHub
parent 73e7a95d54
commit e964af8a5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View file

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- On Windows, Alacritty will now use the native DirectWrite font API - On Windows, Alacritty will now use the native DirectWrite font API
- The `start_maximized` window option is now `startup_mode: Maximized` - The `start_maximized` window option is now `startup_mode: Maximized`
- Cells with identical foreground and background will now show their text upon selection/inversion
### Fixed ### Fixed

View file

@ -281,17 +281,19 @@ impl RenderableCell {
let mut bg_rgb = Self::compute_bg_rgb(colors, cell.bg); let mut bg_rgb = Self::compute_bg_rgb(colors, cell.bg);
let selection_background = config.colors().selection.background; let selection_background = config.colors().selection.background;
let bg_alpha = if let (true, Some(col)) = (selected, selection_background) { if let (true, Some(col)) = (selected, selection_background) {
// Override selection background with config colors // Override selection background with config colors
bg_rgb = col; bg_rgb = col;
1.0
} else if selected ^ cell.inverse() { } else if selected ^ cell.inverse() {
// Invert cell fg and bg colors if fg_rgb == bg_rgb && !cell.flags.contains(Flags::HIDDEN) {
mem::swap(&mut fg_rgb, &mut bg_rgb); // Reveal inversed text when fg/bg is the same
Self::compute_bg_alpha(cell.fg) fg_rgb = colors[NamedColor::Background];
} else { bg_rgb = colors[NamedColor::Foreground];
Self::compute_bg_alpha(cell.bg) } else {
}; // Invert cell fg and bg colors
mem::swap(&mut fg_rgb, &mut bg_rgb);
}
}
// Override selection text with config colors // Override selection text with config colors
if let (true, Some(col)) = (selected, config.colors().selection.text) { if let (true, Some(col)) = (selected, config.colors().selection.text) {
@ -304,7 +306,7 @@ impl RenderableCell {
inner: RenderableCellContent::Chars(cell.chars()), inner: RenderableCellContent::Chars(cell.chars()),
fg: fg_rgb, fg: fg_rgb,
bg: bg_rgb, bg: bg_rgb,
bg_alpha, bg_alpha: Self::compute_bg_alpha(colors, bg_rgb),
flags: cell.flags, flags: cell.flags,
} }
} }
@ -347,10 +349,11 @@ impl RenderableCell {
} }
#[inline] #[inline]
fn compute_bg_alpha(bg: Color) -> f32 { fn compute_bg_alpha(colors: &color::List, bg: Rgb) -> f32 {
match bg { if colors[NamedColor::Background] == bg {
Color::Named(NamedColor::Background) => 0.0, 0.
_ => 1.0, } else {
1.
} }
} }