diff options
author | Ofer Sadan <ofersadan85@gmail.com> | 2024-01-02 13:38:10 +0200 |
---|---|---|
committer | Wei Zhang <kweizh@gmail.com> | 2024-03-22 23:59:12 +0800 |
commit | 94538d01e08e3b9aa53d6ee1f34b00c0b79420ed (patch) | |
tree | 3eb3b8e18409e3bd0ea3837e2d1d766bbe49e552 /src/theme.rs | |
parent | a1bd4d634722e223ad562323e4cea8e1f8f97963 (diff) |
Support multiple file paths for config and theme
Diffstat (limited to 'src/theme.rs')
-rw-r--r-- | src/theme.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/theme.rs b/src/theme.rs index f18b331..82daeb4 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -38,9 +38,9 @@ pub enum Error { } impl Theme { - /// This read theme from file, - /// use the file path if it is absolute - /// prefix the config_file dir to it if it is not + /// Read theme from a file path + /// use the file path as-is if it is absolute + /// search the config paths folders for it if not pub fn from_path<D>(file: &str) -> Result<D, Error> where D: DeserializeOwned + Default, @@ -54,9 +54,16 @@ impl Theme { let path = if Path::new(&real).is_absolute() { real } else { - match config_file::Config::config_file_path() { - Some(p) => p.join(real), - None => return Err(Error::InvalidPath("config home not existed".into())), + let path = config_file::Config::config_paths() + .map(|p| p.join(real.clone())) + .find(|p| p.is_file()); + match path { + Some(p) => p, + None => { + return Err(Error::InvalidPath( + "Did not find theme file in config folders".into(), + )) + } } }; |