feat(ui): Add use_selection_fg flag to control selection foreground color (#2515)

This commit is contained in:
Clément 2025-03-22 14:11:54 +01:00 committed by GitHub
parent dcd9a00ff3
commit 65b57c4b60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 1 deletions

View file

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Select syntax highlighting theme out of the defaults from syntect [[@vasilismanol](https://github.com/vasilismanol)] ([#1931](https://github.com/extrawurst/gitui/issues/1931))
* new command-line option to override the default log file path (`--logfile`) [[@acuteenvy](https://github.com/acuteenvy)] ([#2539](https://github.com/gitui-org/gitui/pull/2539))
* dx: `make check` checks Cargo.toml dependency ordering using `cargo sort` [[@naseschwarz](https://github.com/naseschwarz)]
* add `use_selection_fg` to theme file to allow customizing selection foreground color [[@Upsylonbare](https://github.com/Upsylonbare)] ([#2515](https://github.com/gitui-org/gitui/pull/2515))
### Changed
* improve syntax highlighting file detection [[@acuteenvy](https://github.com/acuteenvy)] ([#2524](https://github.com/extrawurst/gitui/pull/2524))

View file

@ -49,3 +49,16 @@ Note that if you want to turn it off, you should use a blank string:
line_break: Some(""),
)
```
## Customizing selection
By default the `selection_fg` color is used to color the text of the selected line.
Diff line, filename, commit hashes, time and author are re-colored with `selection_fg` color.
This can be changed by specifying the `use_selection_fg` boolean in your `theme.ron`:
```
(
use_selection_fg: Some(false),
)
```
By default, `use_selection_fg` is set to `true`.

View file

@ -16,6 +16,7 @@ pub struct Theme {
command_fg: Color,
selection_bg: Color,
selection_fg: Color,
use_selection_fg: bool,
cmdbar_bg: Color,
cmdbar_extra_lines_bg: Color,
disabled_fg: Color,
@ -151,7 +152,11 @@ impl Theme {
selected: bool,
) -> Style {
if selected {
style.bg(self.selection_bg).fg(self.selection_fg)
if self.use_selection_fg {
style.bg(self.selection_bg).fg(self.selection_fg)
} else {
style.bg(self.selection_bg)
}
} else {
style
}
@ -340,6 +345,7 @@ impl Default for Theme {
command_fg: Color::White,
selection_bg: Color::Blue,
selection_fg: Color::White,
use_selection_fg: true,
cmdbar_bg: Color::Blue,
cmdbar_extra_lines_bg: Color::Blue,
disabled_fg: Color::DarkGray,
@ -387,6 +393,7 @@ mod tests {
(
selection_bg: Some("Black"),
selection_fg: Some("#ffffff"),
use_selection_fg: Some(false),
syntax: Some("InspiredGitHub")
)
"##