From 11873ac9ec45dd89248598e10f2525f4e1637c12 Mon Sep 17 00:00:00 2001 From: Pepijn Bakker Date: Sun, 28 May 2023 14:08:23 +0200 Subject: [PATCH 1/4] fix --- src/color.rs | 32 +++++++++++++++++++++++++------- src/flags/color.rs | 10 ++++++---- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/color.rs b/src/color.rs index ed69849a3..c6d336c42 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,9 +144,18 @@ impl Colors { let theme = match t { ThemeOption::NoColor => None, ThemeOption::Default | ThemeOption::NoLscolors => Some(Theme::default().color), - ThemeOption::Custom(ref file) => { - // TODO: drop the `themes` dir prefix, adding it here only for backwards compatibility + ThemeOption::Custom => { Some( + Theme::from_path::( + Path::new("colors.yaml").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::( Path::new("themes").join(file).to_str().unwrap_or(file), ) @@ -154,7 +164,7 @@ impl Colors { } }; let lscolors = match t { - ThemeOption::Default | ThemeOption::Custom(_) => { + ThemeOption::Default | ThemeOption::CustomLegacy(_) => { Some(LsColors::from_env().unwrap_or_default()) } _ => None, @@ -316,17 +326,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 fc76d34bd..96ec488e6 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) ); } From 1d96f2693eb7194df2b9f8f4568215b220d287c0 Mon Sep 17 00:00:00 2001 From: Pepijn Bakker Date: Sun, 28 May 2023 14:59:31 +0200 Subject: [PATCH 2/4] cargo fmt, fixed ls colors --- src/color.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/color.rs b/src/color.rs index c6d336c42..2a8a3151e 100644 --- a/src/color.rs +++ b/src/color.rs @@ -5,7 +5,7 @@ use std::path::Path; pub use crate::flags::color::ThemeOption; use crate::git::GitStatus; -use crate::{print_output}; +use crate::print_output; use crate::theme::{color::ColorTheme, Theme}; #[allow(dead_code)] @@ -144,18 +144,16 @@ impl Colors { let theme = match t { ThemeOption::NoColor => None, ThemeOption::Default | ThemeOption::NoLscolors => Some(Theme::default().color), - ThemeOption::Custom => { - Some( - Theme::from_path::( - Path::new("colors.yaml").to_str().unwrap() - ) + ThemeOption::Custom => Some( + Theme::from_path::(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."); + 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( + Some( Theme::from_path::( Path::new("themes").join(file).to_str().unwrap_or(file), ) @@ -164,7 +162,7 @@ impl Colors { } }; let lscolors = match t { - ThemeOption::Default | ThemeOption::CustomLegacy(_) => { + ThemeOption::Default | ThemeOption::Custom | ThemeOption::CustomLegacy(_) => { Some(LsColors::from_env().unwrap_or_default()) } _ => None, From 3739261e00aaa9a0d00b4d6165ac9903235a7ac8 Mon Sep 17 00:00:00 2001 From: Pepijn Bakker Date: Sun, 28 May 2023 15:00:10 +0200 Subject: [PATCH 3/4] updated docs --- CHANGELOG.md | 5 ++++- README.md | 14 ++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de3a46f4d..487b54c56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Handle dereference (-L) with broken symlink from [r3dArch](https://github.com/r3dArch) - Avoid using Clap's deprecated structs and functions [sudame](https://github.com/sudame) - Icon theme with overrides from config [sudame](https://github.com/sudame) - +### 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 diff --git a/README.md b/README.md index 227ee075e..f31ed509a 100644 --- a/README.md +++ b/README.md @@ -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, - # when specifying , lsd will look up theme file - # XDG Base Directory if relative, e.g. ~/.config/lsd/themes/.yaml, - # The file path if absolute + # Possible values: default, custom + # When "custom" is set, lsd will look in the config directory for `colors.conf`. 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/.yaml From fd28652a8ed0d2704f467f0b4324c6ceb164a79f Mon Sep 17 00:00:00 2001 From: Pepijn Bakker Date: Sun, 28 May 2023 15:02:45 +0200 Subject: [PATCH 4/4] fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f31ed509a..9ab912824 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ color: # How to colorize the output. # When "classic" is set, this is set to "no-color". # Possible values: default, custom - # When "custom" is set, lsd will look in the config directory for `colors.conf`. + # When "custom" is set, lsd will look in the config directory for `colors.yaml`. theme: default # == Date ==