diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-12-17 15:18:04 +0100 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-12-17 15:18:04 +0100 |
| commit | ffad61acab9fa3ec771a911de462fa686bea1d67 (patch) | |
| tree | abb2b9f437c9f3ba0997532eeb1fa2960f1f04e5 /src/widgets | |
| parent | chore: update cargo deps (diff) | |
| download | sl0pstatus-ffad61acab9fa3ec771a911de462fa686bea1d67.tar.gz sl0pstatus-ffad61acab9fa3ec771a911de462fa686bea1d67.tar.xz sl0pstatus-ffad61acab9fa3ec771a911de462fa686bea1d67.zip | |
chore: move from to_string to to_owned
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/command.rs | 16 | ||||
| -rw-r--r-- | src/widgets/datetime.rs | 4 | ||||
| -rw-r--r-- | src/widgets/mode.rs | 30 | ||||
| -rw-r--r-- | src/widgets/session.rs | 4 | ||||
| -rw-r--r-- | src/widgets/swap_layout.rs | 4 | ||||
| -rw-r--r-- | src/widgets/tabs.rs | 20 |
6 files changed, 41 insertions, 37 deletions
diff --git a/src/widgets/command.rs b/src/widgets/command.rs index 9d50b50..c7df9b7 100644 --- a/src/widgets/command.rs +++ b/src/widgets/command.rs @@ -1,3 +1,4 @@ +use lazy_static::lazy_static; use std::{ collections::BTreeMap, fs::{remove_file, File}, @@ -15,6 +16,10 @@ use crate::{config::ZellijState, widgets::widget::Widget}; const TIMESTAMP_FORMAT: &str = "%s"; +lazy_static! { + static ref COMMAND_REGEX: Regex = Regex::new("_[a-zA-Z0-9]+$").unwrap(); +} + #[derive(Clone, Debug)] struct CommandConfig { command: String, @@ -47,7 +52,7 @@ impl Widget for CommandWidget { let command_config = match self.config.get(name) { Some(cc) => cc, None => { - return "".to_string(); + return "".to_owned(); } }; @@ -56,7 +61,7 @@ impl Widget for CommandWidget { let command_result = match state.command_results.get(name) { Some(cr) => cr, None => { - return "".to_string(); + return "".to_owned(); } }; @@ -124,9 +129,8 @@ fn parse_config(zj_conf: BTreeMap<String, String>) -> BTreeMap<String, CommandCo let mut config: BTreeMap<String, CommandConfig> = BTreeMap::new(); - let key_name_regex = Regex::new("_[a-zA-Z0-9]+$").unwrap(); for key in keys { - let command_name = key_name_regex.replace(&key, "").to_string(); + let command_name = COMMAND_REGEX.replace(&key, "").to_string(); let mut command_conf = CommandConfig { command: "".to_owned(), @@ -139,12 +143,12 @@ fn parse_config(zj_conf: BTreeMap<String, String>) -> BTreeMap<String, CommandCo } if key.ends_with("command") { - command_conf.command = zj_conf.get(&key).unwrap().to_string().clone(); + command_conf.command = zj_conf.get(&key).unwrap().to_owned().clone(); } if key.ends_with("format") { command_conf.format = - FormattedPart::from_format_string(zj_conf.get(&key).unwrap().to_string().clone()); + FormattedPart::from_format_string(zj_conf.get(&key).unwrap().to_owned().clone()); } if key.ends_with("interval") { diff --git a/src/widgets/datetime.rs b/src/widgets/datetime.rs index b6a1193..ef2fbee 100644 --- a/src/widgets/datetime.rs +++ b/src/widgets/datetime.rs @@ -36,8 +36,8 @@ impl DateTimeWidget { } Self { - format: format.to_string(), - color_format: FormattedPart::from_format_string(color_format.to_string()), + format: format.to_owned(), + color_format: FormattedPart::from_format_string(color_format.to_owned()), time_zone, } } diff --git a/src/widgets/mode.rs b/src/widgets/mode.rs index 61dda75..0cd68ac 100644 --- a/src/widgets/mode.rs +++ b/src/widgets/mode.rs @@ -27,72 +27,72 @@ pub struct ModeWidget { impl ModeWidget { pub fn new(config: BTreeMap<String, String>) -> Self { let normal_format = match config.get("mode_normal") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => vec![], }; let locked_format = match config.get("mode_locked") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let resize_format = match config.get("mode_resize") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let pane_format = match config.get("mode_pane") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let tab_format = match config.get("mode_tab") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let scroll_format = match config.get("mode_scroll") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let enter_search_format = match config.get("mode_enter_search") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let search_format = match config.get("mode_search") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let rename_tab_format = match config.get("mode_rename_tab") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let rename_pane_format = match config.get("mode_rename_pane") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let session_format = match config.get("mode_session") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let move_format = match config.get("mode_move") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let prompt_format = match config.get("mode_prompt") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; let tmux_format = match config.get("mode_tmux") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_format.clone(), }; @@ -130,7 +130,7 @@ impl Widget for ModeWidget { (f, content) }) - .fold("".to_string(), |acc, (f, content)| { + .fold("".to_owned(), |acc, (f, content)| { format!("{acc}{}", f.format_string(&content)) }) } diff --git a/src/widgets/session.rs b/src/widgets/session.rs index 2e75289..4d2ebf0 100644 --- a/src/widgets/session.rs +++ b/src/widgets/session.rs @@ -13,8 +13,8 @@ impl SessionWidget { impl Widget for SessionWidget { fn process(&self, _name: &str, state: &ZellijState) -> String { match &state.mode.session_name { - Some(name) => name.to_string(), - None => "".to_string(), + Some(name) => name.to_owned(), + None => "".to_owned(), } } diff --git a/src/widgets/swap_layout.rs b/src/widgets/swap_layout.rs index 9b771ca..9b4dda6 100644 --- a/src/widgets/swap_layout.rs +++ b/src/widgets/swap_layout.rs @@ -16,14 +16,14 @@ impl Widget for SwapLayoutWidget { let active_tab = state.tabs.iter().find(|t| t.active); if active_tab.is_none() { - return "".to_string(); + return "".to_owned(); } let active_tab = active_tab.unwrap(); match active_tab.active_swap_layout_name.clone() { Some(n) => n, - None => "".to_string(), + None => "".to_owned(), } } diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index 569519e..cefd124 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -19,31 +19,31 @@ impl TabsWidget { pub fn new(config: BTreeMap<String, String>) -> Self { let mut normal_tab_format: Vec<FormattedPart> = Vec::new(); if let Some(form) = config.get("tab_normal") { - normal_tab_format = FormattedPart::multiple_from_format_string(form.to_string()); + normal_tab_format = FormattedPart::multiple_from_format_string(form.to_owned()); } let normal_tab_fullscreen_format = match config.get("tab_normal_fullscreen") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_tab_format.clone(), }; let normal_tab_sync_format = match config.get("tab_normal_sync") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => normal_tab_format.clone(), }; let mut active_tab_format = normal_tab_format.clone(); if let Some(form) = config.get("tab_active") { - active_tab_format = FormattedPart::multiple_from_format_string(form.to_string()); + active_tab_format = FormattedPart::multiple_from_format_string(form.to_owned()); } let active_tab_fullscreen_format = match config.get("tab_active_fullscreen") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => active_tab_format.clone(), }; let active_tab_sync_format = match config.get("tab_active_sync") { - Some(form) => FormattedPart::multiple_from_format_string(form.to_string()), + Some(form) => FormattedPart::multiple_from_format_string(form.to_owned()), None => active_tab_format.clone(), }; @@ -60,7 +60,7 @@ impl TabsWidget { impl Widget for TabsWidget { fn process(&self, _name: &str, state: &ZellijState) -> String { - let mut output = "".to_string(); + let mut output = "".to_owned(); for tab in &state.tabs { let content = self.render_tab(tab); @@ -72,7 +72,7 @@ impl Widget for TabsWidget { } fn process_click(&self, state: &ZellijState, pos: usize) { - let mut output = "".to_string(); + let mut output = "".to_owned(); let mut offset = 0; let mut index = 1; @@ -120,7 +120,7 @@ impl TabsWidget { fn render_tab(&self, tab: &TabInfo) -> String { let formatters = self.select_format(tab); - let mut output = "".to_string(); + let mut output = "".to_owned(); for f in formatters.iter() { let mut content = f.content.clone(); @@ -136,6 +136,6 @@ impl TabsWidget { output = format!("{}{}", output, f.format_string(&content)); } - output.to_string() + output.to_owned() } } |
