From d7898c1e0eb8ecbd8463be677a6ad70c992ac937 Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Fri, 2 Jun 2023 18:41:57 +0000 Subject: [PATCH 1/3] Add complete color theming support for Git --- CHANGELOG.md | 1 + README.md | 11 +++++++++++ src/color.rs | 12 +++++++++++- src/theme/color.rs | 29 ++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de3a46f4d..1ee5d1414 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Add complete color theming support for Git [k4yt3x](https://github.com/k4yt3x] - Add [Git integration](https://github.com/Peltoche/lsd/issues/7) from [hpwxf](https://github.com/hpwxf) - In keeping with the coreutils change, add quotes and escapes for necessary filenames from [merelymyself](https://github.com/merelymyself) - Add support for icon theme from [zwpaper](https://github.com/zwpaper) diff --git a/README.md b/README.md index 227ee075e..ac49fd00b 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,17 @@ links: valid: 13 invalid: 245 tree-edge: 245 +git-status: + default: 245 + unmodified: 245 + ignored: 245 + new-in-index: dark_green + new-in-workdir: dark_green + typechange: dark_yellow + deleted: dark_red + renamed: dark_green + modified: dark_yellow + conflicted: dark_red ``` When creating a theme for `lsd`, you can specify any part of the default theme, diff --git a/src/color.rs b/src/color.rs index ed69849a3..eb0c40059 100644 --- a/src/color.rs +++ b/src/color.rs @@ -126,7 +126,17 @@ impl Elem { Elem::TreeEdge => theme.tree_edge, Elem::Links { valid: false } => theme.links.invalid, Elem::Links { valid: true } => theme.links.valid, - Elem::GitStatus { .. } => theme.git_status.default, + + Elem::GitStatus { status: GitStatus::Default } => theme.git_status.default, + Elem::GitStatus { status: GitStatus::Unmodified } => theme.git_status.unmodified, + Elem::GitStatus { status: GitStatus::Ignored } => theme.git_status.ignored, + Elem::GitStatus { status: GitStatus::NewInIndex } => theme.git_status.new_in_index, + Elem::GitStatus { status: GitStatus::NewInWorkdir } => theme.git_status.new_in_workdir, + Elem::GitStatus { status: GitStatus::Typechange } => theme.git_status.typechange, + Elem::GitStatus { status: GitStatus::Deleted } => theme.git_status.deleted, + Elem::GitStatus { status: GitStatus::Renamed } => theme.git_status.renamed, + Elem::GitStatus { status: GitStatus::Modified } => theme.git_status.modified, + Elem::GitStatus { status: GitStatus::Conflicted } => theme.git_status.conflicted, } } } diff --git a/src/theme/color.rs b/src/theme/color.rs index 86f84dfcd..35b871215 100644 --- a/src/theme/color.rs +++ b/src/theme/color.rs @@ -241,6 +241,24 @@ pub struct Links { pub struct GitStatus { #[serde(deserialize_with = "deserialize_color")] pub default: Color, + #[serde(deserialize_with = "deserialize_color")] + pub unmodified: Color, + #[serde(deserialize_with = "deserialize_color")] + pub ignored: Color, + #[serde(deserialize_with = "deserialize_color")] + pub new_in_index: Color, + #[serde(deserialize_with = "deserialize_color")] + pub new_in_workdir: Color, + #[serde(deserialize_with = "deserialize_color")] + pub typechange: Color, + #[serde(deserialize_with = "deserialize_color")] + pub deleted: Color, + #[serde(deserialize_with = "deserialize_color")] + pub renamed: Color, + #[serde(deserialize_with = "deserialize_color")] + pub modified: Color, + #[serde(deserialize_with = "deserialize_color")] + pub conflicted: Color, } impl Default for Permission { @@ -337,7 +355,16 @@ impl Default for Links { impl Default for GitStatus { fn default() -> Self { GitStatus { - default: Color::AnsiValue(13), // Pink + default: Color::AnsiValue(245), // Grey + unmodified: Color::AnsiValue(245), // Grey + ignored: Color::AnsiValue(245), // Grey + new_in_index: Color::DarkGreen, + new_in_workdir: Color::DarkGreen, + typechange: Color::DarkYellow, + deleted: Color::DarkRed, + renamed: Color::DarkGreen, + modified: Color::DarkYellow, + conflicted: Color::DarkRed, } } } From f40bd21cc992d92bc67f834af75ccad81f1049ec Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Sat, 3 Jun 2023 05:33:52 +0000 Subject: [PATCH 2/3] Suppressed NotFound error for Git status --- src/git.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/git.rs b/src/git.rs index 197e10cca..acc01108c 100644 --- a/src/git.rs +++ b/src/git.rs @@ -95,7 +95,9 @@ impl GitCache { match std::fs::canonicalize(filepath) { Ok(filename) => Some(self.inner_get(&filename, is_directory)), Err(err) => { - crate::print_error!("Cannot get git status for {:?}: {}", filepath, err); + if err.kind() != std::io::ErrorKind::NotFound { + crate::print_error!("Cannot get git status for {:?}: {}", filepath, err); + } None } } From 6ee2cd4466e395f4267ee182428a0cc8639b8936 Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Sat, 1 Jul 2023 21:54:20 +0000 Subject: [PATCH 3/3] Formatted src/color.rs to pass the cargo fmt check Signed-off-by: k4yt3x --- src/color.rs | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/color.rs b/src/color.rs index eb0c40059..1331553ce 100644 --- a/src/color.rs +++ b/src/color.rs @@ -127,16 +127,36 @@ impl Elem { Elem::Links { valid: false } => theme.links.invalid, Elem::Links { valid: true } => theme.links.valid, - Elem::GitStatus { status: GitStatus::Default } => theme.git_status.default, - Elem::GitStatus { status: GitStatus::Unmodified } => theme.git_status.unmodified, - Elem::GitStatus { status: GitStatus::Ignored } => theme.git_status.ignored, - Elem::GitStatus { status: GitStatus::NewInIndex } => theme.git_status.new_in_index, - Elem::GitStatus { status: GitStatus::NewInWorkdir } => theme.git_status.new_in_workdir, - Elem::GitStatus { status: GitStatus::Typechange } => theme.git_status.typechange, - Elem::GitStatus { status: GitStatus::Deleted } => theme.git_status.deleted, - Elem::GitStatus { status: GitStatus::Renamed } => theme.git_status.renamed, - Elem::GitStatus { status: GitStatus::Modified } => theme.git_status.modified, - Elem::GitStatus { status: GitStatus::Conflicted } => theme.git_status.conflicted, + Elem::GitStatus { + status: GitStatus::Default, + } => theme.git_status.default, + Elem::GitStatus { + status: GitStatus::Unmodified, + } => theme.git_status.unmodified, + Elem::GitStatus { + status: GitStatus::Ignored, + } => theme.git_status.ignored, + Elem::GitStatus { + status: GitStatus::NewInIndex, + } => theme.git_status.new_in_index, + Elem::GitStatus { + status: GitStatus::NewInWorkdir, + } => theme.git_status.new_in_workdir, + Elem::GitStatus { + status: GitStatus::Typechange, + } => theme.git_status.typechange, + Elem::GitStatus { + status: GitStatus::Deleted, + } => theme.git_status.deleted, + Elem::GitStatus { + status: GitStatus::Renamed, + } => theme.git_status.renamed, + Elem::GitStatus { + status: GitStatus::Modified, + } => theme.git_status.modified, + Elem::GitStatus { + status: GitStatus::Conflicted, + } => theme.git_status.conflicted, } } }