diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-07-15 16:16:46 +0200 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-07-15 16:16:46 +0200 |
| commit | 68d8d4998547e859527ad7aa7112d09ee74f0fbb (patch) | |
| tree | 117f770a008eb44099410c7378d2770122f30895 /src/widgets | |
| parent | chore: update cargo deps (diff) | |
| download | sl0pstatus-68d8d4998547e859527ad7aa7112d09ee74f0fbb.tar.gz sl0pstatus-68d8d4998547e859527ad7aa7112d09ee74f0fbb.tar.xz sl0pstatus-68d8d4998547e859527ad7aa7112d09ee74f0fbb.zip | |
feat: add color aliases
closes #75
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/command.rs | 10 | ||||
| -rw-r--r-- | src/widgets/datetime.rs | 2 | ||||
| -rw-r--r-- | src/widgets/mode.rs | 28 | ||||
| -rw-r--r-- | src/widgets/notification.rs | 8 | ||||
| -rw-r--r-- | src/widgets/swap_layout.rs | 2 | ||||
| -rw-r--r-- | src/widgets/tabs.rs | 20 |
6 files changed, 36 insertions, 34 deletions
diff --git a/src/widgets/command.rs b/src/widgets/command.rs index 91ff991..c5a902f 100644 --- a/src/widgets/command.rs +++ b/src/widgets/command.rs @@ -50,12 +50,14 @@ pub struct CommandResult { pub struct CommandWidget { config: BTreeMap<String, CommandConfig>, + zj_conf: BTreeMap<String, String>, } impl CommandWidget { pub fn new(config: &BTreeMap<String, String>) -> Self { Self { config: parse_config(config), + zj_conf: config.clone(), } } } @@ -123,7 +125,7 @@ impl Widget for CommandWidget { match command_config.render_mode { RenderMode::Static => content, - RenderMode::Dynamic => render_dynamic_formatted_content(&content), + RenderMode::Dynamic => render_dynamic_formatted_content(&content, &self.zj_conf), RenderMode::Raw => content, } } @@ -153,8 +155,8 @@ impl Widget for CommandWidget { } } -fn render_dynamic_formatted_content(content: &str) -> String { - formatted_parts_from_string_cached(content) +fn render_dynamic_formatted_content(content: &str, config: &BTreeMap<String, String>) -> String { + formatted_parts_from_string_cached(content, config) .iter() .map(|fp| fp.format_string(&fp.content)) .collect::<Vec<String>>() @@ -263,7 +265,7 @@ fn parse_config(zj_conf: &BTreeMap<String, String>) -> BTreeMap<String, CommandC if key.ends_with("format") { command_conf.format = - FormattedPart::multiple_from_format_string(zj_conf.get(&key).unwrap()); + FormattedPart::multiple_from_format_string(zj_conf.get(&key).unwrap(), zj_conf); } if key.ends_with("interval") { diff --git a/src/widgets/datetime.rs b/src/widgets/datetime.rs index 1d3a23b..5e9c099 100644 --- a/src/widgets/datetime.rs +++ b/src/widgets/datetime.rs @@ -51,7 +51,7 @@ impl DateTimeWidget { format: format.to_owned(), date_format: date_format.to_owned(), time_format: time_format.to_owned(), - color_format: FormattedPart::multiple_from_format_string(color_format), + color_format: FormattedPart::multiple_from_format_string(color_format, config), time_zone, } } diff --git a/src/widgets/mode.rs b/src/widgets/mode.rs index 68c9bfa..8544cf9 100644 --- a/src/widgets/mode.rs +++ b/src/widgets/mode.rs @@ -28,72 +28,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), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let locked_format = match config.get("mode_locked") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let resize_format = match config.get("mode_resize") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let pane_format = match config.get("mode_pane") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let tab_format = match config.get("mode_tab") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let scroll_format = match config.get("mode_scroll") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let enter_search_format = match config.get("mode_enter_search") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let search_format = match config.get("mode_search") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let rename_tab_format = match config.get("mode_rename_tab") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let rename_pane_format = match config.get("mode_rename_pane") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let session_format = match config.get("mode_session") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let move_format = match config.get("mode_move") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let prompt_format = match config.get("mode_prompt") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; let tmux_format = match config.get("mode_tmux") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => vec![], }; diff --git a/src/widgets/notification.rs b/src/widgets/notification.rs index 1b8cfcd..458d12a 100644 --- a/src/widgets/notification.rs +++ b/src/widgets/notification.rs @@ -20,13 +20,13 @@ pub struct NotificationWidget { impl NotificationWidget { pub fn new(config: &BTreeMap<String, String>) -> Self { let format_unread = match config.get("notification_format_unread") { - Some(f) => FormattedPart::multiple_from_format_string(f), - None => FormattedPart::multiple_from_format_string(""), + Some(f) => FormattedPart::multiple_from_format_string(f, config), + None => FormattedPart::multiple_from_format_string("", config), }; let format_no_notifications = match config.get("notification_format_no_notifications") { - Some(f) => FormattedPart::multiple_from_format_string(f), - None => FormattedPart::multiple_from_format_string(""), + Some(f) => FormattedPart::multiple_from_format_string(f, config), + None => FormattedPart::multiple_from_format_string("", config), }; let show_interval = match config.get("notification_show_interval") { diff --git a/src/widgets/swap_layout.rs b/src/widgets/swap_layout.rs index d8f9ffb..8c9e036 100644 --- a/src/widgets/swap_layout.rs +++ b/src/widgets/swap_layout.rs @@ -13,7 +13,7 @@ impl SwapLayoutWidget { pub fn new(config: &BTreeMap<String, String>) -> Self { let mut format: Vec<FormattedPart> = Vec::new(); if let Some(form) = config.get("swap_layout_format") { - format = FormattedPart::multiple_from_format_string(form); + format = FormattedPart::multiple_from_format_string(form, config); } let hide_if_empty = match config.get("swap_layout_hide_if_empty") { diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index ee88769..46753bf 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -30,36 +30,36 @@ 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); + normal_tab_format = FormattedPart::multiple_from_format_string(form, config); } let normal_tab_fullscreen_format = match config.get("tab_normal_fullscreen") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => normal_tab_format.clone(), }; let normal_tab_sync_format = match config.get("tab_normal_sync") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), 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); + active_tab_format = FormattedPart::multiple_from_format_string(form, config); } let active_tab_fullscreen_format = match config.get("tab_active_fullscreen") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => active_tab_format.clone(), }; let active_tab_sync_format = match config.get("tab_active_sync") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => active_tab_format.clone(), }; let rename_tab_format = match config.get("tab_rename") { - Some(form) => FormattedPart::multiple_from_format_string(form), + Some(form) => FormattedPart::multiple_from_format_string(form, config), None => active_tab_format.clone(), }; @@ -73,15 +73,15 @@ impl TabsWidget { let tab_truncate_start_format = config .get("tab_truncate_start_format") - .map(|form| FormattedPart::from_format_string(form)); + .map(|form| FormattedPart::from_format_string(form, config)); let tab_truncate_end_format = config .get("tab_truncate_end_format") - .map(|form| FormattedPart::from_format_string(form)); + .map(|form| FormattedPart::from_format_string(form, config)); let separator = config .get("tab_separator") - .map(|s| FormattedPart::from_format_string(s)); + .map(|s| FormattedPart::from_format_string(s, config)); Self { normal_tab_format, |
