mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2025-03-04 16:59:58 +01:00
use rust config for i3status-rust
This commit is contained in:
parent
cefaf24168
commit
4a4317a0d7
9 changed files with 172 additions and 73 deletions
|
@ -272,7 +272,7 @@ bar {
|
|||
font pango:<% opt.term_font %> 12
|
||||
mode hide
|
||||
position top
|
||||
status_command i3status-rs
|
||||
status_command i3status
|
||||
separator_symbol |
|
||||
colors {
|
||||
background #282A36
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
[theme]
|
||||
theme = "dracula"
|
||||
|
||||
[icons]
|
||||
icons = "material-nf"
|
||||
|
||||
[icons.overrides]
|
||||
# this should never show, as the bat block auto hides without a battery
|
||||
bat_not_available = "x"
|
||||
|
||||
[[block]]
|
||||
block = "memory"
|
||||
format = " $icon $mem_used_percents $mem_used/$mem_avail"
|
||||
format_alt = " $icon $swap_used_percents $swap_used/$swap_free"
|
||||
|
||||
[[block]]
|
||||
block = "cpu"
|
||||
interval = 1
|
||||
format = " $icon $frequency $barchart $utilization"
|
||||
|
||||
[[block]]
|
||||
block = "temperature"
|
||||
interval = 5
|
||||
format = " $icon $min - $average ~ $max +"
|
||||
chip = "*-isa-*"
|
||||
idle = <% opt.temperatures.normal %>
|
||||
info = <% opt.temperatures.medium %>
|
||||
warning = <% opt.temperatures.high %>
|
||||
|
||||
[[block]]
|
||||
block = "music"
|
||||
interface_name_exclude = [".*kdeconnect.*", "mpd"]
|
||||
format = " $icon {$combo.str(max_w:20, rot_interval:0.1)|} $prev| $play| $next|"
|
||||
|
||||
[[block]]
|
||||
block = "sound"
|
||||
format = " $icon $output_description{ $volume|}"
|
||||
|
||||
[[block]]
|
||||
block = "battery"
|
||||
interval = 10
|
||||
format = " $icon $percentage $power"
|
||||
missing_format = ""
|
||||
|
||||
[[block]]
|
||||
block = "time"
|
||||
interval = 1
|
||||
format = " $icon $timestamp.datetime(f:'%a %d.%m.%Y %T')"
|
|
@ -1,13 +0,0 @@
|
|||
idle_bg = "#44475a"
|
||||
idle_fg = "#f8f8f2"
|
||||
info_bg = "#44475a"
|
||||
info_fg = "#f8f8f2"
|
||||
good_bg = "#50fa7b"
|
||||
good_fg = "#6272a4"
|
||||
warning_bg = "#ffb86c"
|
||||
warning_fg = "#bd93f9"
|
||||
critical_bg = "#ff5555"
|
||||
critical_fg = "#bd93f9"
|
||||
separator = "\ue0b2"
|
||||
separator_bg = "auto"
|
||||
separator_fg = "auto"
|
|
@ -31,11 +31,4 @@ opts.commands = {
|
|||
zenity = "yad",
|
||||
}
|
||||
|
||||
-- Device temperature levels. Used for status bar.
|
||||
opts.temperatures = {
|
||||
normal = 40,
|
||||
medium = 65,
|
||||
high = 80,
|
||||
}
|
||||
|
||||
return opts
|
||||
|
|
2
scripts/i3status/.gitignore
vendored
Normal file
2
scripts/i3status/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/Cargo.lock
|
13
scripts/i3status/Cargo.toml
Normal file
13
scripts/i3status/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "i3status"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.71"
|
||||
env_logger = "0.10.0"
|
||||
i3status-rs = { git = "https://github.com/greshake/i3status-rust.git" }
|
||||
serde_json = "1.0.96"
|
||||
tokio = "1.28.1"
|
139
scripts/i3status/src/main.rs
Normal file
139
scripts/i3status/src/main.rs
Normal file
|
@ -0,0 +1,139 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use i3status_rs::{
|
||||
blocks,
|
||||
config::{BlockConfigEntry, SharedConfig},
|
||||
escape::CollectEscaped,
|
||||
icons::Icons,
|
||||
protocol,
|
||||
themes::{
|
||||
color::{Color, Rgba},
|
||||
separator::Separator,
|
||||
ColorOrLink,
|
||||
Theme,
|
||||
ThemeOverrides,
|
||||
ThemeUserConfig,
|
||||
},
|
||||
widget::{State, Widget},
|
||||
BarState,
|
||||
};
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
if let Err(e) = try_main().await {
|
||||
let err_widget = Widget::new()
|
||||
.with_text(e.to_string().chars().collect_pango_escaped())
|
||||
.with_state(State::Critical);
|
||||
|
||||
serde_json::to_writer(
|
||||
std::io::stdout(),
|
||||
&err_widget.get_data(&Default::default(), 0).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
println!(",");
|
||||
|
||||
eprintln!("{e}");
|
||||
|
||||
std::future::pending::<()>().await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn try_main() -> anyhow::Result<()> {
|
||||
env_logger::try_init()?;
|
||||
protocol::init(false);
|
||||
|
||||
fn override_color(r: u8, g: u8, b: u8) -> Option<ColorOrLink> {
|
||||
Some(ColorOrLink::Color(Color::Rgba(Rgba { r, g, b, a: 0xff })))
|
||||
}
|
||||
|
||||
let icons = Icons::from_file("material-nf")?;
|
||||
let theme = Theme::try_from(ThemeUserConfig {
|
||||
theme: Some("slick".into()),
|
||||
overrides: Some(ThemeOverrides {
|
||||
// dracula theme
|
||||
idle_bg: override_color(0x44, 0x47, 0x5a),
|
||||
idle_fg: override_color(0xf8, 0xf8, 0xf2),
|
||||
info_bg: override_color(0x44, 0x47, 0x5a),
|
||||
info_fg: override_color(0xf8, 0xf8, 0xf2),
|
||||
good_bg: override_color(0x50, 0xfa, 0x7b),
|
||||
good_fg: override_color(0x62, 0x72, 0xa4),
|
||||
warning_bg: override_color(0xff, 0xb8, 0x6c),
|
||||
warning_fg: override_color(0xbd, 0x93, 0xf9),
|
||||
critical_bg: override_color(0xff, 0x55, 0x55),
|
||||
critical_fg: override_color(0xbd, 0x93, 0xf9),
|
||||
separator: Some(Separator::Custom("\u{e0b2}".to_string())),
|
||||
separator_bg: Some(ColorOrLink::Color(Color::Auto)),
|
||||
separator_fg: Some(ColorOrLink::Color(Color::Auto)),
|
||||
..Default::default()
|
||||
}),
|
||||
})?;
|
||||
|
||||
let mut bar = BarState::new(i3status_rs::config::Config {
|
||||
shared: SharedConfig {
|
||||
theme: Arc::new(theme),
|
||||
icons: Arc::new(icons),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
macro_rules! spawn {
|
||||
($mod:ident $structinit:tt) => {
|
||||
bar.spawn_block(BlockConfigEntry {
|
||||
config: blocks::BlockConfig::$mod(blocks::$mod::Config $structinit),
|
||||
common: Default::default(),
|
||||
})
|
||||
.await?;
|
||||
};
|
||||
}
|
||||
|
||||
spawn!(memory {
|
||||
format: " $icon $mem_used_percents $mem_used/$mem_avail".parse()?,
|
||||
format_alt: Some(" $icon $swap_used_percents $swap_used/$swap_free".parse()?),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
spawn!(cpu {
|
||||
interval: 1.into(),
|
||||
format: " $icon $frequency $barchart $utilization".parse()?,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
spawn!(temperature {
|
||||
interval: 5.into(),
|
||||
format: " $icon $min - $average ~ $max +".parse()?,
|
||||
chip: Some("*-isa-*".into()),
|
||||
idle: Some(40.),
|
||||
info: Some(65.),
|
||||
warning: Some(80.),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
spawn!(music {
|
||||
interface_name_exclude: vec![".*kdeconnect.*".to_string(), "mpd".to_string()],
|
||||
format: " $icon {$combo.str(max_w:20, rot_interval:0.1)|} $prev| $play| $next|".parse()?,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
spawn!(sound {
|
||||
format: " $icon $output_description{ $volume|}".parse()?,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
spawn!(battery {
|
||||
interval: 10.into(),
|
||||
format: " $icon $percentage $power".parse()?,
|
||||
missing_format: "".parse()?,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
spawn!(time {
|
||||
interval: 1.into(),
|
||||
format: " $icon $timestamp.datetime(f:'%a %d.%m.%Y %T')".parse()?,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
bar.run_event_loop(|| panic!("Hey! No restarting!")).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
(mklink "scripts/withjava.sh" (bin-path "withjava"))
|
||||
|
||||
;; Compile Zig scripts
|
||||
(install-rust "scripts/i3status")
|
||||
(install-zig "scripts/mzteinit")
|
||||
(install-zig "scripts/openbrowser")
|
||||
(install-zig "scripts/playtwitch")
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
cmd
|
||||
rm
|
||||
copy
|
||||
install-zig)
|
||||
install-zig
|
||||
install-rust)
|
||||
|
||||
;; Whether to log calls or not
|
||||
(define log-calls (make-parameter #t))
|
||||
|
@ -32,6 +33,17 @@
|
|||
(define-logging copy copy-directory/files)
|
||||
|
||||
(define-logging install-zig
|
||||
(λ (path)
|
||||
(parameterize ([current-directory path] [log-calls #f])
|
||||
(cmd "zig" "build" "-p" (output-bin-path) "-Doptimize=ReleaseFast"))))
|
||||
(λ (path)
|
||||
(parameterize ([current-directory path] [log-calls #f])
|
||||
(cmd "zig" "build" "-p" (output-bin-path) "-Doptimize=ReleaseFast"))))
|
||||
|
||||
(define-logging install-rust
|
||||
(λ (path)
|
||||
(parameterize ([current-directory path] [log-calls #f])
|
||||
(cmd "cargo"
|
||||
"-Z"
|
||||
"unstable-options"
|
||||
"build"
|
||||
"--release"
|
||||
"--out-dir"
|
||||
(build-path (output-bin-path) "bin")))))
|
||||
|
|
Loading…
Add table
Reference in a new issue