Skip to content

Commit 4301bdd

Browse files
authored
Add detail color configs (#113)
* Add detail color configs * Update README * Update config.schema.json
1 parent cf8bae0 commit 4301bdd

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ list_hash_fg = "yellow"
411411
list_date_fg = "magenta"
412412
list_match_fg = "black"
413413
list_match_bg = "yellow"
414+
detail_label_fg = "reset"
415+
detail_name_fg = "reset"
416+
detail_date_fg = "reset"
414417
detail_email_fg = "blue"
418+
detail_hash_fg = "reset"
415419
detail_ref_branch_fg = "green"
416420
detail_ref_remote_branch_fg = "red"
417421
detail_ref_tag_fg = "yellow"

config.schema.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,31 @@
351351
"description": "Background color for a search match in the commit list.",
352352
"default": "yellow"
353353
},
354+
"detail_label_fg": {
355+
"type": "string",
356+
"description": "Color for labels in the commit detail view.",
357+
"default": "reset"
358+
},
359+
"detail_name_fg": {
360+
"type": "string",
361+
"description": "Color for author/committer names in the commit detail view.",
362+
"default": "reset"
363+
},
364+
"detail_date_fg": {
365+
"type": "string",
366+
"description": "Color for author/committer dates in the commit detail view.",
367+
"default": "reset"
368+
},
354369
"detail_email_fg": {
355370
"type": "string",
356-
"description": "Color for email addresses in the commit detail view.",
371+
"description": "Color for author/committer email addresses in the commit detail view.",
357372
"default": "blue"
358373
},
374+
"detail_hash_fg": {
375+
"type": "string",
376+
"description": "Color for the commit hash in the commit detail view.",
377+
"default": "reset"
378+
},
359379
"detail_ref_branch_fg": {
360380
"type": "string",
361381
"description": "Color for local branches in the commit detail view.",

src/color.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ pub struct ColorTheme {
4242
#[default(RatatuiColor::Yellow)]
4343
pub list_match_bg: RatatuiColor,
4444

45+
#[default(RatatuiColor::Reset)]
46+
pub detail_label_fg: RatatuiColor,
47+
#[default(RatatuiColor::Reset)]
48+
pub detail_name_fg: RatatuiColor,
49+
#[default(RatatuiColor::Reset)]
50+
pub detail_date_fg: RatatuiColor,
4551
#[default(RatatuiColor::Blue)]
4652
pub detail_email_fg: RatatuiColor,
53+
#[default(RatatuiColor::Reset)]
54+
pub detail_hash_fg: RatatuiColor,
4755
#[default(RatatuiColor::Green)]
4856
pub detail_ref_branch_fg: RatatuiColor,
4957
#[default(RatatuiColor::Red)]

src/widget/commit_detail.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,26 @@ impl CommitDetail<'_> {
128128
let mut label_lines: Vec<Line> = Vec::new();
129129
let mut value_lines: Vec<Line> = Vec::new();
130130

131-
label_lines.push(Line::raw(" Author: "));
131+
label_lines.push(Line::from(" Author: ").fg(self.color_theme.detail_label_fg));
132132
label_lines.push(self.empty_line());
133133
value_lines.extend(self.author_lines());
134134

135135
if is_author_committer_different(self.commit) {
136-
label_lines.push(Line::raw("Committer: "));
136+
label_lines.push(Line::from("Committer: ").fg(self.color_theme.detail_label_fg));
137137
label_lines.push(self.empty_line());
138138
value_lines.extend(self.committer_lines());
139139
}
140140

141-
label_lines.push(Line::raw(" SHA: "));
141+
label_lines.push(Line::from(" SHA: ").fg(self.color_theme.detail_label_fg));
142142
value_lines.push(self.sha_line());
143143

144144
if has_parent(self.commit) {
145-
label_lines.push(Line::raw(" Parents: "));
145+
label_lines.push(Line::from(" Parents: ").fg(self.color_theme.detail_label_fg));
146146
value_lines.push(self.parents_line());
147147
}
148148

149149
if has_refs(self.refs) {
150-
label_lines.push(Line::raw(" Refs: "));
150+
label_lines.push(Line::from(" Refs: ").fg(self.color_theme.detail_label_fg));
151151
value_lines.push(self.refs_line());
152152
}
153153

@@ -190,25 +190,30 @@ impl CommitDetail<'_> {
190190
};
191191
vec![
192192
Line::from(vec![
193-
name.into(),
193+
name.fg(self.color_theme.detail_name_fg),
194194
" <".into(),
195195
email.fg(self.color_theme.detail_email_fg),
196196
"> ".into(),
197197
]),
198-
Line::raw(date_str),
198+
Line::from(date_str.fg(self.color_theme.detail_date_fg)),
199199
]
200200
}
201201

202202
fn sha_line(&self) -> Line<'_> {
203-
Line::raw(self.commit.commit_hash.as_str())
203+
Line::from(
204+
self.commit
205+
.commit_hash
206+
.as_str()
207+
.fg(self.color_theme.detail_hash_fg),
208+
)
204209
}
205210

206211
fn parents_line(&self) -> Line<'_> {
207212
let mut spans = Vec::new();
208213
let parents = &self.commit.parent_commit_hashes;
209214
for (i, hash) in parents
210215
.iter()
211-
.map(|hash| Span::raw(hash.as_short_hash()))
216+
.map(|hash| hash.as_short_hash().fg(self.color_theme.detail_hash_fg))
212217
.enumerate()
213218
{
214219
spans.push(hash);

0 commit comments

Comments
 (0)