crossterm: Render with synchronized output

This takes advantage of the synchronized output commands from crossterm
to tell the terminal emulator when to pause and resume drawing. This
should feel snappier and have fewer visual artifacts like tearing when
we update the screen with many changes (scrolling or changing theme for
example).
This commit is contained in:
Michael Davis 2025-03-28 12:49:27 -04:00
parent 9558cb4002
commit 2234d94b50
No known key found for this signature in database

View file

@ -146,6 +146,10 @@ where
}
}
}
fn supports_synchronized_output(&self) -> bool {
self.features().synchronized_output_mode != SynchronizedOutputMode::NotSupported
}
}
impl<W> Write for CrosstermBackend<W>
@ -268,6 +272,10 @@ where
where
I: Iterator<Item = (u16, u16, &'a Cell)>,
{
if self.supports_synchronized_output() {
queue!(self.buffer, terminal::BeginSynchronizedUpdate)?;
}
let mut fg = Color::Reset;
let mut bg = Color::Reset;
let mut underline_color = Color::Reset;
@ -326,7 +334,13 @@ where
SetForegroundColor(CColor::Reset),
SetBackgroundColor(CColor::Reset),
SetAttribute(CAttribute::Reset)
)
)?;
if self.supports_synchronized_output() {
execute!(self.buffer, terminal::EndSynchronizedUpdate)?;
}
Ok(())
}
fn hide_cursor(&mut self) -> io::Result<()> {