diff --git a/Cargo.toml b/Cargo.toml index 2f21ac6..7768c34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,9 @@ license = "MIT" [dependencies] serde = { version = "1.0.228", features = ["derive"] } toml = "0.9.8" + +[profile.release] +strip = true +lto = true +opt-level = 3 +codegen-units = 1 \ No newline at end of file diff --git a/src/config/mod.rs b/src/config/mod.rs index 825e28f..2875279 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -21,7 +21,7 @@ pub fn config_dir() -> Result { pub fn init_config() -> Result> { let dir = config_dir()?; if !fs::exists(&dir)? { - fs::create_dir(&dir)?; + fs::create_dir_all(&dir)?; let file = format!("{}/config.toml", dir); let cfg = config::default(); let contents = toml::to_string(&cfg)?; diff --git a/src/main.rs b/src/main.rs index febb1ea..4f9d2bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,31 +19,35 @@ fn main() -> Result<(), Box> { let ascii_art = match cfg.display.ascii.as_str() { "stack" => ascii::STACK, - s => panic!("unknown ascii art '{}'", s), + s => return Err(format!("unknown ascii art '{}'", s).into()), }; let max_length = ascii_art .lines() .max_by_key(|l| l.chars().count()) - .unwrap() - .chars() - .count(); + .map(|l| l.chars().count()) + .unwrap_or(0); for line in ascii_art.lines() { let module_name = modules.pop_front().unwrap_or(""); - let out: (&str, String) = match module_name { + + if module_name.is_empty() { + println!("{line:max_length$}"); + continue; + } + + let (key, value) = match module_name { "os" => ("OS", data::os::distro()), "desktop" => ("DE", data::desktop::desktop()), "shell" => ("SH", data::shell::shell()), "uptime" => ("UP", data::uptime::uptime()), - _ => panic!("unknown module '{}'", module_name), + _ => return Err(format!("unknown module '{}'", module_name).into()), }; + println!( "{line:max_length$} {accent}{key}{primary}{seperator}{value}{RESET}", accent = cfg.colours.accent, - key = out.0, primary = cfg.colours.primary, seperator = cfg.display.seperator, - value = out.1 ); }