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
//! 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::trace;
use super::super::{App, provider_status};
use crate::action::Action;
use crate::components::clone_wizard::CloneWizard;
use crate::components::command_line::CommandLine;
use crate::components::keybinds_popup::KeybindsPopup;
use crate::components::settings_popup::SettingsPopup;
use crate::mode::Mode;
use crate::theme::BorderShape;
use crate::theme::Theme;
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 => {
trace("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(crate::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() {
let name = 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(&entry.name, "", "", 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
}
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
}
}