tony / oxwm

Branch: d5b3499
Switch branches/tags
master
tonybtw Added blocks... lol d5b3499 2025-10-04
38 lines · 863 B Raw Blame History
1 use super::Block;
2 use anyhow::Result;
3 use std::process::Command;
4 use std::time::Duration;
5
6 pub struct Uname {
7 cached_version: String,
8 prefix: &'static str,
9 color: u32,
10 }
11
12 impl Uname {
13 pub fn new(prefix: &'static str, color: u32) -> Self {
14 Self {
15 cached_version: String::new(),
16 prefix,
17 color,
18 }
19 }
20 }
21
22 impl Block for Uname {
23 fn content(&mut self) -> Result<String> {
24 if self.cached_version.is_empty() {
25 let output = Command::new("uname").arg("-r").output()?;
26 self.cached_version = String::from_utf8_lossy(&output.stdout).trim().to_string();
27 }
28 Ok(format!("{}{}", self.prefix, self.cached_version))
29 }
30
31 fn interval(&self) -> Duration {
32 Duration::from_secs(u64::MAX)
33 }
34
35 fn color(&self) -> u32 {
36 self.color
37 }
38 }