aboutsummaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorDaniel Jankowski <daniel.jankowski@rub.de>2023-12-17 14:33:32 +0100
committerDaniel Jankowski <daniel.jankowski@rub.de>2023-12-17 14:33:32 +0100
commitaa67d6fbecab9a45b6044f019adb303bc84d63fe (patch)
treeb29760b80a67a44d274c62936b41c3ccc484c95d /src/widgets
parentfeat: perf + mem optimization of rendering (diff)
downloadsl0pstatus-aa67d6fbecab9a45b6044f019adb303bc84d63fe.tar.gz
sl0pstatus-aa67d6fbecab9a45b6044f019adb303bc84d63fe.tar.xz
sl0pstatus-aa67d6fbecab9a45b6044f019adb303bc84d63fe.zip
feat: further perf + mem optimization of widgets
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/command.rs4
-rw-r--r--src/widgets/mode.rs42
-rw-r--r--src/widgets/tabs.rs16
3 files changed, 32 insertions, 30 deletions
diff --git a/src/widgets/command.rs b/src/widgets/command.rs
index 8a7a3f8..9d50b50 100644
--- a/src/widgets/command.rs
+++ b/src/widgets/command.rs
@@ -98,7 +98,7 @@ impl Widget for CommandWidget {
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);
+ get_timestamp_from_event_or_default(name, state, command_config.interval);
if ts.timestamp() - last_run.timestamp() >= command_config.interval {
let mut context = BTreeMap::new();
@@ -159,7 +159,7 @@ fn parse_config(zj_conf: BTreeMap<String, String>) -> BTreeMap<String, CommandCo
fn get_timestamp_from_event_or_default(
name: &str,
- state: ZellijState,
+ state: &ZellijState,
interval: i64,
) -> DateTime<Local> {
let command_result = state.command_results.get(name);
diff --git a/src/widgets/mode.rs b/src/widgets/mode.rs
index 0937b50..61dda75 100644
--- a/src/widgets/mode.rs
+++ b/src/widgets/mode.rs
@@ -118,18 +118,20 @@ impl ModeWidget {
impl Widget for ModeWidget {
fn process(&self, _name: &str, state: &ZellijState) -> String {
self.select_format(state.mode.mode)
- .iter_mut()
+ .iter()
.map(|f| {
+ let mut content = f.content.clone();
+
if f.content.contains("{name}") {
- f.content = f
+ content = f
.content
.replace("{name}", format!("{:?}", state.mode.mode).as_str());
}
- f
+ (f, content)
})
- .fold("".to_string(), |acc, f| {
- format!("{acc}{}", f.format_string(&f.content))
+ .fold("".to_string(), |acc, (f, content)| {
+ format!("{acc}{}", f.format_string(&content))
})
}
@@ -137,22 +139,22 @@ impl Widget for ModeWidget {
}
impl ModeWidget {
- fn select_format(&self, mode: InputMode) -> Vec<FormattedPart> {
+ fn select_format(&self, mode: InputMode) -> &Vec<FormattedPart> {
match mode {
- InputMode::Normal => self.normal_format.clone(),
- InputMode::Locked => self.locked_format.clone(),
- InputMode::Resize => self.resize_format.clone(),
- InputMode::Pane => self.pane_format.clone(),
- InputMode::Tab => self.tab_format.clone(),
- InputMode::Scroll => self.scroll_format.clone(),
- InputMode::EnterSearch => self.enter_search_format.clone(),
- InputMode::Search => self.search_format.clone(),
- InputMode::RenameTab => self.rename_tab_format.clone(),
- InputMode::RenamePane => self.rename_pane_format.clone(),
- InputMode::Session => self.session_format.clone(),
- InputMode::Move => self.move_format.clone(),
- InputMode::Prompt => self.prompt_format.clone(),
- InputMode::Tmux => self.tmux_format.clone(),
+ InputMode::Normal => &self.normal_format,
+ InputMode::Locked => &self.locked_format,
+ InputMode::Resize => &self.resize_format,
+ InputMode::Pane => &self.pane_format,
+ InputMode::Tab => &self.tab_format,
+ InputMode::Scroll => &self.scroll_format,
+ InputMode::EnterSearch => &self.enter_search_format,
+ InputMode::Search => &self.search_format,
+ InputMode::RenameTab => &self.rename_tab_format,
+ InputMode::RenamePane => &self.rename_pane_format,
+ InputMode::Session => &self.session_format,
+ InputMode::Move => &self.move_format,
+ InputMode::Prompt => &self.prompt_format,
+ InputMode::Tmux => &self.tmux_format,
}
}
}
diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs
index 8c386d5..569519e 100644
--- a/src/widgets/tabs.rs
+++ b/src/widgets/tabs.rs
@@ -94,32 +94,32 @@ impl Widget for TabsWidget {
}
impl TabsWidget {
- fn select_format(&self, info: TabInfo) -> Vec<FormattedPart> {
+ fn select_format(&self, info: &TabInfo) -> &Vec<FormattedPart> {
if info.active && info.is_fullscreen_active {
- return self.active_tab_fullscreen_format.clone();
+ return &self.active_tab_fullscreen_format;
}
if info.active && info.is_sync_panes_active {
- return self.active_tab_sync_format.clone();
+ return &self.active_tab_sync_format;
}
if info.active {
- return self.active_tab_format.clone();
+ return &self.active_tab_format;
}
if info.is_fullscreen_active {
- return self.normal_tab_fullscreen_format.clone();
+ return &self.normal_tab_fullscreen_format;
}
if info.is_sync_panes_active {
- return self.normal_tab_sync_format.clone();
+ return &self.normal_tab_sync_format;
}
- self.normal_tab_format.clone()
+ &self.normal_tab_format
}
fn render_tab(&self, tab: &TabInfo) -> String {
- let formatters = self.select_format(tab.clone());
+ let formatters = self.select_format(tab);
let mut output = "".to_string();
for f in formatters.iter() {