diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-08-31 19:47:42 +0200 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-08-31 19:47:42 +0200 |
| commit | 9756c19ab3272dc5e81db4f16ed6bc3e5ad46675 (patch) | |
| tree | c541f61c91896c916d8e0c4025fb547bcd4d2921 /src/widgets | |
| parent | chore: remove format suffix from config (diff) | |
| download | sl0pstatus-9756c19ab3272dc5e81db4f16ed6bc3e5ad46675.tar.gz sl0pstatus-9756c19ab3272dc5e81db4f16ed6bc3e5ad46675.tar.xz sl0pstatus-9756c19ab3272dc5e81db4f16ed6bc3e5ad46675.zip | |
feat: add left + right widgets + date widget
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/clock.rs | 47 | ||||
| -rw-r--r-- | src/widgets/mod.rs | 1 | ||||
| -rw-r--r-- | src/widgets/tabs.rs | 10 |
3 files changed, 52 insertions, 6 deletions
diff --git a/src/widgets/clock.rs b/src/widgets/clock.rs new file mode 100644 index 0000000..4351fc8 --- /dev/null +++ b/src/widgets/clock.rs @@ -0,0 +1,47 @@ +use std::collections::BTreeMap; + +use chrono::Local; + +use crate::{config::FormattedPart, render}; + +use super::widget::Widget; + +pub struct ClockWidget { + format: String, + color_format: FormattedPart, +} + +impl ClockWidget { + pub fn new(config: BTreeMap<String, String>) -> Self { + let mut format = "%H:%M"; + if let Some(form) = config.get("clock_format") { + format = form; + } + + let mut color_format = ""; + if let Some(form) = config.get("clock") { + color_format = form; + } + + Self { + format: format.to_string(), + color_format: FormattedPart::from_format_string(color_format.to_string()), + } + } +} + +impl Widget for ClockWidget { + fn process(&self, _state: crate::ZellijState) -> String { + let mut output = self.color_format.content.clone(); + if output.contains("{time}") { + let date = Local::now(); + + output = output.replace( + "{time}", + format!("{}", date.format(self.format.as_str())).as_str(), + ); + } + + render::formatting(self.color_format.clone(), output) + } +} diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index a017530..124e372 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -1,3 +1,4 @@ +pub mod clock; pub mod mode; pub mod tabs; pub mod widget; diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index 6353251..00b87f9 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -18,11 +18,10 @@ impl TabsWidget { normal_tab_format_string = form; } - let active_tab_format = - FormattedPart::from_format_string(match config.get("tab_active") { - Some(form) => form.to_string(), - None => normal_tab_format_string.to_string(), - }); + let active_tab_format = FormattedPart::from_format_string(match config.get("tab_active") { + Some(form) => form.to_string(), + None => normal_tab_format_string.to_string(), + }); Self { normal_tab_format: FormattedPart::from_format_string( @@ -39,7 +38,6 @@ impl Widget for TabsWidget { for tab in state.tabs { let formatter = self.select_format(tab.clone()); - println!("{:?}", tab.clone()); let mut content = formatter.content.clone(); if content.contains("{name}") { |
