62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
use chrono::NaiveTime;
|
|
|
|
use i3monkit::{ColorRGB, Header, I3Protocol, WidgetCollection};
|
|
|
|
use num_cpus;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
use i3xs::widgets::cpu::CpuWidget;
|
|
use i3xs::widgets::datetime::{DateTimeWidget, TimeColor};
|
|
use i3xs::widgets::network::NetworkSpeedWidget;
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
#[structopt(name = "i3xs", about = "Custom i3 status bar program.")]
|
|
struct Opt {
|
|
#[structopt(short, long)]
|
|
nic: String,
|
|
}
|
|
|
|
fn main() {
|
|
let mut bar = WidgetCollection::new();
|
|
|
|
let opts = Opt::from_args();
|
|
|
|
// Display all the cpu usage for each core
|
|
for i in 0..num_cpus::get() as u32 {
|
|
bar.push(CpuWidget::new(i));
|
|
}
|
|
|
|
// Realtime upload/download rate for a interface
|
|
bar.push(NetworkSpeedWidget::new(&opts.nic, 6));
|
|
|
|
let mut dt = DateTimeWidget::tz("%H:%M %Z".to_string(), "Europe/London".to_string());
|
|
dt.set_colors(&vec![
|
|
TimeColor {
|
|
start: NaiveTime::from_hms(15, 0, 0),
|
|
color: ColorRGB::yellow(),
|
|
},
|
|
TimeColor {
|
|
start: NaiveTime::from_hms(16, 0, 0),
|
|
color: ColorRGB::red(),
|
|
},
|
|
]);
|
|
bar.push(dt);
|
|
|
|
let mut dt = DateTimeWidget::new("%m/%d %H:%M".to_string());
|
|
dt.set_colors(&vec![
|
|
TimeColor {
|
|
start: NaiveTime::from_hms(15, 0, 0),
|
|
color: ColorRGB::yellow(),
|
|
},
|
|
TimeColor {
|
|
start: NaiveTime::from_hms(16, 0, 0),
|
|
color: ColorRGB::red(),
|
|
},
|
|
]);
|
|
bar.push(dt);
|
|
|
|
// Then start updating the status bar
|
|
bar.update_loop(I3Protocol::new(Header::new(1), std::io::stdout()));
|
|
}
|