Compare commits

...

8 Commits

Author SHA1 Message Date
bee2189ae5 work: add Amsterdam time 2025-03-05 17:20:08 -08:00
3b2c74c01e Add UTC time to work clock 2025-01-23 12:30:43 -08:00
b21a06b622 Address lint 2024-08-27 11:43:46 -07:00
4fcbf23210 Show current volume level, disable London time on work 2024-08-27 11:42:24 -07:00
b124148b0b Only show power levels for battery powered things 2024-08-27 11:31:33 -07:00
b9935c991f Make network device filtering a regex.
Work and home have different naming schemes.
2023-07-31 07:53:11 -07:00
f51bbf62d9 Merge branch 'master' of https://git.z.xinu.tv/wathiede/i3xs 2023-07-30 14:06:55 -07:00
376db0eeb4 Add disk R/W stats 2023-07-30 14:06:39 -07:00
7 changed files with 27 additions and 16 deletions

1
Cargo.lock generated
View File

@@ -208,6 +208,7 @@ dependencies = [
"glob",
"i3monkit",
"num_cpus",
"regex",
"structopt",
"thiserror",
]

View File

@@ -27,3 +27,4 @@ chrono = "0.4"
chrono-tz = "0.5"
glob = "0.3.1"
thiserror = "1.0.40"
regex = "1.9.1"

View File

@@ -1,5 +1,5 @@
use chrono::NaiveTime;
use i3monkit::{ColorRGB, Header, I3Protocol, WidgetCollection};
use i3monkit::{widgets::VolumeWidget, ColorRGB, Header, I3Protocol, WidgetCollection};
use i3xs::widgets::{
cpu::CpuWidget,
datetime::{DateTimeWidget, TimeColor},
@@ -27,6 +27,8 @@ fn main() {
// Realtime read/write rate for a any active disks
bar.push(AllDiskSpeedWidget::new(6));
bar.push(VolumeWidget::new("default", "Master", 0));
let mut dt = DateTimeWidget::new("%m/%d %H:%M");
dt.set_colors(vec![
TimeColor {

View File

@@ -1,8 +1,9 @@
use chrono::NaiveTime;
use i3monkit::{ColorRGB, Header, I3Protocol, WidgetCollection};
use i3monkit::{widgets::VolumeWidget, ColorRGB, Header, I3Protocol, WidgetCollection};
use i3xs::widgets::{
cpu::CpuWidget,
datetime::{DateTimeWidget, TimeColor},
disk::AllDiskSpeedWidget,
network::AllNetworkSpeedWidget,
power::PowerSupply,
};
@@ -26,7 +27,8 @@ fn main() {
// Realtime read/write rate for a any active disks
bar.push(AllDiskSpeedWidget::new(6));
let mut dt = DateTimeWidget::tz("%H:%M %Z", chrono_tz::Europe::London);
// Setup time in Amsterdam widget with end of day warnings
let mut dt = DateTimeWidget::tz("%H:%M %Z", chrono_tz::Europe::Amsterdam);
dt.set_colors(vec![
TimeColor {
start: NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
@@ -47,6 +49,8 @@ fn main() {
]);
bar.push(dt);
bar.push(VolumeWidget::new("default", "Master", 0));
let mut dt = DateTimeWidget::new("%m/%d %H:%M");
dt.set_colors(vec![
TimeColor {
@@ -67,6 +71,8 @@ fn main() {
},
]);
bar.push(dt);
let dt_utc = DateTimeWidget::tz("UTC %H:%M", chrono::offset::Utc);
bar.push(dt_utc);
// Then start updating the status bar
bar.update_loop(I3Protocol::new(Header::new(1), std::io::stdout()));

View File

@@ -1,10 +1,4 @@
use std::{
collections::vec_deque::VecDeque,
fs::File,
io::{BufRead, BufReader, Error, ErrorKind, Result},
path::PathBuf,
time::SystemTime,
};
use std::{collections::vec_deque::VecDeque, io::Result, time::SystemTime};
use i3monkit::{Block, Widget, WidgetUpdate};
@@ -158,7 +152,6 @@ impl Widget for DiskSpeedWidget {
}
pub struct AllDiskSpeedWidget {
num_samples: usize,
disks: Vec<DiskSpeedWidget>,
}
impl AllDiskSpeedWidget {
@@ -171,7 +164,7 @@ impl AllDiskSpeedWidget {
})
.collect();
AllDiskSpeedWidget { num_samples, disks }
AllDiskSpeedWidget { disks }
}
}

View File

@@ -7,12 +7,12 @@ use std::{
};
use i3monkit::{Block, Widget, WidgetUpdate};
use regex::Regex;
use crate::spark;
const NETWORK_PATH_PREFIX: &str = "/sys/class/net";
const NETWORK_STAT_SUFFIX: &str = "statistics/dummy";
const DEVICE_PREFIX: &str = "enp";
struct TransferStat {
rx: u64,
@@ -175,18 +175,18 @@ impl Widget for NetworkSpeedWidget {
}
pub struct AllNetworkSpeedWidget {
num_samples: usize,
nics: Vec<NetworkSpeedWidget>,
}
impl AllNetworkSpeedWidget {
pub fn new(num_samples: usize) -> Self {
let dev_pat = Regex::new("(enp|eno).*").expect("bad re");
let nics = std::fs::read_dir(NETWORK_PATH_PREFIX)
.expect(&format!("couldn't list {NETWORK_PATH_PREFIX}"))
.filter_map(|dir| {
let d = dir.unwrap();
let p = d.file_name();
let p = p.to_string_lossy();
if p.starts_with(DEVICE_PREFIX) {
if dev_pat.is_match(&p) {
Some(NetworkSpeedWidget::new(&p, num_samples))
} else {
None
@@ -194,7 +194,7 @@ impl AllNetworkSpeedWidget {
})
.collect();
AllNetworkSpeedWidget { num_samples, nics }
AllNetworkSpeedWidget { nics }
}
}

View File

@@ -58,6 +58,14 @@ impl PowerSupply {
})
})
.collect::<Result<_, _>>()?;
// Skip things that aren't battery powered
if !values
.get("POWER_SUPPLY_TYPE")
.map(|t| t == &"Battery")
.unwrap_or(false)
{
continue;
}
let cap: u32 = values
.get("POWER_SUPPLY_CAPACITY")
.unwrap_or(&"0")