Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/example_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ascii = "stack"
seperator = ": "
modules = ["os", "desktop", "shell", "uptime"]
lowercase = false

[colours]
primary = "\u001B[39m" # reset
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct DisplayConfig {
pub ascii: String,
pub seperator: String,
pub modules: Vec<String>,
pub lowercase: bool,
}

#[derive(Deserialize, Serialize)]
Expand All @@ -33,6 +34,7 @@ pub fn default() -> Config {
"shell".to_string(),
"uptime".to_string(),
],
lowercase: false,
},
colours: ColoursConfig {
primary: "\x1B[39m".to_string(),
Expand Down
16 changes: 13 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ pub fn init_config() -> Result<bool, Box<dyn Error>> {

pub fn read_config() -> Result<config::Config, Box<dyn Error>> {
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::<config::Config>(&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)
}
}
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ fn main() -> Result<(), Box<dyn Error>> {
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()),
"uptime" => ("UP", data::uptime::uptime()),
_ => 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,
Expand Down