Added new custom option for color config, marked themes folder as deprecated. (#851)

This commit is contained in:
Pepijn Bakker 2023-06-23 14:19:25 +02:00 committed by GitHub
parent d97e7c42fd
commit 0e3f97b817
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 16 deletions

View file

@ -31,6 +31,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Icon theme with overrides from config [sudame](https://github.com/sudame)
- Incorrect colorizing with `--size=bytes` [bells307](https://github.com/bells307)
### Changed
- Color theme is now expected to be in `$XDG/lsd/colors.yaml` by default from [peppidesu](https://github.com/peppidesu)
Legacy behaviour (`themes` folder) is marked as deprecated but is still supported.
[#749](https://github.com/lsd-rs/lsd/issues/749)
## [0.23.1] - 2022-09-13
### Fixed

View file

@ -121,10 +121,8 @@ color:
when: auto
# How to colorize the output.
# When "classic" is set, this is set to "no-color".
# 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>.yaml,
# The file path if absolute
# Possible values: default, custom
# When "custom" is set, lsd will look in the config directory for `colors.yaml`.
theme: default
# == Date ==
@ -243,9 +241,13 @@ Color theme can be configured in the [configuration file](#configuration)(color.
The valid theme configurations are:
- `default`: the default color scheme shipped in `lsd`
- theme-file-name(yaml): use the theme file to specify colors(without the `yaml` extension)
- `custom`: use a custom color scheme defined in `colors.yaml`
- *(deprecated) theme_file_name(yaml): use the theme file to specify colors(without the `yaml` extension)*
when configured with the `theme-file-name` which is a `yaml` file,
When set to `custom`, `lsd` will look for `colors.yaml` in the
XDG Base Directory, e.g. ~/.config/lsd/colors.yaml
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, e.g. ~/.config/lsd/themes/<theme-file-name>.yaml

View file

@ -5,6 +5,7 @@ use std::path::Path;
pub use crate::flags::color::ThemeOption;
use crate::git::GitStatus;
use crate::print_output;
use crate::theme::{color::ColorTheme, Theme};
#[allow(dead_code)]
@ -143,7 +144,14 @@ impl Colors {
let theme = match t {
ThemeOption::NoColor => None,
ThemeOption::Default | ThemeOption::NoLscolors => Some(Theme::default().color),
ThemeOption::Custom(ref file) => {
ThemeOption::Custom => Some(
Theme::from_path::<ColorTheme>(Path::new("colors").to_str().unwrap())
.unwrap_or_default(),
),
ThemeOption::CustomLegacy(ref file) => {
print_output!(
"Warning: the 'themes' directory is deprecated, use 'colors.yaml' instead."
);
// TODO: drop the `themes` dir prefix, adding it here only for backwards compatibility
Some(
Theme::from_path::<ColorTheme>(
@ -154,7 +162,7 @@ impl Colors {
}
};
let lscolors = match t {
ThemeOption::Default | ThemeOption::Custom(_) => {
ThemeOption::Default | ThemeOption::Custom | ThemeOption::CustomLegacy(_) => {
Some(LsColors::from_env().unwrap_or_default())
}
_ => None,
@ -316,17 +324,25 @@ mod tests {
}
#[test]
fn test_color_new_default_theme() {
fn test_color_new_custom_theme() {
assert_eq!(
Colors::new(ThemeOption::Default).theme,
Colors::new(ThemeOption::Custom).theme,
Some(ColorTheme::default_dark()),
);
}
#[test]
fn test_color_new_bad_custom_theme() {
fn test_color_new_custom_no_file_theme() {
assert_eq!(
Colors::new(ThemeOption::Custom("not-existed".to_string())).theme,
Colors::new(ThemeOption::Custom).theme,
Some(ColorTheme::default_dark()),
);
}
#[test]
fn test_color_new_bad_legacy_custom_theme() {
assert_eq!(
Colors::new(ThemeOption::CustomLegacy("not-existed".to_string())).theme,
Some(ColorTheme::default_dark()),
);
}

View file

@ -40,7 +40,8 @@ pub enum ThemeOption {
Default,
#[allow(dead_code)]
NoLscolors,
Custom(String),
CustomLegacy(String),
Custom,
}
impl ThemeOption {
@ -77,7 +78,8 @@ impl<'de> de::Deserialize<'de> for ThemeOption {
{
match value {
"default" => Ok(ThemeOption::Default),
str => Ok(ThemeOption::Custom(str.to_string())),
"custom" => Ok(ThemeOption::Custom),
str => Ok(ThemeOption::CustomLegacy(str.to_string())),
}
}
}
@ -301,10 +303,10 @@ mod test_theme_option {
let mut c = Config::with_none();
c.color = Some(config_file::Color {
when: None,
theme: Some(ThemeOption::Custom("not-existed".to_string())),
theme: Some(ThemeOption::CustomLegacy("not-existed".to_string())),
});
assert_eq!(
ThemeOption::Custom("not-existed".to_string()),
ThemeOption::CustomLegacy("not-existed".to_string()),
ThemeOption::from_config(&c)
);
}