From 9c7476d846f83553f8b6918532336bfcf46c0be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Have=CC=81?= Date: Sun, 30 Apr 2023 15:25:52 +0200 Subject: [PATCH] Remove GitTheme --- README.md | 13 ----- src/config_file.rs | 16 +----- src/core.rs | 3 +- src/display.rs | 16 +++--- src/flags.rs | 4 -- src/flags/git_theme.rs | 119 ----------------------------------------- src/git_theme.rs | 14 +---- 7 files changed, 12 insertions(+), 173 deletions(-) delete mode 100644 src/flags/git_theme.rs diff --git a/README.md b/README.md index 5540b8095..227ee075e 100644 --- a/README.md +++ b/README.md @@ -229,19 +229,6 @@ symlink-arrow: ⇒ # Whether to display block headers. # Possible values: false, true header: false - -# == Git == -git: - # Whether to display git status - # Possible values: false, true - enabled: false - # How to display git status - # When "classic" is set, this is set to "default". - # 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 - theme: default ``` diff --git a/src/config_file.rs b/src/config_file.rs index c627d1856..c9392c838 100644 --- a/src/config_file.rs +++ b/src/config_file.rs @@ -4,8 +4,8 @@ use crate::flags::layout::Layout; use crate::flags::permission::PermissionFlag; use crate::flags::size::SizeFlag; use crate::flags::sorting::{DirGrouping, SortColumn}; +use crate::flags::HyperlinkOption; use crate::flags::{ColorOption, ThemeOption}; -use crate::flags::{GitTheme, HyperlinkOption}; ///! This module provides methods to handle the program's config files and operations related to ///! this. use crate::print_error; @@ -45,7 +45,6 @@ pub struct Config { pub symlink_arrow: Option, pub hyperlink: Option, pub header: Option, - pub git_theme: Option, } #[derive(Eq, PartialEq, Debug, Deserialize)] @@ -98,7 +97,6 @@ impl Config { symlink_arrow: None, hyperlink: None, header: None, - git_theme: None, } } @@ -325,15 +323,6 @@ hyperlink: never # == Symlink arrow == # Specifies how the symlink arrow display, chars in both ascii and utf8 symlink-arrow: ⇒ - -# == Git == - # How to display git status - # When "classic" is set, this is set to "default". - # 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 -git-theme: default "#; #[cfg(test)] @@ -353,7 +342,7 @@ mod tests { use crate::flags::permission::PermissionFlag; use crate::flags::size::SizeFlag; use crate::flags::sorting::{DirGrouping, SortColumn}; - use crate::flags::{GitTheme, HyperlinkOption}; + use crate::flags::HyperlinkOption; #[test] fn test_read_default() { @@ -400,7 +389,6 @@ mod tests { symlink_arrow: Some("⇒".into()), hyperlink: Some(HyperlinkOption::Never), header: None, - git_theme: Some(GitTheme::Default) }, c ); diff --git a/src/core.rs b/src/core.rs index 14daad5bd..b0d0efc9c 100644 --- a/src/core.rs +++ b/src/core.rs @@ -51,7 +51,6 @@ impl Core { let icon_when = flags.icons.when; let icon_theme = flags.icons.theme.clone(); - let git_theme = flags.git_theme.clone(); // TODO: Rework this so that flags passed downstream does not // have Auto option for any (icon, color, hyperlink). @@ -81,7 +80,7 @@ impl Core { flags, colors: Colors::new(color_theme), icons: Icons::new(tty_available, icon_when, icon_theme, icon_separator), - git_theme: GitTheme::new(git_theme), + git_theme: GitTheme::new(), sorters, } } diff --git a/src/display.rs b/src/display.rs index b7c3afaf3..6fea6e9a3 100644 --- a/src/display.rs +++ b/src/display.rs @@ -488,9 +488,7 @@ mod tests { use crate::app::Cli; use crate::color; use crate::color::Colors; - use crate::flags::{ - GitTheme as GitFlagTheme, HyperlinkOption, IconOption, IconTheme as FlagTheme, - }; + use crate::flags::{HyperlinkOption, IconOption, IconTheme as FlagTheme}; use crate::icon::Icons; use crate::meta::{FileType, Name}; use crate::Config; @@ -697,7 +695,7 @@ mod tests { &flags, &Colors::new(color::ThemeOption::NoColor), &Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()), - &GitTheme::new(GitFlagTheme::Default), + &GitTheme::new(), ); assert_eq!("one.d\n├── .hidden\n└── two\n", output); @@ -729,7 +727,7 @@ mod tests { &flags, &Colors::new(color::ThemeOption::NoColor), &Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()), - &GitTheme::new(GitFlagTheme::Default), + &GitTheme::new(), ); let length_before_b = |i| -> usize { @@ -770,7 +768,7 @@ mod tests { &flags, &Colors::new(color::ThemeOption::NoColor), &Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()), - &GitTheme::new(GitFlagTheme::Default), + &GitTheme::new(), ); assert_eq!(output.lines().nth(1).unwrap().chars().next().unwrap(), '└'); @@ -810,7 +808,7 @@ mod tests { &flags, &Colors::new(color::ThemeOption::NoColor), &Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()), - &GitTheme::new(GitFlagTheme::Default), + &GitTheme::new(), ); assert!(output.ends_with("└── two\n")); @@ -841,7 +839,7 @@ mod tests { &flags, &Colors::new(color::ThemeOption::NoColor), &Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()), - &GitTheme::new(GitFlagTheme::Default), + &GitTheme::new(), ); dir.close().unwrap(); @@ -875,7 +873,7 @@ mod tests { &flags, &Colors::new(color::ThemeOption::NoColor), &Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string()), - &GitTheme::new(GitFlagTheme::Default), + &GitTheme::new(), ); dir.close().unwrap(); diff --git a/src/flags.rs b/src/flags.rs index 568faebb6..a73ac6534 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -3,7 +3,6 @@ pub mod color; pub mod date; pub mod dereference; pub mod display; -pub mod git_theme; pub mod header; pub mod hyperlink; pub mod icons; @@ -24,7 +23,6 @@ pub use color::{ColorOption, ThemeOption}; pub use date::DateFlag; pub use dereference::Dereference; pub use display::Display; -pub use git_theme::GitTheme; pub use header::Header; pub use hyperlink::HyperlinkOption; pub use icons::IconOption; @@ -74,7 +72,6 @@ pub struct Flags { pub symlink_arrow: SymlinkArrow, pub hyperlink: HyperlinkOption, pub header: Header, - pub git_theme: GitTheme, pub should_quote: bool, } @@ -105,7 +102,6 @@ impl Flags { symlink_arrow: SymlinkArrow::configure_from(cli, config), hyperlink: HyperlinkOption::configure_from(cli, config), header: Header::configure_from(cli, config), - git_theme: GitTheme::configure_from(cli, config), should_quote: true, }) } diff --git a/src/flags/git_theme.rs b/src/flags/git_theme.rs deleted file mode 100644 index 9db3fb79e..000000000 --- a/src/flags/git_theme.rs +++ /dev/null @@ -1,119 +0,0 @@ -//! This module defines the [GitTheme] flag. To set it up from [ArgMatches], a [Config] and its -//! [Default] value, use the [configure_from](Configurable::configure_from) method. - -use super::Configurable; -use serde::de::{self, Deserializer, Visitor}; - -use crate::app::Cli; -use crate::config_file::Config; - -/// Configure how to display git block -/// -/// git block is enabled in block flags -#[derive(Clone, Debug, PartialEq, Eq, Default)] -pub enum GitTheme { - /// Default ASCII theme - #[default] - Default, - /// Custom theme using a YAML config file - Custom(String), -} - -impl Configurable for GitTheme { - /// Get a potential `GitTheme` value from [ArgMatches]. - /// - /// Git theme is not yet configurable from cli - fn from_cli(_cli: &Cli) -> Option { - None - } - - /// Get a potential `GitTheme` value from a [Config]. - /// - /// If the `Config::git_theme` has value, - /// this returns it as the value of the `GitTheme`, in a [Some]. - /// Otherwise this returns [None]. - fn from_config(config: &Config) -> Option { - config.git_theme.clone() - } -} - -impl<'de> de::Deserialize<'de> for GitTheme { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - struct ThemeOptionVisitor; - - impl<'de> Visitor<'de> for ThemeOptionVisitor { - type Value = GitTheme; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("`default` or ") - } - - fn visit_str(self, value: &str) -> Result - where - E: de::Error, - { - match value { - "default" => Ok(GitTheme::Default), - str => Ok(GitTheme::Custom(str.to_string())), - } - } - } - - deserializer.deserialize_identifier(ThemeOptionVisitor) - } -} - -#[cfg(not(feature = "no-git"))] -#[cfg(test)] -mod test { - use clap::Parser; - - use super::GitTheme; - - use crate::app::Cli; - use crate::config_file::Config; - use crate::flags::Configurable; - - #[test] - fn test_from_arg_matches_none() { - let argv = ["lsd"]; - let cli = Cli::try_parse_from(argv).unwrap(); - assert_eq!(None, GitTheme::from_cli(&cli)); - } - - #[test] - fn test_from_arg_matches_true() { - let argv = ["lsd", "--git"]; - let cli = Cli::try_parse_from(argv).unwrap(); - assert_eq!(None, GitTheme::from_cli(&cli)); - } - - #[test] - fn test_from_config_none() { - assert_eq!(None, GitTheme::from_config(&Config::with_none())); - } - - #[test] - fn test_from_config_true() { - let mut c = Config::with_none(); - c.git_theme = Some(GitTheme::Default); - assert_eq!(Some(GitTheme::Default), GitTheme::from_config(&c)); - } - - #[test] - fn test_from_config_false() { - let mut c = Config::with_none(); - c.git_theme = Some(GitTheme::Default); - assert_eq!(Some(GitTheme::Default), GitTheme::from_config(&c)); - } - - #[test] - fn test_from_default_config() { - let mut c = Config::with_none(); - c.git_theme = None; - assert_eq!(None, GitTheme::from_config(&c)); - } -} diff --git a/src/git_theme.rs b/src/git_theme.rs index a884c45c7..27bd965e6 100644 --- a/src/git_theme.rs +++ b/src/git_theme.rs @@ -1,23 +1,13 @@ -use crate::flags::GitTheme as GitFlagTheme; use crate::git::GitStatus; use crate::theme::git::GitThemeSymbols; -use crate::theme::Theme; -use std::path::Path; pub struct GitTheme { symbols: GitThemeSymbols, } impl GitTheme { - pub fn new(theme: GitFlagTheme) -> GitTheme { - let git_symbols = match theme { - GitFlagTheme::Default => GitThemeSymbols::default(), - GitFlagTheme::Custom(ref file) => Theme::from_path::( - Path::new("themes").join(file).to_str().unwrap_or(file), - ) - .unwrap_or_default(), - }; - + pub fn new() -> GitTheme { + let git_symbols = GitThemeSymbols::default(); Self { symbols: git_symbols, }