mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-10 07:04:17 +00:00
perf(crossterm): Speed up fg/bg color setting
Use Crossterm SetColors instead of SetForegroundColor and SetBackgroundColor. In https://github.com/crossterm-rs/crossterm/pull/879 I changed the SetColors command to write both colors at once with a single write instead of multiple writes that more bytes. This led to a 15-25% fps increase when testing the colors_rgb example on iTerm2 on an M2 Macbook Pro.
This commit is contained in:
parent
4392759501
commit
af8da7f06c
1 changed files with 6 additions and 9 deletions
|
@ -10,8 +10,8 @@ use crossterm::{
|
|||
cursor::{Hide, MoveTo, Show},
|
||||
execute, queue,
|
||||
style::{
|
||||
Attribute as CAttribute, Attributes as CAttributes, Color as CColor, ContentStyle, Print,
|
||||
SetAttribute, SetBackgroundColor, SetForegroundColor,
|
||||
Attribute as CAttribute, Attributes as CAttributes, Color as CColor, Colors, ContentStyle,
|
||||
Print, SetAttribute, SetBackgroundColor, SetColors, SetForegroundColor,
|
||||
},
|
||||
terminal::{self, Clear},
|
||||
};
|
||||
|
@ -145,14 +145,11 @@ where
|
|||
diff.queue(&mut self.writer)?;
|
||||
modifier = cell.modifier;
|
||||
}
|
||||
if cell.fg != fg {
|
||||
let color = CColor::from(cell.fg);
|
||||
queue!(self.writer, SetForegroundColor(color))?;
|
||||
if cell.fg != fg || cell.bg != bg {
|
||||
let fg_color = CColor::from(cell.fg);
|
||||
let bg_color = CColor::from(cell.bg);
|
||||
queue!(self.writer, SetColors(Colors::new(fg_color, bg_color)))?;
|
||||
fg = cell.fg;
|
||||
}
|
||||
if cell.bg != bg {
|
||||
let color = CColor::from(cell.bg);
|
||||
queue!(self.writer, SetBackgroundColor(color))?;
|
||||
bg = cell.bg;
|
||||
}
|
||||
#[cfg(feature = "underline-color")]
|
||||
|
|
Loading…
Reference in a new issue