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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
//! Action dispatch — app lifecycle: quit, popups, command line, settings, the declared-provider consent answers, and the clone run
//! (moved from app/mod.rs, plans/0021 M1 — a pure move, zero behavior
//! change).
use super::super::{App, provider, provider_status};
use crate::action::Action;
use crate::components::clone_wizard::CloneWizard;
use crate::components::command_line::CommandLine;
use crate::components::consent_popup::ConsentPopup;
use crate::components::keybinds_popup::KeybindsPopup;
use crate::components::settings_popup::SettingsPopup;
use crate::mode::Mode;
use crate::theme::BorderShape;
use crate::theme::Theme;
use rootle_provider::RepoId;
impl App {
/// This domain's arms: `Some(action)` back when not ours, so the
/// next domain tries it; arm bodies are moved verbatim.
pub(crate) fn try_lifecycle(&mut self, action: Action) -> Option<Action> {
let _consumed: bool = match action {
Action::Quit | Action::LeaderQuit => {
self.state.last_path = Some(self.browser.dir_path());
self.state.save();
self.should_quit = true;
true
}
Action::ClosePopup => {
// Topmost overlay first; the search popup last.
if self.wizard.take().is_some()
|| self.settings.take().is_some()
|| self.help.take().is_some()
|| self.command_line.take().is_some()
{
return None;
}
if self.refs_popup.take().is_some() {
// Revisions switcher cancelled: the live preview
// reverts to the committed revision.
let baseline = self.refs_baseline.clone();
self.browser.set_current_ref(baseline);
return None;
}
self.popup = None;
self.mode = Mode::Browse;
true
}
Action::Leader => {
self.mode = Mode::Leader;
true
}
Action::KeybindsPopup => {
self.help = Some(KeybindsPopup::new());
true
}
Action::CommandLine => {
self.command_line = Some(CommandLine::new());
true
}
Action::RunCommand(name) => {
self.command_line = None;
match name.as_str() {
"settings" => {
let themes = Theme::available_names();
self.settings = Some(SettingsPopup::new(&self.config, themes));
}
"clone" => {
let (repos, orgs) = self.clone_candidates();
if orgs.is_empty() {
let cwd = std::env::current_dir().unwrap_or_default();
// Direct selections carry no listing
// metadata (v1.4): bare names.
let repos = repos
.into_iter()
.map(rootle_provider::RepoInfo::bare)
.collect();
self.wizard = Some(CloneWizard::new(repos, cwd));
} else {
self.status = Some(format!("expanding {} org(s)…", orgs.len()));
if !self.offline {
self.spawn_expand_clone(repos, orgs);
}
}
}
other => {
// `:42` jumps to line 42 in a file view — the
// zoomed preview submode or a search hit's
// expanded file pane (plans/0016 M1).
match other.parse::<u32>() {
Ok(line) if line > 0 => {
let jumped = if let Some(view) = &mut self.search_view {
view.expanded_goto_line(line)
} else if self.browser.preview.text_line_count() > 0 {
self.browser.preview.set_cursor_line(line);
true
} else {
false
};
if !jumped {
self.status = Some(format!(":{other}: not in a file view"));
}
}
_ => self.status = Some(format!("unknown command: {other}")),
}
}
}
true
}
Action::RunClone { repos, dest } => {
if repos.is_empty() {
self.status = Some("nothing selected to clone".into());
self.wizard = None;
} else {
let count = repos.len();
self.status = Some(format!("cloning {count} repos…"));
self.wizard = None;
if !self.offline {
self.spawn_clones(repos, dest);
}
}
true
}
Action::ApplySettings(config) => {
self.settings = None; // close the popup
let theme_changed = config.theme != self.config.theme;
let provider_changed = config.provider != self.config.provider;
let ui_changed = config.ui != self.config.ui;
self.config = config;
// Hot reload: rebuild the palette (and chrome prefs);
// every component reads Theme per render, so the
// repaint is automatic.
if theme_changed || ui_changed {
let name = self.config.theme.name.clone();
let border = BorderShape::parse(&self.config.ui.border).unwrap_or_default();
self.theme = Theme::load(&name)
.with_border(border)
.with_nerd_font(self.config.ui.nerd_font)
.with_separator(&self.config.ui.separator);
}
match self.config.save() {
Ok(()) => {
self.status = Some(if provider_changed {
"settings saved — provider applies after restart".into()
} else {
"settings saved".into()
})
}
Err(e) => self.status = Some(format!("settings: {e} (applied live)")),
}
true
}
Action::DeclarationDecline => {
if let Some(consent) = self.consent.take() {
// 0022: the health popup names its issue, the install
// popup its declaration — both decline to github.
let name = match consent.health_issue() {
Some(issue) => issue.name.clone(),
None => consent.declaration().name.clone(),
};
// Honest degraded mode: the fallback is named, the
// declaration stays in the config, the retry is a
// command away — and the notice is sticky.
let note = format!(
"{name} not installed — browsing github (retry: rootle provider install {name})"
);
self.degraded = Some(note.clone());
self.status = Some(note);
}
true
}
Action::DeclarationState(state) => {
if let Some(consent) = &mut self.consent {
consent.set_state(state);
}
true
}
Action::Noop => true,
// 0019 M2: the consent popup's answers.
// 0021 M3 hygiene: yank from the repo search popup — the
// selected entry's URL (org page or repo tree).
Action::SearchYank => {
if let Some(popup) = &self.popup
&& let Some(entry) = popup.selected_entry()
{
let url = match entry.kind {
crate::components::pane::EntryKind::Org => {
self.provider.org_url(&entry.name)
}
_ => self.provider.web_url(
&RepoId::from(entry.name.as_str()),
"",
None,
None,
None,
false,
),
};
match url {
Ok(u) => {
self.pending_clipboard = Some(u.clone());
self.status = Some(format!("yanked {u}"));
}
Err(e) => self.status = Some(provider_status(&e)),
}
}
true
}
// 0022 M2 health prompt: retry the spawn once — rebuild
// the provider; swap it in on success, show the error on
// failure (the popup stays up).
Action::DeclarationRetry => {
// 0030: the retry rebuild is a provider lifecycle
// event under a fresh operation id.
let op = rootle_trace::operation_id();
let (provider, outcome) = rootle_trace::in_operation(op, || {
rootle_trace::record_with(
rootle_trace::EventKind::ProviderLifecycle,
|| serde_json::json!({"stage": "rebuild"}),
);
let built = provider::build(&self.config);
rootle_trace::record_with(rootle_trace::EventKind::ProviderLifecycle, || {
serde_json::json!({
"stage": "rebuild",
"outcome": match &built.1 {
provider::BuildOutcome::Ready => "ready",
provider::BuildOutcome::Warn(_) => "warn",
provider::BuildOutcome::Health(_) => "health",
provider::BuildOutcome::Missing(_) => "missing",
},
})
});
built
});
match outcome {
provider::BuildOutcome::Ready | provider::BuildOutcome::Warn(_) => {
self.provider = provider;
self.consent = None;
self.degraded = None;
self.status = Some("provider back".into());
}
provider::BuildOutcome::Health(issue) => {
self.provider = provider;
if let Some(popup) = &mut self.consent {
popup.set_state(crate::action::DeclarationState::Failed(issue.error));
}
}
provider::BuildOutcome::Missing(decl) => {
self.provider = provider;
self.consent = Some(ConsentPopup::new(decl));
}
}
true
}
// 0022 M2 health prompt: open the config in the editor —
// main suspends the terminal for it (the same editor path
// as file opens).
Action::DeclarationEditConfig => {
self.consent = None;
match (
crate::editor::resolve_program(&self.config),
crate::config::Config::path(),
) {
(Some(program), Some(path)) => {
let mut args = crate::editor::build_args(&program, &self.config);
args.push(path.to_string_lossy().into_owned());
self.pending_editor = Some(crate::editor::EditorJob { program, args });
}
_ => {
self.status =
Some("no editor found — set [editor].program or $EDITOR".into())
}
}
true
}
Action::DeclarationAccept => {
if let Some(consent) = &mut self.consent {
let decl = consent.declaration().clone();
consent.set_state(crate::action::DeclarationState::Installing);
self.status = Some(format!("installing {}…", decl.name));
self.spawn_declared_install(decl);
}
true
}
_ => return Some(action),
};
debug_assert!(_consumed);
None
}
}