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 complete color theming support for Git #852

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 31 additions & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 126,37 @@ 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,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
29 changes: 28 additions & 1 deletion src/theme/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
Loading