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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! The multi-root REPOSITORIES overview: one row per workspace folder that is a git
//! repository, drawing them, and the click that picks one.
use super::*;
/// One row of the multi-root REPOSITORIES overview (#161): a workspace
/// folder that is a git repository, as the App's per-folder workers see
/// it each frame.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RepoRow {
pub label: String,
pub branch: Option<String>,
pub changes: usize,
pub active: bool,
pub workspace_root: std::path::PathBuf,
}
impl SourceControlPanel {
/// Paint the multi-root REPOSITORIES overview (#161) starting at `y`,
/// returning the y below it (unchanged when hidden). One row per
/// repository: label, branch (dim), change count (right-aligned),
/// the ACTIVE repository's row on the selection background.
pub(super) fn render_repositories_section(
&mut self,
inner: Rect,
y: u16,
buf: &mut Buffer,
) -> u16 {
if self.repositories.len() < 2 {
return y;
}
let bottom = inner.y + inner.height;
let mut y = y;
if y >= bottom {
return y;
}
let tones = crate::widgets::surface::tones(self.theme);
buf.set_stringn(
inner.x + 1,
y,
"REPOSITORIES",
inner.width.saturating_sub(1) as usize,
Style::default()
.fg(tones.map_or_else(
|| self.theme.ui(Color::Rgb(0x8a, 0x92, 0xa4)),
|t| t.muted(),
))
.add_modifier(Modifier::BOLD),
);
y += 1;
for row in &self.repositories {
if y >= bottom {
break;
}
let rect = Rect {
x: inner.x,
y,
width: inner.width,
height: 1,
};
// Croft Loch: rows stay on the chrome (the default background
// painted black bars across it), the active repository wears the
// selected-row band and bar, the label is body text and the
// branch muted.
if let Some(t) = tones {
let hovered = crate::widgets::hover::contains(rect, self.hover_pointer);
// Clear the row onto the chrome first: in the no-repo state
// the overview paints over the empty-state card's top.
for x in rect.left()..rect.right() {
buf[(x, y)]
.set_symbol(" ")
.set_style(Style::default().bg(t.chrome()));
}
if row.active {
crate::widgets::surface::paint_selected_row(
buf,
Rect {
x: rect.x.saturating_sub(1),
width: rect.width + u16::from(rect.x > 0),
..rect
},
t,
t.chrome,
self.focused,
);
} else if hovered {
buf.set_style(rect, Style::default().bg(t.hover_on(t.chrome)));
}
let branch = row.branch.as_deref().unwrap_or("—");
let weight = if row.active {
Modifier::BOLD
} else {
Modifier::empty()
};
let line = Line::from(vec![
Span::styled(
format!(" {}", row.label),
Style::default().fg(t.text()).add_modifier(weight),
),
Span::styled(format!(" {branch}"), Style::default().fg(t.muted())),
]);
buf.set_line(rect.x, y, &line, rect.width);
let left_w = line.width() as u16;
if row.changes > 0 {
let count = row.changes.to_string();
let cx = (rect.x + rect.width).saturating_sub(count.len() as u16 + 1);
if cx > rect.x + left_w {
buf.set_string(
cx,
y,
&count,
Style::default().fg(self.theme.ui(Color::Rgb(0xe0, 0x9a, 0x4e))),
);
}
}
self.repo_row_areas.push((rect, row.workspace_root.clone()));
y += 1;
continue;
}
let hover_bg =
crate::widgets::hover::row_hover_bg(rect, self.hover_pointer, self.theme);
let (bg, fg) = if row.active {
(self.theme.selection(), self.theme.ui(Color::White))
} else if let Some(h) = hover_bg {
(h, self.theme.ui(Color::Gray))
} else {
(Color::Reset, self.theme.ui(Color::Gray))
};
for x in rect.x..rect.x + rect.width {
buf[(x, y)].set_bg(bg);
}
let branch = row.branch.as_deref().unwrap_or("—");
let left = format!(" {} {branch}", row.label);
buf.set_stringn(
rect.x,
y,
&left,
rect.width as usize,
Style::default().bg(bg).fg(fg).add_modifier(if row.active {
Modifier::BOLD
} else {
Modifier::empty()
}),
);
if row.changes > 0 {
let count = row.changes.to_string();
let cx = (rect.x + rect.width).saturating_sub(count.len() as u16 + 1);
if cx > rect.x + left.len() as u16 {
buf.set_string(
cx,
y,
&count,
Style::default()
.bg(bg)
.fg(self.theme.ui(Color::Rgb(0xe0, 0x9a, 0x4e))),
);
}
}
self.repo_row_areas.push((rect, row.workspace_root.clone()));
y += 1;
}
// One blank spacer so the branch row does not crowd the section.
y = (y + 1).min(bottom);
y
}
/// Map a click to the repositories-overview row it landed on (#161).
pub fn click_repository(&self, x: u16, y: u16) -> Option<std::path::PathBuf> {
self.repo_row_areas
.iter()
.find(|(r, _)| x >= r.x && x < r.x + r.width && y == r.y)
.map(|(_, root)| root.clone())
}
}