Created
August 9, 2017 22:46
-
-
Save Ploppz/c285b45b66c725a36c859f67235150f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env run-cargo-script | |
//! ```cargo | |
//! [dependencies] | |
//! unixbar = "0" | |
//! systemstat = "0" | |
//! ``` | |
#[macro_use] extern crate unixbar; | |
extern crate systemstat; | |
use unixbar::*; | |
use systemstat::{System, Platform, ByteSize}; | |
fn main() { | |
let mut sep = Separator::new("#770000", "#000000"); | |
UnixBar::new(LemonbarFormatter::new()) | |
.add(Text::new(bfmt![fg[sep.fg] bg[sep.bg] text["Hello "]])) | |
.add(Text::new(sep.right("#ffffff", "#335533"))) | |
.add(Text::new(bfmt![fg[sep.fg] bg[sep.bg] text["World "]])) | |
.add(Text::new(sep.right("#00ff00", "#677766"))) | |
.add(Text::new(bfmt![fg[sep.fg] bg[sep.bg] text["Hello "]])) | |
.add(Text::new(sep.right("#000000", "#00000000"))) | |
.add(Text::new(bfmt![center])) | |
.add(Bspwm::new(|desktops| Format::Concat(desktops.iter().map(|d| | |
Box::new( { | |
let bg = if d.focused { "#99aa11" } else { "#111111" }; | |
bfmt![ | |
click[MouseButton::Left => format!("bspc desktop -f {}", d.name)] | |
bg[bg] fmt[" {} ", d.name] | |
] | |
}) | |
).collect()))) | |
.add(Text::new(bfmt![right])) | |
.add(Text::new(sep.left("#ffffff", "#000000"))) | |
.add(Periodic::new( | |
Duration::from_secs(2), | |
|| match System::new().memory() { | |
Ok(mem) => bfmt![fg[sep.fg] bg[sep.bg] fmt[" {}/{} RAM ", as_string_gb(mem.total - mem.free), mem.total]], | |
Err(_) => bfmt![fg["#bb1155"] bg[sep.bg] text["error"]], | |
})) | |
.add(Text::new(sep.left("#ffffff", "#000000"))) | |
.add(Wrap::new( | |
|f| bfmt![fg["#bb1155"] f], | |
DateTime::new("%H:%M:%S")) | |
) | |
.add(Text::new(bfmt![text[" | "]])) | |
.add(Wrap::new( | |
|f| bfmt![fg["#bb1155"] f], | |
DateTime::new("%W. %A")) // week, day | |
) | |
.add(Text::new(bfmt![text[" | "]])) | |
.add(Wrap::new( | |
|f| bfmt![fg["#bb1155"] f], | |
DateTime::new("%d. %B")) // date, month | |
) | |
.run(); | |
} | |
fn as_string_gb(bytes: ByteSize) -> String { | |
format!("{}", (bytes.as_usize()/1000000) as f32 / 1000.0) | |
} | |
struct Separator { | |
fg: &'static str, | |
bg: &'static str, | |
} | |
impl Separator { | |
pub fn new(fg: &'static str, bg: &'static str) -> Separator { | |
Separator { | |
fg: fg, | |
bg: bg, | |
} | |
} | |
pub fn left(&mut self, fg: &'static str, bg: &'static str) -> Format { | |
let ret = bfmt![ | |
fg[bg] bg[self.bg] text[" ⮃⮂"] | |
]; | |
self.fg = fg; | |
self.bg = bg; | |
ret | |
} | |
pub fn right(&mut self, fg: &'static str, bg: &'static str) -> Format { | |
let ret = bfmt![ | |
fg[self.bg] bg[bg] text["⮀⮁ "] | |
]; | |
self.fg = fg; | |
self.bg = bg; | |
ret | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment