Add last-color optimization for crossterm intermediate buffer optimization.
@@ -328,6 +328,8 @@ fn partial_redraw(buffer : &mut Vec<OutputBuffer>) {
}
// Render just the dirty tiles
+ let mut last_bg = RGBA::new();
+ let mut last_fg = RGBA::new();
dirty.iter().for_each(|idx| {
let x = idx % width as usize;
let y = idx / width as usize;
@@ -338,6 +340,8 @@ fn partial_redraw(buffer : &mut Vec<OutputBuffer>) {
cursor::MoveTo(x as u16, y as u16)
)
.expect("Command fail");
+
+ if t.fg != last_fg {
queue!(
stdout(),
crossterm::style::SetForegroundColor(crossterm::style::Color::Rgb {
@@ -347,6 +351,10 @@ fn partial_redraw(buffer : &mut Vec<OutputBuffer>) {
})
)
.expect("Command fail");
+ last_fg = t.fg;
+ }
+
+ if t.bg != last_bg {
queue!(
stdout(),
crossterm::style::SetBackgroundColor(crossterm::style::Color::Rgb {
@@ -356,6 +364,8 @@ fn partial_redraw(buffer : &mut Vec<OutputBuffer>) {
})
)
.expect("Command fail");
+ last_bg = t.bg;
+ }
queue!(stdout(), Print(to_char(t.glyph as u8))).expect("Command fail");
});
}
\ No newline at end of file
