Skip to content

Commit

Permalink
config: support yofi.toml filename
Browse files Browse the repository at this point in the history
Allows editors to more easily syntax highlight.
  • Loading branch information
jdek committed May 24, 2024
1 parent f773614 commit 346c4fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Features

- config.toml is now additionally supported.

## Changes

## Fixes
Expand Down
28 changes: 17 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,17 +115,20 @@ struct Icon {
}

fn default_config_path() -> Result<Option<PathBuf>> {
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 {
Expand Down

0 comments on commit 346c4fe

Please sign in to comment.