diff options
author | Pepijn Bakker <bakker.pepijn@gmail.com> | 2023-06-23 14:19:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-23 20:19:25 +0800 |
commit | 0e3f97b8171ed521d5f84bad773d9aa04ce06ad3 (patch) | |
tree | 081031ab63a0818a073126a12fda298792f3d9f2 | |
parent | d97e7c42fd5b76aa6760f70c88cdbca432cc9aa3 (diff) |
Added new `custom` option for color config, marked themes folder as deprecated. (#851)
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | src/color.rs | 28 | ||||
-rw-r--r-- | src/flags/color.rs | 10 |
4 files changed, 41 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 779b6d4..fc44853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/src/color.rs b/src/color.rs index ed69849..2a8a315 100644 --- a/src/color.rs +++ b/src/color.rs @@ -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::Custom).theme, + Some(ColorTheme::default_dark()), + ); + } + + #[test] + fn test_color_new_custom_no_file_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_bad_legacy_custom_theme() { assert_eq!( - Colors::new(ThemeOption::Custom("not-existed".to_string())).theme, + Colors::new(ThemeOption::CustomLegacy("not-existed".to_string())).theme, Some(ColorTheme::default_dark()), ); } diff --git a/src/flags/color.rs b/src/flags/color.rs index fc76d34..96ec488 100644 --- a/src/flags/color.rs +++ b/src/flags/color.rs @@ -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) ); } |