Skip to content

Commit

Permalink
Fix alacritty_terminal not emitting damage on color change
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov authored Feb 7, 2022
1 parent 998250f commit c2959f4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions alacritty_terminal/src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,12 @@ impl<T: EventListener> Handler for Term<T> {
#[inline]
fn set_color(&mut self, index: usize, color: Rgb) {
trace!("Setting color[{}] = {:?}", index, color);

// Damage terminal if the color changed and it's not the cursor.
if index != NamedColor::Cursor as usize && self.colors[index] != Some(color) {
self.mark_fully_damaged();
}

self.colors[index] = Some(color);
}

Expand All @@ -1645,6 +1651,12 @@ impl<T: EventListener> Handler for Term<T> {
#[inline]
fn reset_color(&mut self, index: usize) {
trace!("Resetting color[{}]", index);

// Damage terminal if the color changed and it's not the cursor.
if index != NamedColor::Cursor as usize && self.colors[index].is_some() {
self.mark_fully_damaged();
}

self.colors[index] = None;
}

Expand Down Expand Up @@ -2992,6 +3004,23 @@ mod tests {
assert!(!term.damage.is_fully_damaged);
term.reset_damage();

let color_index = 257;
term.set_color(color_index, Rgb::default());
assert!(term.damage.is_fully_damaged);
term.reset_damage();

// Setting the same color once again shouldn't trigger full damage.
term.set_color(color_index, Rgb::default());
assert!(!term.damage.is_fully_damaged);

term.reset_color(color_index);
assert!(term.damage.is_fully_damaged);
term.reset_damage();

// We shouldn't trigger fully damage when cursor gets update.
term.set_color(NamedColor::Cursor as usize, Rgb::default());
assert!(!term.damage.is_fully_damaged);

// However requesting terminal damage should mark terminal as fully damaged in `Insert`
// mode.
let _ = term.damage(None);
Expand Down

0 comments on commit c2959f4

Please sign in to comment.