Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
zwpaper marked this conversation as resolved.
Show resolved Hide resolved
theme: default

# == Date ==
Expand Down Expand Up @@ -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
Expand Down
28 changes: 22 additions & 6 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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>(
Expand All @@ -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,
Expand Down Expand Up @@ -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()),
);
}
Expand Down
10 changes: 6 additions & 4 deletions src/flags/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ pub enum ThemeOption {
Default,
#[allow(dead_code)]
NoLscolors,
Custom(String),
CustomLegacy(String),
Custom,
}

impl ThemeOption {
Expand Down Expand Up @@ -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())),
}
}
}
Expand Down Expand Up @@ -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)
);
}
Expand Down