From 346c4feceb22a53c25c7c3ad625a7c236f49d5ef Mon Sep 17 00:00:00 2001 From: "J. Dekker" Date: Sat, 25 May 2024 00:06:36 +0200 Subject: [PATCH] config: support yofi.toml filename Allows editors to more easily syntax highlight. --- CHANGELOG.md | 2 ++ src/config.rs | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b2f6c2..5cc3dd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Features +- config.toml is now additionally supported. + ## Changes ## Fixes diff --git a/src/config.rs b/src/config.rs index 8665233..449650a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,7 +8,10 @@ use serde::Deserialize; use crate::style::{Margin, Padding, Radius}; use crate::Color; -const DEFAULT_CONFIG_NAME: &str = concat!(crate::prog_name!(), ".config"); +const DEFAULT_CONFIG_NAMES: [&str; 2] = [ + concat!(crate::prog_name!(), ".toml"), + concat!(crate::prog_name!(), ".config"), +]; const DEFAULT_ICON_SIZE: u16 = 16; const DEFAULT_FONT_SIZE: u16 = 24; @@ -112,17 +115,20 @@ struct Icon { } fn default_config_path() -> Result> { - let file = xdg::BaseDirectories::with_prefix(crate::prog_name!()) - .context("failed to get xdg dirs")? - .get_config_file(DEFAULT_CONFIG_NAME); - if file - .try_exists() - .with_context(|| format!("reading default config at {}", file.display()))? - { - Ok(Some(file)) - } else { - Ok(None) + let xdg_dirs = + xdg::BaseDirectories::with_prefix(crate::prog_name!()).context("failed to get xdg dirs")?; + + for &filename in &DEFAULT_CONFIG_NAMES { + let file = xdg_dirs.get_config_file(filename); + if file + .try_exists() + .with_context(|| format!("reading default config at {}", file.display()))? + { + return Ok(Some(file)); + } } + + Ok(None) } impl Config {