aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2021-08-19 19:02:05 +0200
committerGitHub <noreply@github.com>2021-08-19 19:02:05 +0200
commit210086506301d16caadf40dd06b189a758debbf1 (patch)
treec79496e4309a3f9695b91c88d0efcce9ef26d418
parentFix scrolling (#650) (diff)
downloadsl0ppij-210086506301d16caadf40dd06b189a758debbf1.tar.gz
sl0ppij-210086506301d16caadf40dd06b189a758debbf1.tar.xz
sl0ppij-210086506301d16caadf40dd06b189a758debbf1.zip
fix(performance): undo degredation introduced in 646 (#651)
* fix(performance): undo degredation introduced in 646 * style(fmt): make rustfmt happy * style(fmt): make clippy happy
-rw-r--r--zellij-server/src/panes/grid.rs31
-rw-r--r--zellij-server/src/panes/terminal_character.rs49
-rw-r--r--zellij-server/src/panes/terminal_pane.rs4
3 files changed, 27 insertions, 57 deletions
diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs
index 85910f3e..f42c1dbc 100644
--- a/zellij-server/src/panes/grid.rs
+++ b/zellij-server/src/panes/grid.rs
@@ -348,7 +348,7 @@ pub struct Grid {
colors: Palette,
output_buffer: OutputBuffer,
title_stack: Vec<String>,
- pub changed_colors: [Option<AnsiCode>; 256],
+ pub changed_colors: Option<[Option<AnsiCode>; 256]>,
pub should_render: bool,
pub cursor_key_mode: bool, // DECCKM - when set, cursor keys should send ANSI direction codes (eg. "OD") instead of the arrow keys (eg. "")
pub erasure_mode: bool, // ERM
@@ -402,7 +402,7 @@ impl Grid {
selection: Default::default(),
title_stack: vec![],
title: None,
- changed_colors: [None; 256],
+ changed_colors: None,
}
}
pub fn render_full_viewport(&mut self) {
@@ -1227,7 +1227,7 @@ impl Grid {
self.disable_linewrap = false;
self.cursor.change_shape(CursorShape::Block);
self.output_buffer.update_all_lines();
- self.changed_colors = [None; 256];
+ self.changed_colors = None;
}
fn set_preceding_character(&mut self, terminal_character: TerminalCharacter) {
self.preceding_char = Some(terminal_character);
@@ -1356,22 +1356,12 @@ impl Perform for Grid {
fn print(&mut self, c: char) {
let c = self.cursor.charsets[self.active_charset].map(c);
- // we add the changed_colors here instead of changing the actual colors on the
- // TerminalCharacter in real time because these changed colors also affect the area around
- // the character (eg. empty space after it)
- // on the other hand, we must do it here and not at render-time because then it would be
- // wiped out when one scrolls
- let styles = self
- .cursor
- .pending_styles
- .changed_colors(self.changed_colors);
-
// apparently, building TerminalCharacter like this without a "new" method
// is a little faster
let terminal_character = TerminalCharacter {
character: c,
width: c.width().unwrap_or(0),
- styles,
+ styles: self.cursor.pending_styles,
};
self.set_preceding_character(terminal_character);
self.add_character(terminal_character);
@@ -1447,7 +1437,10 @@ impl Perform for Grid {
let index = parse_number(chunk[0]);
let color = xparse_color(chunk[1]);
if let (Some(i), Some(c)) = (index, color) {
- self.changed_colors[i as usize] = Some(c);
+ if self.changed_colors.is_none() {
+ self.changed_colors = Some([None; 256]);
+ }
+ self.changed_colors.as_mut().unwrap()[i as usize] = Some(c);
return;
}
}
@@ -1526,16 +1519,16 @@ impl Perform for Grid {
b"104" => {
// Reset all color indexes when no parameters are given.
if params.len() == 1 {
- for i in 0..256 {
- self.changed_colors[i] = None;
- }
+ self.changed_colors = None;
return;
}
// Reset color indexes given as parameters.
for param in &params[1..] {
if let Some(index) = parse_number(param) {
- self.changed_colors[index as usize] = None
+ if self.changed_colors.is_some() {
+ self.changed_colors.as_mut().unwrap()[index as usize] = None
+ }
}
}
diff --git a/zellij-server/src/panes/terminal_character.rs b/zellij-server/src/panes/terminal_character.rs
index a17c9d7e..2e1a018d 100644
--- a/zellij-server/src/panes/terminal_character.rs
+++ b/zellij-server/src/panes/terminal_character.rs
@@ -21,7 +21,6 @@ pub const EMPTY_TERMINAL_CHARACTER: TerminalCharacter = TerminalCharacter {
bold: Some(AnsiCode::Reset),
dim: Some(AnsiCode::Reset),
italic: Some(AnsiCode::Reset),
- changed_colors: None,
},
};
@@ -110,7 +109,6 @@ pub struct CharacterStyles {
pub bold: Option<AnsiCode>,
pub dim: Option<AnsiCode>,
pub italic: Option<AnsiCode>,
- pub changed_colors: Option<[Option<AnsiCode>; 256]>,
}
impl Default for CharacterStyles {
@@ -127,7 +125,6 @@ impl Default for CharacterStyles {
bold: None,
dim: None,
italic: None,
- changed_colors: None,
}
}
}
@@ -180,10 +177,6 @@ impl CharacterStyles {
self.strike = strike_code;
self
}
- pub fn changed_colors(mut self, changed_colors: [Option<AnsiCode>; 256]) -> Self {
- self.changed_colors = Some(changed_colors);
- self
- }
pub fn clear(&mut self) {
self.foreground = None;
self.background = None;
@@ -200,6 +193,7 @@ impl CharacterStyles {
pub fn update_and_return_diff(
&mut self,
new_styles: &CharacterStyles,
+ changed_colors: Option<[Option<AnsiCode>; 256]>,
) -> Option<CharacterStyles> {
let mut diff: Option<CharacterStyles> = None;
@@ -329,13 +323,16 @@ impl CharacterStyles {
}
}
- if let Some(changed_colors) = new_styles.changed_colors {
- if let Some(new_diff) = diff.as_mut() {
- diff = Some(new_diff.changed_colors(changed_colors));
- self.changed_colors = new_styles.changed_colors;
- } else {
- diff = Some(CharacterStyles::new().changed_colors(changed_colors));
- self.changed_colors = new_styles.changed_colors;
+ if let Some(changed_colors) = changed_colors {
+ if let Some(AnsiCode::ColorIndex(color_index)) = diff.and_then(|diff| diff.foreground) {
+ if let Some(changed_color) = changed_colors[color_index as usize] {
+ diff.as_mut().unwrap().foreground = Some(changed_color);
+ }
+ }
+ if let Some(AnsiCode::ColorIndex(color_index)) = diff.and_then(|diff| diff.background) {
+ if let Some(changed_color) = changed_colors[color_index as usize] {
+ diff.as_mut().unwrap().background = Some(changed_color);
+ }
}
}
diff
@@ -498,17 +495,7 @@ impl Display for CharacterStyles {
write!(f, "\u{1b}[38;2;{};{};{}m", r, g, b)?;
}
AnsiCode::ColorIndex(color_index) => {
- match self
- .changed_colors
- .and_then(|changed_colors| changed_colors[color_index as usize])
- {
- Some(AnsiCode::RgbCode((r, g, b))) => {
- write!(f, "\u{1b}[38;2;{};{};{}m", r, g, b)?;
- }
- _ => {
- write!(f, "\u{1b}[38;5;{}m", color_index)?;
- }
- }
+ write!(f, "\u{1b}[38;5;{}m", color_index)?;
}
AnsiCode::Reset => {
write!(f, "\u{1b}[39m")?;
@@ -525,17 +512,7 @@ impl Display for CharacterStyles {
write!(f, "\u{1b}[48;2;{};{};{}m", r, g, b)?;
}
AnsiCode::ColorIndex(color_index) => {
- match self
- .changed_colors
- .and_then(|changed_colors| changed_colors[color_index as usize])
- {
- Some(AnsiCode::RgbCode((r, g, b))) => {
- write!(f, "\u{1b}[48;2;{};{};{}m", r, g, b)?;
- }
- _ => {
- write!(f, "\u{1b}[48;5;{}m", color_index)?;
- }
- }
+ write!(f, "\u{1b}[48;5;{}m", color_index)?;
}
AnsiCode::Reset => {
write!(f, "\u{1b}[49m")?;
diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs
index 658ecaf6..e9531819 100644
--- a/zellij-server/src/panes/terminal_pane.rs
+++ b/zellij-server/src/panes/terminal_pane.rs
@@ -236,8 +236,8 @@ impl Pane for TerminalPane {
break;
}
- if let Some(new_styles) =
- character_styles.update_and_return_diff(&t_character.styles)
+ if let Some(new_styles) = character_styles
+ .update_and_return_diff(&t_character.styles, self.grid.changed_colors)
{
vte_output.push_str(&new_styles.to_string());
}