diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-12-17 13:46:19 +0100 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-12-17 13:46:19 +0100 |
| commit | f51455d02e14c447fe174b2ae4869c24e83349d4 (patch) | |
| tree | f441f8f2181fceab62975041b6b5b4f102e8f174 /src/widgets | |
| parent | feat: add more benches for widgets (diff) | |
| download | sl0pstatus-f51455d02e14c447fe174b2ae4869c24e83349d4.tar.gz sl0pstatus-f51455d02e14c447fe174b2ae4869c24e83349d4.tar.xz sl0pstatus-f51455d02e14c447fe174b2ae4869c24e83349d4.zip | |
feat: perf + mem optimization of rendering
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/command.rs | 10 | ||||
| -rw-r--r-- | src/widgets/datetime.rs | 6 | ||||
| -rw-r--r-- | src/widgets/mode.rs | 6 | ||||
| -rw-r--r-- | src/widgets/session.rs | 8 | ||||
| -rw-r--r-- | src/widgets/swap_layout.rs | 4 | ||||
| -rw-r--r-- | src/widgets/tabs.rs | 12 | ||||
| -rw-r--r-- | src/widgets/widget.rs | 4 |
7 files changed, 25 insertions, 25 deletions
diff --git a/src/widgets/command.rs b/src/widgets/command.rs index ea6a6fc..8a7a3f8 100644 --- a/src/widgets/command.rs +++ b/src/widgets/command.rs @@ -43,7 +43,7 @@ impl CommandWidget { } impl Widget for CommandWidget { - fn process(&self, name: &str, state: ZellijState) -> String { + fn process(&self, name: &str, state: &ZellijState) -> String { let command_config = match self.config.get(name) { Some(cc) => cc, None => { @@ -51,7 +51,7 @@ impl Widget for CommandWidget { } }; - run_command_if_needed(command_config.clone(), name, state.clone()); + run_command_if_needed(command_config.clone(), name, state); let command_result = match state.command_results.get(name) { Some(cr) => cr, @@ -89,13 +89,13 @@ impl Widget for CommandWidget { ); } - command_config.format.format_string(content) + command_config.format.format_string(&content) } - fn process_click(&self, _state: ZellijState, _pos: usize) {} + fn process_click(&self, _state: &ZellijState, _pos: usize) {} } -fn run_command_if_needed(command_config: CommandConfig, name: &str, state: ZellijState) { +fn run_command_if_needed(command_config: CommandConfig, name: &str, state: &ZellijState) { let ts = Local::now(); let last_run = get_timestamp_from_event_or_default(name, state.clone(), command_config.interval); diff --git a/src/widgets/datetime.rs b/src/widgets/datetime.rs index c75f816..b6a1193 100644 --- a/src/widgets/datetime.rs +++ b/src/widgets/datetime.rs @@ -44,7 +44,7 @@ impl DateTimeWidget { } impl Widget for DateTimeWidget { - fn process(&self, _name: &str ,_state: ZellijState) -> String { + fn process(&self, _name: &str ,_state: &ZellijState) -> String { let mut output = self.color_format.content.clone(); if output.contains("{format}") { let date = Local::now(); @@ -60,8 +60,8 @@ impl Widget for DateTimeWidget { ); } - self.color_format.format_string(output) + self.color_format.format_string(&output) } - fn process_click(&self, _state: ZellijState, _pos: usize) {} + fn process_click(&self, _state: &ZellijState, _pos: usize) {} } diff --git a/src/widgets/mode.rs b/src/widgets/mode.rs index ff0e412..0937b50 100644 --- a/src/widgets/mode.rs +++ b/src/widgets/mode.rs @@ -116,7 +116,7 @@ impl ModeWidget { } impl Widget for ModeWidget { - fn process(&self, _name: &str, state: ZellijState) -> String { + fn process(&self, _name: &str, state: &ZellijState) -> String { self.select_format(state.mode.mode) .iter_mut() .map(|f| { @@ -129,11 +129,11 @@ impl Widget for ModeWidget { f }) .fold("".to_string(), |acc, f| { - format!("{acc}{}", f.format_string(f.content.clone())) + format!("{acc}{}", f.format_string(&f.content)) }) } - fn process_click(&self, _state: ZellijState, _pos: usize) {} + fn process_click(&self, _state: &ZellijState, _pos: usize) {} } impl ModeWidget { diff --git a/src/widgets/session.rs b/src/widgets/session.rs index 46b4142..2e75289 100644 --- a/src/widgets/session.rs +++ b/src/widgets/session.rs @@ -11,12 +11,12 @@ impl SessionWidget { } impl Widget for SessionWidget { - fn process(&self, _name: &str, state: ZellijState) -> String { - match state.mode.session_name { - Some(name) => name, + fn process(&self, _name: &str, state: &ZellijState) -> String { + match &state.mode.session_name { + Some(name) => name.to_string(), None => "".to_string(), } } - fn process_click(&self, _state: ZellijState, _pos: usize) {} + fn process_click(&self, _state: &ZellijState, _pos: usize) {} } diff --git a/src/widgets/swap_layout.rs b/src/widgets/swap_layout.rs index 97ad250..9b771ca 100644 --- a/src/widgets/swap_layout.rs +++ b/src/widgets/swap_layout.rs @@ -12,7 +12,7 @@ impl SwapLayoutWidget { } impl Widget for SwapLayoutWidget { - fn process(&self, _name: &str, state: ZellijState) -> String { + fn process(&self, _name: &str, state: &ZellijState) -> String { let active_tab = state.tabs.iter().find(|t| t.active); if active_tab.is_none() { @@ -27,7 +27,7 @@ impl Widget for SwapLayoutWidget { } } - fn process_click(&self, _state: ZellijState, _pos: usize) { + fn process_click(&self, _state: &ZellijState, _pos: usize) { next_swap_layout() } } diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index 78c819d..8c386d5 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -59,10 +59,10 @@ impl TabsWidget { } impl Widget for TabsWidget { - fn process(&self, _name: &str, state: ZellijState) -> String { + fn process(&self, _name: &str, state: &ZellijState) -> String { let mut output = "".to_string(); - for tab in state.tabs { + for tab in &state.tabs { let content = self.render_tab(tab); output = format!("{}{}", output, content); @@ -71,12 +71,12 @@ impl Widget for TabsWidget { output } - fn process_click(&self, state: ZellijState, pos: usize) { + fn process_click(&self, state: &ZellijState, pos: usize) { let mut output = "".to_string(); let mut offset = 0; let mut index = 1; - for tab in state.tabs { + for tab in &state.tabs { let content = strip_ansi_escapes::strip_str(self.render_tab(tab)); if pos > offset && pos < offset + content.chars().count() { @@ -118,7 +118,7 @@ impl TabsWidget { self.normal_tab_format.clone() } - fn render_tab(&self, tab: TabInfo) -> String { + fn render_tab(&self, tab: &TabInfo) -> String { let formatters = self.select_format(tab.clone()); let mut output = "".to_string(); @@ -133,7 +133,7 @@ impl TabsWidget { content = content.replace("{index}", (tab.position + 1).to_string().as_str()); } - output = format!("{}{}", output, f.format_string(content)); + output = format!("{}{}", output, f.format_string(&content)); } output.to_string() diff --git a/src/widgets/widget.rs b/src/widgets/widget.rs index 338c83c..ff4a784 100644 --- a/src/widgets/widget.rs +++ b/src/widgets/widget.rs @@ -1,6 +1,6 @@ use crate::config::ZellijState; pub trait Widget { - fn process(&self, name: &str, state: ZellijState) -> String; - fn process_click(&self, state: ZellijState, pos: usize); + fn process(&self, name: &str, state: &ZellijState) -> String; + fn process_click(&self, state: &ZellijState, pos: usize); } |
