From 0c5ce16afbe87fcde5abb15c4decd97d556da4fe Mon Sep 17 00:00:00 2001 From: April Date: Mon, 27 Oct 2025 16:48:14 +0000 Subject: [PATCH] add lowercase + basic way to migrate config adds something to allow the user to make the output lowercase + basic migration --- docs/example_config.toml | 1 + src/config/config.rs | 2 ++ src/config/mod.rs | 16 +++++++++++++--- src/main.rs | 6 +++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/example_config.toml b/docs/example_config.toml index 2a7caf5..1a7a106 100644 --- a/docs/example_config.toml +++ b/docs/example_config.toml @@ -2,6 +2,7 @@ ascii = "stack" seperator = ": " modules = ["os", "desktop", "shell", "uptime"] +lowercase = false [colours] primary = "\u001B[39m" # reset diff --git a/src/config/config.rs b/src/config/config.rs index cc542c3..257bdb7 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -14,6 +14,7 @@ pub struct DisplayConfig { pub ascii: String, pub seperator: String, pub modules: Vec, + pub lowercase: bool, } #[derive(Deserialize, Serialize)] @@ -33,6 +34,7 @@ pub fn default() -> Config { "shell".to_string(), "uptime".to_string(), ], + lowercase: false, }, colours: ColoursConfig { primary: "\x1B[39m".to_string(), diff --git a/src/config/mod.rs b/src/config/mod.rs index 2875279..bd7f26d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -34,7 +34,17 @@ pub fn init_config() -> Result> { pub fn read_config() -> Result> { let file = format!("{}/config.toml", config_dir()?); - let contents = fs::read_to_string(file)?; - let cfg: config::Config = toml::from_str(contents.as_str())?; - Ok(cfg) + let contents = fs::read_to_string(&file)?; + + match toml::from_str::(&contents) { + Ok(cfg) => Ok(cfg), + Err(_) => { + println!("[!] migrating config to latest version..."); + let cfg = config::default(); + let new_contents = toml::to_string(&cfg)?; + fs::write(&file, new_contents)?; + println!("[!] config migrated at: {file}"); + Ok(cfg) + } + } } diff --git a/src/main.rs b/src/main.rs index 4f9d2bd..01e842b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ fn main() -> Result<(), Box> { continue; } - let (key, value) = match module_name { + let (key, mut value) = match module_name { "os" => ("OS", data::os::distro()), "desktop" => ("DE", data::desktop::desktop()), "shell" => ("SH", data::shell::shell()), @@ -43,6 +43,10 @@ fn main() -> Result<(), Box> { _ => return Err(format!("unknown module '{}'", module_name).into()), }; + if cfg.display.lowercase { + value = value.to_lowercase(); + } + println!( "{line:max_length$} {accent}{key}{primary}{seperator}{value}{RESET}", accent = cfg.colours.accent,