1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! How a row looks: its git decoration and name colour, the folder icon's colour, the
//! active indent guide, and whether a path is ignored, gone at the scrubbed commit, or
//! changed by an agent and not yet reviewed.
use super::*;
impl FileTree {
/// The git decoration `path`'s row wears (#1513). None on a workspace
/// root row, and none while the history scrubber shows a commit: the
/// working tree's changes are not that commit's.
pub fn git_decoration(&self, path: &Path) -> Option<crate::git::GitDecoration> {
if self.scrub_tree.is_some() || self.is_root_path(path) {
return None;
}
self.git_decorations.get(path).copied()
}
/// A row's name colour: dimmed when git ignores it (or it is absent at
/// the scrubbed commit), its git decoration's colour when it changed,
/// the plain foreground otherwise.
pub(super) fn name_fg(&self, cx: &ViewCx, path: &Path) -> Color {
if self.is_ignored(path) || self.is_absent_at_scrub(path) {
cx.theme.ignored_fg()
} else if let Some(dec) = self.git_decoration(path) {
cx.theme.git_decoration_fg(dec)
} else if let Some(t) = crate::theme::tones(cx.theme) {
// Croft Loch's body ink: the named White follows the host
// terminal's palette and is usually pure #fff.
t.text()
} else {
cx.theme.ui(Color::White)
}
}
/// A folder icon's colour: the icon's own tan on a boxed theme, eased
/// most of the way toward the muted ink under `surfaces`, so folders
/// read by their shape and a long tree is not a column of gold.
pub(super) fn folder_icon_fg(&self, cx: &ViewCx, color: Color) -> Color {
match (crate::theme::tones(cx.theme), color) {
(Some(t), Color::Rgb(r, g, b)) => {
crate::gradient::rgb_color(crate::gradient::lerp_rgb((r, g, b), t.muted, 0.45))
}
_ => cx.theme.ui(color),
}
}
/// The active indent guide for Croft Loch's tree: the level of the
/// selected row's parent folder and the node-index range of that
/// folder's children, `(level, first, end)`. `None` when the selection
/// sits directly under a root, whose level draws no guide.
pub(super) fn active_indent_guide(&self) -> Option<(usize, usize, usize)> {
let sel = self.nodes.get(self.selected)?;
if sel.depth < 2 {
return None;
}
let parent = (0..self.selected)
.rev()
.find(|&i| self.nodes[i].depth < sel.depth)?;
let level = self.nodes[parent].depth;
let end = (parent + 1..self.nodes.len())
.find(|&i| self.nodes[i].depth <= level)
.unwrap_or(self.nodes.len());
Some((level, parent + 1, end))
}
/// True when `path` is git-ignored: either listed in the ignored set
/// itself or a descendant of an ignored directory (the set stores a
/// fully-ignored dir as one collapsed entry). Walks ancestors up to the
/// workspace root, so the cost is O(depth) per visible row.
pub fn is_ignored(&self, path: &Path) -> bool {
if self.ignored.is_empty() {
return false;
}
let mut p = path;
loop {
if self.ignored.contains(p) {
return true;
}
// Stop at whichever workspace root owns the path (#145): the
// walk must never escape a root into its parent directories.
if self.is_root_path(p) {
return false;
}
match p.parent() {
Some(parent) => p = parent,
None => return false,
}
}
}
/// True when the scrubber sits on a commit whose tree lacks `path`
/// (#371). Only paths strictly under the listed directory count: the
/// root row itself, and rows of another workspace root the listing
/// never covered, keep their colour.
pub fn is_absent_at_scrub(&self, path: &Path) -> bool {
let Some((base, present)) = self.scrub_tree.as_ref() else {
return false;
};
path != base && path.starts_with(base) && !present.contains(path)
}
/// Whether `path` is a file an agent changed that is still unreviewed.
///
/// Exact membership, deliberately: see [`Self::agent_touched`].
pub fn is_agent_touched(&self, path: &Path) -> bool {
!self.agent_touched.is_empty() && self.agent_touched.contains(path)
}
/// Whether a collapsed folder at `dir` hides a file an agent changed and
/// the user has not reviewed (#345), for its dimmer rollup dot.
///
/// Derived at paint time from [`Self::agent_touched`], never stored: the
/// dot clears by itself when the last file under it is reviewed, which
/// is what keeps it from being the mark no gesture removes that the
/// field's exact membership guards against.
pub fn hides_agent_touched(&self, dir: &Path) -> bool {
!self.agent_touched.is_empty()
&& self
.agent_touched
.iter()
.any(|p| p != dir && p.starts_with(dir))
}
}