Skip to content

Commit afe5a44

Browse files
committed
render normal vs. highlighted
1 parent 6ba6e79 commit afe5a44

File tree

6 files changed

+116
-54
lines changed

6 files changed

+116
-54
lines changed

src/components/commitlist.rs

Lines changed: 75 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ impl CommitList {
297297

298298
#[allow(clippy::too_many_arguments)]
299299
fn get_entry_to_add<'a>(
300+
&self,
300301
e: &'a LogEntry,
301302
selected: bool,
302303
tags: Option<String>,
@@ -315,6 +316,9 @@ impl CommitList {
315316
let splitter =
316317
Span::styled(splitter_txt, theme.text(true, selected));
317318

319+
let normal = !self.items.highlighting()
320+
|| (self.items.highlighting() && e.highlighted);
321+
318322
// marker
319323
if let Some(marked) = marked {
320324
txt.push(Span::styled(
@@ -331,15 +335,19 @@ impl CommitList {
331335
// commit hash
332336
txt.push(Span::styled(
333337
Cow::from(&*e.hash_short),
334-
theme.commit_hash(selected),
338+
normal
339+
.then(|| theme.commit_hash(selected))
340+
.unwrap_or_else(|| theme.commit_unhighlighted()),
335341
));
336342

337343
txt.push(splitter.clone());
338344

339345
// commit timestamp
340346
txt.push(Span::styled(
341347
Cow::from(e.time_to_string(now)),
342-
theme.commit_time(selected),
348+
normal
349+
.then(|| theme.commit_time(selected))
350+
.unwrap_or_else(|| theme.commit_unhighlighted()),
343351
));
344352

345353
txt.push(splitter.clone());
@@ -351,30 +359,41 @@ impl CommitList {
351359
// commit author
352360
txt.push(Span::styled::<String>(
353361
author,
354-
theme.commit_author(selected),
362+
normal
363+
.then(|| theme.commit_author(selected))
364+
.unwrap_or_else(|| theme.commit_unhighlighted()),
355365
));
356366

357367
txt.push(splitter.clone());
358368

359369
// commit tags
360370
if let Some(tags) = tags {
361371
txt.push(splitter.clone());
362-
txt.push(Span::styled(tags, theme.tags(selected)));
372+
txt.push(Span::styled(
373+
tags,
374+
normal
375+
.then(|| theme.tags(selected))
376+
.unwrap_or_else(|| theme.commit_unhighlighted()),
377+
));
363378
}
364379

365380
if let Some(local_branches) = local_branches {
366381
txt.push(splitter.clone());
367382
txt.push(Span::styled(
368383
local_branches,
369-
theme.branch(selected, true),
384+
normal
385+
.then(|| theme.branch(selected, true))
386+
.unwrap_or_else(|| theme.commit_unhighlighted()),
370387
));
371388
}
372389

373390
if let Some(remote_branches) = remote_branches {
374391
txt.push(splitter.clone());
375392
txt.push(Span::styled(
376393
remote_branches,
377-
theme.branch(selected, true),
394+
normal
395+
.then(|| theme.branch(selected, true))
396+
.unwrap_or_else(|| theme.commit_unhighlighted()),
378397
));
379398
}
380399

@@ -387,7 +406,9 @@ impl CommitList {
387406
// commit msg
388407
txt.push(Span::styled(
389408
format!("{:message_width$}", &e.msg),
390-
theme.text(true, selected),
409+
normal
410+
.then(|| theme.text(true, selected))
411+
.unwrap_or_else(|| theme.commit_unhighlighted()),
391412
));
392413

393414
Line::from(txt)
@@ -428,57 +449,18 @@ impl CommitList {
428449
.join(" ")
429450
});
430451

431-
let remote_branches = self
432-
.remote_branches
433-
.get(&e.id)
434-
.and_then(|remote_branches| {
435-
let filtered_branches: Vec<_> = remote_branches
436-
.iter()
437-
.filter(|remote_branch| {
438-
self.local_branches
439-
.get(&e.id)
440-
.map_or(true, |local_branch| {
441-
local_branch.iter().any(
442-
|local_branch| {
443-
let has_corresponding_local_branch = match &local_branch.details {
444-
BranchDetails::Local(details) =>
445-
details
446-
.upstream
447-
.as_ref()
448-
.map_or(false, |upstream| upstream.reference == remote_branch.reference),
449-
BranchDetails::Remote(_) =>
450-
false,
451-
};
452-
453-
!has_corresponding_local_branch
454-
},
455-
)
456-
})
457-
})
458-
.map(|remote_branch| {
459-
format!("[{0}]", remote_branch.name)
460-
})
461-
.collect();
462-
463-
if filtered_branches.is_empty() {
464-
None
465-
} else {
466-
Some(filtered_branches.join(" "))
467-
}
468-
});
469-
470452
let marked = if any_marked {
471453
self.is_marked(&e.id)
472454
} else {
473455
None
474456
};
475457

476-
txt.push(Self::get_entry_to_add(
458+
txt.push(self.get_entry_to_add(
477459
e,
478460
idx + self.scroll_top.get() == selection,
479461
tags,
480462
local_branches,
481-
remote_branches,
463+
self.remote_branches_string(e),
482464
&self.theme,
483465
width,
484466
now,
@@ -489,6 +471,51 @@ impl CommitList {
489471
txt
490472
}
491473

474+
fn remote_branches_string(&self, e: &LogEntry) -> Option<String> {
475+
self.remote_branches.get(&e.id).and_then(|remote_branches| {
476+
let filtered_branches: Vec<_> = remote_branches
477+
.iter()
478+
.filter(|remote_branch| {
479+
self.local_branches.get(&e.id).map_or(
480+
true,
481+
|local_branch| {
482+
local_branch.iter().any(|local_branch| {
483+
let has_corresponding_local_branch =
484+
match &local_branch.details {
485+
BranchDetails::Local(
486+
details,
487+
) => details
488+
.upstream
489+
.as_ref()
490+
.map_or(
491+
false,
492+
|upstream| {
493+
upstream.reference == remote_branch.reference
494+
},
495+
),
496+
BranchDetails::Remote(_) => {
497+
false
498+
}
499+
};
500+
501+
!has_corresponding_local_branch
502+
})
503+
},
504+
)
505+
})
506+
.map(|remote_branch| {
507+
format!("[{0}]", remote_branch.name)
508+
})
509+
.collect();
510+
511+
if filtered_branches.is_empty() {
512+
None
513+
} else {
514+
Some(filtered_branches.join(" "))
515+
}
516+
})
517+
}
518+
492519
#[allow(clippy::missing_const_for_fn)]
493520
fn relative_selection(&self) -> usize {
494521
self.selection.saturating_sub(self.items.index_offset())

src/components/file_revlog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl FileRevlogComponent {
257257
//
258258
// [gitui-issue]: https://github.com/extrawurst/gitui/issues/1560
259259
// [tui-issue]: https://github.com/fdehau/tui-rs/issues/626
260-
self.items.set_items(0, commits);
260+
self.items.set_items(0, commits, &None);
261261
}
262262

263263
self.table_state.set(table_state);

src/components/utils/logitems.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use asyncgit::sync::{CommitId, CommitInfo};
22
use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc};
3-
use std::slice::Iter;
3+
use std::{collections::HashSet, slice::Iter};
44

55
#[cfg(feature = "ghemoji")]
66
use super::emoji::emojifi_string;
@@ -18,6 +18,7 @@ pub struct LogEntry {
1818
//TODO: use tinyvec here
1919
pub hash_short: BoxStr,
2020
pub id: CommitId,
21+
pub highlighted: bool,
2122
}
2223

2324
impl From<CommitInfo> for LogEntry {
@@ -49,6 +50,7 @@ impl From<CommitInfo> for LogEntry {
4950
time,
5051
hash_short,
5152
id: c.id,
53+
highlighted: false,
5254
}
5355
}
5456
}
@@ -76,6 +78,7 @@ impl LogEntry {
7678
pub struct ItemBatch {
7779
index_offset: usize,
7880
items: Vec<LogEntry>,
81+
highlighting: bool,
7982
}
8083

8184
impl ItemBatch {
@@ -88,6 +91,11 @@ impl ItemBatch {
8891
self.index_offset
8992
}
9093

94+
///
95+
pub const fn highlighting(&self) -> bool {
96+
self.highlighting
97+
}
98+
9199
/// shortcut to get an `Iter` of our internal items
92100
pub fn iter(&self) -> Iter<'_, LogEntry> {
93101
self.items.iter()
@@ -103,9 +111,24 @@ impl ItemBatch {
103111
&mut self,
104112
start_index: usize,
105113
commits: Vec<CommitInfo>,
114+
hightlighted: &Option<HashSet<CommitId>>,
106115
) {
116+
log::debug!("highlighted: {:?}", hightlighted);
107117
self.items.clear();
108-
self.items.extend(commits.into_iter().map(LogEntry::from));
118+
self.items.extend(commits.into_iter().map(|c| {
119+
let id = c.id;
120+
let mut entry = LogEntry::from(c);
121+
if hightlighted
122+
.as_ref()
123+
.map(|highlighted| highlighted.contains(&id))
124+
.unwrap_or_default()
125+
{
126+
log::debug!("highlighting: {:?}", id);
127+
entry.highlighted = true;
128+
}
129+
entry
130+
}));
131+
self.highlighting = hightlighted.is_some();
109132
self.index_offset = start_index;
110133
}
111134

src/tabs/revlog.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use ratatui::{
2424
layout::{Constraint, Direction, Layout, Rect},
2525
Frame,
2626
};
27-
use std::time::Duration;
27+
use std::{collections::HashSet, time::Duration};
2828
use sync::CommitTags;
2929

3030
const SLICE_SIZE: usize = 1200;
@@ -35,6 +35,7 @@ pub struct Revlog {
3535
commit_details: CommitDetailsComponent,
3636
list: CommitList,
3737
git_log: AsyncLog,
38+
3839
git_tags: AsyncTags,
3940
git_local_branches: AsyncSingleJob<AsyncBranchesJob>,
4041
git_remote_branches: AsyncSingleJob<AsyncBranchesJob>,
@@ -184,7 +185,14 @@ impl Revlog {
184185
);
185186

186187
if let Ok(commits) = commits {
187-
self.list.items().set_items(want_min, commits);
188+
let highlighted: HashSet<CommitId> =
189+
commits.iter().map(|c| c.id).take(10).collect();
190+
191+
self.list.items().set_items(
192+
want_min,
193+
commits,
194+
&Some(highlighted),
195+
);
188196
}
189197

190198
Ok(())

src/tabs/stashlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl StashList {
5555
)?;
5656

5757
self.list.set_count_total(commits.len());
58-
self.list.items().set_items(0, commits);
58+
self.list.items().set_items(0, commits, &None);
5959
}
6060

6161
Ok(())

src/ui/style.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ impl Theme {
212212
)
213213
}
214214

215+
pub fn commit_unhighlighted(&self) -> Style {
216+
Style::default().fg(self.disabled_fg)
217+
}
218+
215219
pub fn log_marker(&self, selected: bool) -> Style {
216220
let mut style = Style::default()
217221
.fg(self.commit_author)

0 commit comments

Comments
 (0)