diff --git a/Cargo.toml b/Cargo.toml index 6bf5a8a..a7cec7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,6 @@ string-builder = "0.2.*" env_logger = "0.4.*" dotenvy = "0.15.7" log = "0.4" -signal-hook = "0.3.*" \ No newline at end of file +signal-hook = "0.3.*" +toml = "0.5.*" +clap = { version = "4.2.*", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index c0f6946..616095c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; use std::thread::{self}; +use clap::Parser; use mpris::PlayerFinder; +use structs::cli::Cli; use structs::{config::Config, data::Data}; use crate::update_players::update_players; use crate::update_message::update_message; @@ -20,9 +22,6 @@ fn handle_signal(data: &Data, pf: &PlayerFinder) { } } -//todo: load different config giles depending on CLI argument -//so i can specify 3 files to use with my polybar config - fn main() { //dotenvy::dotenv().expect("Failed to read .env file"); std::env::set_var("RUST_LOG", "error"); @@ -30,7 +29,8 @@ fn main() { panic!("{}", e); } - let mut cfg: Config = confy::load("polybar-now-playing", None).unwrap(); //TODO: error handling + let cli = Cli::parse(); + let mut cfg: Config = confy::load("polybar-now-playing", cli.config_file.as_str()).unwrap(); //TODO: error handling cfg.priorities_to_lower(); let mut data: Data = Data::default(); let term = Arc::new(AtomicBool::new(false)); diff --git a/src/print_text.rs b/src/print_text.rs index 5828ef5..87a2db6 100644 --- a/src/print_text.rs +++ b/src/print_text.rs @@ -25,7 +25,9 @@ fn build_string(cfg: &Config, data: &mut Data) -> String { b.append(' '); } else { cutoff(&cfg.metadata_fields, cfg.break_character, &mut data.display_text); - b.append(data.display_prefix.clone()); + if cfg.render_prefix { + b.append(data.display_prefix.clone()); + } b.append(' '); b.append(format!(" %{{T{}}}", cfg.font_index)); let mut idx = 0; let len = cfg.metadata_fields.len() as i32; diff --git a/src/structs/cli.rs b/src/structs/cli.rs new file mode 100644 index 0000000..9090aeb --- /dev/null +++ b/src/structs/cli.rs @@ -0,0 +1,11 @@ +use clap::Parser; + +/// Program which finds the active mpris player. +/// +/// Most configuration is done through config files. +#[derive(Parser)] +pub struct Cli { + /// The name of the config file to use. + #[arg(short = 'c', long = "config", default_value = "default")] + pub config_file: String, +} \ No newline at end of file diff --git a/src/structs/config.rs b/src/structs/config.rs index 85594f7..ca9b7f9 100644 --- a/src/structs/config.rs +++ b/src/structs/config.rs @@ -21,6 +21,16 @@ impl Field { } } +// I shouldn't need this; remove when done with testing FIXME +impl Default for Field { + fn default() -> Self { + Self { + field: Default::default(), + num_chars: Default::default() + } + } +} + #[derive(Serialize, Deserialize)] pub struct Rating { pub nil: char, @@ -49,15 +59,16 @@ impl Default for Rating { #[derive(Serialize, Deserialize)] pub struct Config { pub font_index: u8, - pub update_delay: Duration, pub metadata_separator: char, pub array_separator: char, pub hide_output: bool, + pub render_prefix: bool, + pub break_character: char, + pub player_priorities: Vec, + pub rating_icons: Rating, pub metadata_fields: Vec, pub player_prefixes: HashMap, - pub rating_icons: Rating, - pub player_priorities: Vec, - pub break_character: char, + pub update_delay: Duration, } impl Default for Config { @@ -68,11 +79,12 @@ impl Default for Config { metadata_separator: '|', array_separator: '+', hide_output: true, + render_prefix: true, metadata_fields: vec![Field::constructor("xesam:title", 40), Field::constructor("xesam:artist", 20)], - player_prefixes: default_player_prefixes(), rating_icons: Rating::default(), player_priorities: vec![ms("clementine"), ms("spotify"), ms("deadbeef"), ms("mpv"), ms("vlc"), ms("firefox"), ms("chromium")], break_character: '-', + player_prefixes: default_player_prefixes(), } } } diff --git a/src/structs/mod.rs b/src/structs/mod.rs index 8321105..2d1458b 100644 --- a/src/structs/mod.rs +++ b/src/structs/mod.rs @@ -1,2 +1,3 @@ pub mod config; -pub mod data; \ No newline at end of file +pub mod data; +pub mod cli; \ No newline at end of file