From 61121e599d5b619dc6552c370820596eaf5d6116 Mon Sep 17 00:00:00 2001 From: zwPapEr Date: Tue, 31 Aug 2021 19:12:45 +0800 Subject: [PATCH] theme: :hammer: use `themes` dir for themes configurations Signed-off-by: zwPapEr --- README.md | 8 ++++---- src/color.rs | 5 ++--- src/color/theme.rs | 4 +++- src/flags/color.rs | 6 +++++- src/flags/icons.rs | 11 +---------- src/flags/layout.rs | 1 - src/meta/mod.rs | 2 +- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index aa13ece..a465245 100644 --- a/README.md +++ b/README.md @@ -215,9 +215,9 @@ color: when: auto # How to colorize the output. # When "classic" is set, this is set to "no-color". - # Possible values: default, no-color, no-lscolors, - # when specifying , lsd will look up theme file in - # XDG Base Directory if relative + # Possible values: default, + # when specifying , lsd will look up theme file + # XDG Base Directory if relative, e.g. ~/.config/lsd/themes/, # The file path if absolute theme: default @@ -322,7 +322,7 @@ The valid theme configurations are: when configured with the `theme-file-name` which is a `yaml` file, `lsd` will look up the theme file in the following way: -- relative name: check the XDG Base Directory +- relative name: check the themes under XDG Base Directory, e.g. ~/.config/lsd/themes/ - absolute name: use the file path and name to find theme file Check [Theme file content](#theme-file-content) for details. diff --git a/src/color.rs b/src/color.rs index 4cbc74c..99ec6db 100644 --- a/src/color.rs +++ b/src/color.rs @@ -136,12 +136,11 @@ impl Colors { ThemeOption::NoColor => None, ThemeOption::Default => Some(Theme::default()), ThemeOption::NoLscolors => Some(Theme::default()), - ThemeOption::Custom(ref file) => { - Some(Theme::from_path(file).unwrap_or_else(Theme::default)) - } + ThemeOption::Custom(ref file) => Some(Theme::from_path(file).unwrap_or_default()), }; let lscolors = match t { ThemeOption::Default => Some(LsColors::from_env().unwrap_or_default()), + ThemeOption::Custom(_) => Some(LsColors::from_env().unwrap_or_default()), _ => None, }; diff --git a/src/color/theme.rs b/src/color/theme.rs index 854ade7..e15c956 100644 --- a/src/color/theme.rs +++ b/src/color/theme.rs @@ -132,7 +132,9 @@ impl Theme { let path = if Path::new(&real).is_absolute() { real } else { - config_file::Config::config_file_path().unwrap().join(real) + config_file::Config::config_file_path()? + .join("themes") + .join(real) }; match fs::read(&path) { Ok(f) => match Self::with_yaml(&String::from_utf8_lossy(&f)) { diff --git a/src/flags/color.rs b/src/flags/color.rs index ec32719..161a7d4 100644 --- a/src/flags/color.rs +++ b/src/flags/color.rs @@ -153,7 +153,11 @@ impl Configurable for ColorOption { return Some(Self::Never); } - config.color.as_ref().map(|color| color.when) + if let Some(c) = &config.color { + c.when + } else { + None + } } fn from_environment() -> Option { diff --git a/src/flags/icons.rs b/src/flags/icons.rs index 48e305a..77217d0 100644 --- a/src/flags/icons.rs +++ b/src/flags/icons.rs @@ -100,16 +100,7 @@ pub enum IconTheme { Fancy, } -impl IconTheme { - // /// Get a value from a string. - // fn from_str(value: &str) -> Option { - // match value { - // "fancy" => Some(Self::Fancy), - // "unicode" => Some(Self::Unicode), - // _ => panic!("Bad icons.theme config, {}", &value), - // } - // } -} +impl IconTheme {} impl Configurable for IconTheme { /// Get a potential `IconTheme` variant from [ArgMatches]. diff --git a/src/flags/layout.rs b/src/flags/layout.rs index 74c1761..0b917bb 100644 --- a/src/flags/layout.rs +++ b/src/flags/layout.rs @@ -14,7 +14,6 @@ use serde::Deserialize; pub enum Layout { Grid, Tree, - #[serde(rename = "oneline")] OneLine, } diff --git a/src/meta/mod.rs b/src/meta/mod.rs index 476b08d..0a55d70 100644 --- a/src/meta/mod.rs +++ b/src/meta/mod.rs @@ -249,12 +249,12 @@ impl Meta { } } +#[cfg(unix)] #[cfg(test)] mod tests { use super::Meta; #[test] - #[cfg(unix)] fn test_from_path_path() { let dir = assert_fs::TempDir::new().unwrap(); let meta = Meta::from_path(dir.path(), false).unwrap();