diff options
author | Aram Drevekenin <aram@poor.dev> | 2022-11-21 20:07:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-21 20:07:24 +0100 |
commit | 63e7531c48f1c8fbe916e3ac5475cf36201f52b8 (patch) | |
tree | 534e56cf9cf2924cec94a32bef1b6bcf92760209 /default-plugins/tab-bar/src/main.rs | |
parent | 5ad0429adc3bbb33b2578d3e699f2e61d6d0b940 (diff) |
performance(rendering): improve rendering performance (#1960)
* refactor(plugins): plugins now need to explicitly ask to be rendered
* performance(render): remove various needless renders
* performance(render): cache boundaries
* performance(render): adjust tests and cache cursor location/shape
* style(comment): remove outdated
* style(fmt): rustfmt
Diffstat (limited to 'default-plugins/tab-bar/src/main.rs')
-rw-r--r-- | default-plugins/tab-bar/src/main.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs index f03102610..6f0456a8f 100644 --- a/default-plugins/tab-bar/src/main.rs +++ b/default-plugins/tab-bar/src/main.rs @@ -22,7 +22,7 @@ struct State { active_tab_idx: usize, mode_info: ModeInfo, mouse_click_pos: usize, - should_render: bool, + should_change_tab: bool, } static ARROW_SEPARATOR: &str = ""; @@ -39,13 +39,23 @@ impl ZellijPlugin for State { ]); } - fn update(&mut self, event: Event) { + fn update(&mut self, event: Event) -> bool { + let mut should_render = false; match event { - Event::ModeUpdate(mode_info) => self.mode_info = mode_info, + Event::ModeUpdate(mode_info) => { + if self.mode_info != mode_info { + should_render = true; + } + self.mode_info = mode_info; + }, Event::TabUpdate(tabs) => { if let Some(active_tab_index) = tabs.iter().position(|t| t.active) { // tabs are indexed starting from 1 so we need to add 1 - self.active_tab_idx = active_tab_index + 1; + let active_tab_idx = active_tab_index + 1; + if self.active_tab_idx != active_tab_idx || self.tabs != tabs { + should_render = true; + } + self.active_tab_idx = active_tab_idx; self.tabs = tabs; } else { eprintln!("Could not find active tab."); @@ -53,13 +63,18 @@ impl ZellijPlugin for State { }, Event::Mouse(me) => match me { Mouse::LeftClick(_, col) => { + if self.mouse_click_pos != col { + should_render = true; + self.should_change_tab = true; + } self.mouse_click_pos = col; - self.should_render = true; }, Mouse::ScrollUp(_) => { + should_render = true; switch_tab_to(min(self.active_tab_idx + 1, self.tabs.len()) as u32); }, Mouse::ScrollDown(_) => { + should_render = true; switch_tab_to(max(self.active_tab_idx.saturating_sub(1), 1) as u32); }, _ => {}, @@ -68,6 +83,7 @@ impl ZellijPlugin for State { eprintln!("Got unrecognized event: {:?}", event); }, } + should_render } fn render(&mut self, _rows: usize, cols: usize) { @@ -110,7 +126,7 @@ impl ZellijPlugin for State { for bar_part in tab_line { s = format!("{}{}", s, &bar_part.part); - if self.should_render + if self.should_change_tab && self.mouse_click_pos >= len_cnt && self.mouse_click_pos < len_cnt + bar_part.len && bar_part.tab_index.is_some() @@ -133,6 +149,6 @@ impl ZellijPlugin for State { print!("{}\u{1b}[48;5;{}m\u{1b}[0K", s, color); }, } - self.should_render = false; + self.should_change_tab = false; } } |