tony / oxwm

Branch: 11d2346
Switch branches/tags
master
tonybtw Added proper error handling in blocks, and font. added error modal so config syntax error doesnt crash when you reload your oxwm, added keybind overlay modal to show the important keybinds (inspired by niri), moved keysms helper function into const file to reduce code duplication. ad06fa5 2025-11-09
38 lines · 916 B Raw Blame History
1 use super::Block;
2 use crate::errors::BlockError;
3 use chrono::Local;
4 use std::time::Duration;
5
6 pub struct DateTime {
7 format_template: String,
8 time_format: String,
9 interval: Duration,
10 color: u32,
11 }
12
13 impl DateTime {
14 pub fn new(format_template: &str, time_format: &str, interval_secs: u64, color: u32) -> Self {
15 Self {
16 format_template: format_template.to_string(),
17 time_format: time_format.to_string(),
18 interval: Duration::from_secs(interval_secs),
19 color,
20 }
21 }
22 }
23
24 impl Block for DateTime {
25 fn content(&mut self) -> Result<String, BlockError> {
26 let now = Local::now();
27 let time_str = now.format(&self.time_format).to_string();
28 Ok(self.format_template.replace("{}", &time_str))
29 }
30
31 fn interval(&self) -> Duration {
32 self.interval
33 }
34
35 fn color(&self) -> u32 {
36 self.color
37 }
38 }