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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
use crate::git::{ChangeEntry, ChangeKind, ChangeSection, GitStatus};
use crate::icons;
use crate::widgets::scrollbar;
use crate::widgets::view_cx::ViewCx;
use ratatui::{
buffer::Buffer,
layout::{Alignment, Rect},
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph, Widget, Wrap},
};
use std::collections::BTreeSet;
mod buttons;
mod change_list;
mod clicks;
mod commit_menu;
mod empty_state;
mod key_stops;
mod message;
mod palette;
mod render;
mod repositories;
pub use buttons::primary_button_colors;
pub use buttons::render_button;
use buttons::*;
use change_list::*;
use clicks::*;
pub use commit_menu::CommitMenuItem;
pub use empty_state::CardButton;
use message::*;
use palette::*;
#[cfg(test)]
use render::*;
pub use repositories::RepoRow;
/// Source Control's Tab stops (#871), in VS Code's order: Tab steps down
/// them and round again, Shift+Tab steps back up. Only the stops on screen
/// take part: REPOSITORIES while there are several, and in a folder with
/// no repository the card's buttons in place of the message box, the
/// change list and COMMITS.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum KeyStop {
/// The REPOSITORIES rows: the arrows move `repo_cursor`, Enter or Space
/// switches the view to that repository, as a click on its row does.
Repositories,
/// The commit message box: typing writes the message.
#[default]
Message,
/// The change list: the arrows move `selected_change`, Enter opens its
/// diff. Tab, or Down on the message's last line, steps here; Shift+Tab,
/// or Up on the first row, steps back.
List,
/// COMMITS, below the change list: the arrows pick a commit, Enter
/// opens it.
Commits,
/// The no-repository card's buttons, Initialize Repository or each
/// subfolder repository's Open: `card_button` is the one with the keys,
/// Enter or Space presses it.
Card,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct RowActionAreas {
pub entry_idx: usize,
/// Discard / stage are painted on a selected *unstaged* row; `unstage`
/// on a selected *staged* row. The irrelevant rects are left default
/// (zero-size, so they never hit-test) for the row's section.
pub discard: Rect,
pub stage: Rect,
pub unstage: Rect,
}
pub struct SourceControlPanel {
pub message: String,
pub message_cursor: usize,
/// Leading characters scrolled out of view on the left of the
/// commit-message input so the caret stays visible when the message is
/// wider than the box. Recomputed every render from the cursor and the
/// box width.
pub message_scroll: usize,
/// Message lines scrolled out of view above the commit-message input
/// once the message has more lines than the box shows. Recomputed every
/// render, like `message_scroll`, to keep the caret's line visible.
pub message_line_scroll: usize,
pub status: GitStatus,
/// Git has answered for the folder shown (#871). Until it has, `status`
/// is a default that reads as "no repository", so the keys stay with the
/// message box as before rather than going to the card, where Enter
/// would run `git init`.
pub status_known: bool,
/// The prepared merge message last put in the box (#1282), whole
/// (#1336), to tell an untouched seed from the user's own text.
seeded_message: Option<String>,
pub entries: Vec<ChangeEntry>,
/// The multi-root repositories overview (#161), pushed by the App per
/// frame from its per-folder git workers. Length below two hides the
/// section (single-folder panels render exactly as before).
pub repositories: Vec<RepoRow>,
/// Frame-truth hit rects for the overview rows (cleared and
/// re-recorded every render, #103): click switches the panel to that
/// repository.
pub repo_row_areas: Vec<(Rect, std::path::PathBuf)>,
pub last_area: Rect,
pub last_inner: Rect,
pub last_input_area: Rect,
pub last_button_area: Rect,
/// Hit-test rect for the chevron split-button that opens the Commit
/// dropdown (Commit & Push, Push, View …). Empty when the panel is in
/// the no-repo state or the button row was clipped.
pub last_commit_caret_area: Rect,
pub last_list_area: Rect,
pub last_scrollbar: Rect,
/// Hit-test rect for the empty-state "Initialize Repository" button.
/// Empty when the panel is in a git repo or when the panel is too
/// small to draw the empty-state card.
pub last_init_repo_button_area: Rect,
/// Repositories in the workspace's immediate subfolders, as (label,
/// absolute path), set by `App` while the workspace itself is in no
/// repo (#1227). Non-empty, the empty-state card lists them with an
/// Open button each in place of Initialize.
pub nested_repos: Vec<(String, std::path::PathBuf)>,
/// Hit-test rects for those Open buttons; empty whenever none paint.
pub nested_repo_button_areas: Vec<(Rect, std::path::PathBuf)>,
/// Cell rect reserved for the no-repo empty-state hero illustration.
/// `App` paints an OSC-1337 inline PNG here on iTerm2-class terminals;
/// the widget paints an ASCII Y-fork as fallback so the same rect
/// reads as a logo on plain terminals too. Empty when the panel is
/// in a git repo or the empty-state card is too small to allocate.
pub last_hero_area: Rect,
/// Set by `App` after probing the host terminal for OSC-1337 inline
/// image support. When true, the empty-state render leaves the hero
/// rect blank so the PNG owns those cells without competing with an
/// ASCII fallback that would briefly flash through during resize.
pub inline_hero_image_active: bool,
pub scroll: usize,
/// Index into `entries` of the currently-selected change, if any.
/// Drives the row-highlight bg so the user can tell at a glance
/// which entry the editor is showing the diff for.
pub selected_change: Option<usize>,
/// Indices of all rows currently selected (multi-select). Always
/// includes `selected_change` when that is `Some`. Cmd+A populates this
/// with every entry; a plain click resets it to the single clicked row.
/// The Stage shortcut (Cmd+S) acts on this set; click on an action icon
/// still acts on just that row.
pub multi_selection: BTreeSet<usize>,
/// Which of the view's Tab stops has the keys (#871): one at a time,
/// so only one of them ever draws as focused.
pub keys: KeyStop,
/// The REPOSITORIES row the keyboard is on while that section has the
/// keys (#871).
pub repo_cursor: usize,
/// The no-repository card's button the keyboard is on (#871), counted
/// down the card.
pub card_button: usize,
/// Status / error line painted below the button after a commit attempt.
/// Cleared on the next refresh.
pub commit_feedback: Option<String>,
pub commit_feedback_is_error: bool,
/// Hit-test rects for the inline action icons (Discard, Stage) painted
/// on the selected unstaged row. `None` when no row is selected or the
/// selected row is already staged. Cleared at the top of each render
/// and re-populated for the visible selected row.
pub last_row_actions: Option<RowActionAreas>,
/// Hit-test rect for the refresh pill at the right of the SOURCE CONTROL
/// header row, mirroring the Remote Explorer refresh affordance. Clicking
/// it forces an immediate, un-debounced git re-scan. Empty when the panel
/// is in the no-repo state or the header row was clipped.
pub header_refresh_btn: Rect,
/// Hit-test rect for the branch name on the branch row. Clicking it
/// opens the Checkout / Create Branch picker, mirroring VS Code's
/// clickable status-bar branch indicator. Empty in the no-repo state.
pub last_branch_area: Rect,
/// Hit-test rect for the "⋯" actions pill in the header (left of the
/// refresh pill). Opens the full Source Control actions menu. Empty in
/// the no-repo state or when the header row is too narrow.
pub header_more_btn: Rect,
}
impl SourceControlPanel {
pub fn new() -> Self {
Self {
message: String::new(),
message_cursor: 0,
message_scroll: 0,
message_line_scroll: 0,
status: GitStatus::default(),
status_known: false,
seeded_message: None,
entries: Vec::new(),
repositories: Vec::new(),
repo_row_areas: Vec::new(),
last_area: Rect::default(),
last_inner: Rect::default(),
last_input_area: Rect::default(),
last_button_area: Rect::default(),
last_commit_caret_area: Rect::default(),
last_list_area: Rect::default(),
last_scrollbar: Rect::default(),
last_init_repo_button_area: Rect::default(),
nested_repos: Vec::new(),
nested_repo_button_areas: Vec::new(),
last_hero_area: Rect::default(),
inline_hero_image_active: false,
scroll: 0,
selected_change: None,
multi_selection: BTreeSet::new(),
keys: KeyStop::Message,
repo_cursor: 0,
card_button: 0,
commit_feedback: None,
commit_feedback_is_error: false,
last_row_actions: None,
header_refresh_btn: Rect::default(),
last_branch_area: Rect::default(),
header_more_btn: Rect::default(),
}
}
}
impl Default for SourceControlPanel {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests;