mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-13 21:52:37 +00:00
theme: 🔨 use themes
dir for themes configurations
Signed-off-by: zwPapEr <zw.paper@gmail.com>
This commit is contained in:
parent
81c1a79c85
commit
61121e599d
7 changed files with 16 additions and 21 deletions
|
@ -215,9 +215,9 @@ color:
|
||||||
when: auto
|
when: auto
|
||||||
# How to colorize the output.
|
# How to colorize the output.
|
||||||
# When "classic" is set, this is set to "no-color".
|
# When "classic" is set, this is set to "no-color".
|
||||||
# Possible values: default, no-color, no-lscolors, <theme-file-name>
|
# Possible values: default, <theme-file-name>
|
||||||
# when specifying <theme-file-name>, lsd will look up theme file in
|
# when specifying <theme-file-name>, lsd will look up theme file
|
||||||
# XDG Base Directory if relative
|
# XDG Base Directory if relative, e.g. ~/.config/lsd/themes/<theme-file-name>,
|
||||||
# The file path if absolute
|
# The file path if absolute
|
||||||
theme: default
|
theme: default
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ The valid theme configurations are:
|
||||||
|
|
||||||
when configured with the `theme-file-name` which is a `yaml` file,
|
when configured with the `theme-file-name` which is a `yaml` file,
|
||||||
`lsd` will look up the theme file in the following way:
|
`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
|
- absolute name: use the file path and name to find theme file
|
||||||
|
|
||||||
Check [Theme file content](#theme-file-content) for details.
|
Check [Theme file content](#theme-file-content) for details.
|
||||||
|
|
|
@ -136,12 +136,11 @@ impl Colors {
|
||||||
ThemeOption::NoColor => None,
|
ThemeOption::NoColor => None,
|
||||||
ThemeOption::Default => Some(Theme::default()),
|
ThemeOption::Default => Some(Theme::default()),
|
||||||
ThemeOption::NoLscolors => Some(Theme::default()),
|
ThemeOption::NoLscolors => Some(Theme::default()),
|
||||||
ThemeOption::Custom(ref file) => {
|
ThemeOption::Custom(ref file) => Some(Theme::from_path(file).unwrap_or_default()),
|
||||||
Some(Theme::from_path(file).unwrap_or_else(Theme::default))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let lscolors = match t {
|
let lscolors = match t {
|
||||||
ThemeOption::Default => Some(LsColors::from_env().unwrap_or_default()),
|
ThemeOption::Default => Some(LsColors::from_env().unwrap_or_default()),
|
||||||
|
ThemeOption::Custom(_) => Some(LsColors::from_env().unwrap_or_default()),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,9 @@ impl Theme {
|
||||||
let path = if Path::new(&real).is_absolute() {
|
let path = if Path::new(&real).is_absolute() {
|
||||||
real
|
real
|
||||||
} else {
|
} else {
|
||||||
config_file::Config::config_file_path().unwrap().join(real)
|
config_file::Config::config_file_path()?
|
||||||
|
.join("themes")
|
||||||
|
.join(real)
|
||||||
};
|
};
|
||||||
match fs::read(&path) {
|
match fs::read(&path) {
|
||||||
Ok(f) => match Self::with_yaml(&String::from_utf8_lossy(&f)) {
|
Ok(f) => match Self::with_yaml(&String::from_utf8_lossy(&f)) {
|
||||||
|
|
|
@ -153,7 +153,11 @@ impl Configurable<Self> for ColorOption {
|
||||||
return Some(Self::Never);
|
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> {
|
fn from_environment() -> Option<Self> {
|
||||||
|
|
|
@ -100,16 +100,7 @@ pub enum IconTheme {
|
||||||
Fancy,
|
Fancy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IconTheme {
|
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 Configurable<Self> for IconTheme {
|
impl Configurable<Self> for IconTheme {
|
||||||
/// Get a potential `IconTheme` variant from [ArgMatches].
|
/// Get a potential `IconTheme` variant from [ArgMatches].
|
||||||
|
|
|
@ -14,7 +14,6 @@ use serde::Deserialize;
|
||||||
pub enum Layout {
|
pub enum Layout {
|
||||||
Grid,
|
Grid,
|
||||||
Tree,
|
Tree,
|
||||||
#[serde(rename = "oneline")]
|
|
||||||
OneLine,
|
OneLine,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,12 +249,12 @@ impl Meta {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Meta;
|
use super::Meta;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
|
||||||
fn test_from_path_path() {
|
fn test_from_path_path() {
|
||||||
let dir = assert_fs::TempDir::new().unwrap();
|
let dir = assert_fs::TempDir::new().unwrap();
|
||||||
let meta = Meta::from_path(dir.path(), false).unwrap();
|
let meta = Meta::from_path(dir.path(), false).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue