theme: 🔨 use themes dir for themes configurations

Signed-off-by: zwPapEr <zw.paper@gmail.com>
This commit is contained in:
zwPapEr 2021-08-31 19:12:45 +08:00 committed by Abin Simon
parent 81c1a79c85
commit 61121e599d
7 changed files with 16 additions and 21 deletions

View file

@ -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, <theme-file-name>
# when specifying <theme-file-name>, lsd will look up theme file in
# XDG Base Directory if relative
# Possible values: default, <theme-file-name>
# when specifying <theme-file-name>, lsd will look up theme file
# XDG Base Directory if relative, e.g. ~/.config/lsd/themes/<theme-file-name>,
# 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/<theme-file-name>
- absolute name: use the file path and name to find theme file
Check [Theme file content](#theme-file-content) for details.

View file

@ -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,
};

View file

@ -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)) {

View file

@ -153,7 +153,11 @@ impl Configurable<Self> 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<Self> {

View file

@ -100,16 +100,7 @@ pub enum IconTheme {
Fancy,
}
impl IconTheme {
// /// Get a value from a string.
// fn from_str(value: &str) -> Option<Self> {
// match value {
// "fancy" => Some(Self::Fancy),
// "unicode" => Some(Self::Unicode),
// _ => panic!("Bad icons.theme config, {}", &value),
// }
// }
}
impl IconTheme {}
impl Configurable<Self> for IconTheme {
/// Get a potential `IconTheme` variant from [ArgMatches].

View file

@ -14,7 +14,6 @@ use serde::Deserialize;
pub enum Layout {
Grid,
Tree,
#[serde(rename = "oneline")]
OneLine,
}

View file

@ -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();