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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
//! Bottom strip: key hints, or a footer alert in place when one is active.
use ratatui::Frame;
use ratatui::layout::{Alignment, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::Paragraph;
use super::super::app::{
App, ConfigFocus, ConfigRow, FallbackHint, FooterAlert, GLOBAL_CONFIG_ROWS, GlobalConfigRow,
LoginSession, PluginFocus, StatusFocus, Tab, TokenView, config_rows, fallback_hint,
has_sub_focus,
};
use super::super::theme;
use super::format::spinner_frame;
const TAB_NAV: (&str, &str) = ("←→", "tabs");
pub(super) fn draw(frame: &mut Frame<'_>, area: Rect, app: &App) {
// 1-col breathing room on each side; the alert row (which replaces this in
// place) shares the same inset so the left margin never jumps.
let area = inset_x(area, 1);
// A login in flight owns the footer, independent of `footer_alert` so key
// handling that clears alerts can't hide it.
if let Some(session) = &app.login {
// Any open modal owns esc/q (the login modal collapses, others handle
// their own keys), so the hint flips to `q back` for the whole stack.
let modal_open = !app.modals.is_empty();
draw_login(frame, area, session, modal_open, app.tick_count);
return;
}
// A live alert replaces the hint bar in place — one footer row, never stacked.
if let Some(alert) = &app.footer_alert {
draw_alert(frame, area, alert);
return;
}
// `q` label: "back" in a sub-focus, "quit" at top level.
// (While armed the alert row shows instead, so this label stays "quit".)
let q_label: &str = if has_sub_focus(app) { "back" } else { "quit" };
let tail: &[(&str, &str)] = match app.tab {
Tab::Overview => &[("⇧↑↓", "reorder"), ("a", "actions"), ("?", "help")],
Tab::Usage => &[
("↑↓", "account"),
("r", "refresh account"),
("a", "actions"),
("?", "help"),
],
Tab::Tokens => match app.token_view {
TokenView::Dashboard => &[
("↵", "models"),
("r", "reload"),
("c", "count cache"),
("a", "actions"),
("?", "help"),
],
TokenView::Models => &[
("↑↓", "model"),
("c", "count cache"),
("a", "actions"),
("?", "help"),
],
},
Tab::Setup => match app.config_focus {
ConfigFocus::Profiles => &[
("↑↓", "account"),
("↵", "configure"),
("n", "new"),
("a", "actions"),
("?", "help"),
],
ConfigFocus::Actions => {
// Row-aware: the `model` row cycles on space; env rows edit a value
// or open the add-env key editor.
match config_rows(app).get(app.config_action_cursor) {
Some(ConfigRow::Model) => &[
("↑↓", "row"),
("space", "cycle"),
("↵", "custom"),
("a", "actions"),
("?", "help"),
],
Some(ConfigRow::EnvEntry(_)) => &[
("↑↓", "row"),
("↵", "edit value"),
("a", "actions"),
("?", "help"),
],
Some(ConfigRow::EnvAdd) => &[
("↑↓", "row"),
("↵", "add env"),
("a", "actions"),
("?", "help"),
],
// The reveal chip has no `a` actions, so it isn't advertised.
Some(ConfigRow::ModelOverrideAdd) => {
&[("↑↓", "row"), ("↵", "add override"), ("?", "help")]
}
_ => &[
("↑↓", "row"),
("↵", "edit / toggle"),
("a", "actions"),
("?", "help"),
],
}
}
},
Tab::Config => {
if app.refresh_interval_draft.is_some() {
&[("↵", "save"), ("←→", "caret"), ("esc", "cancel")]
} else if GLOBAL_CONFIG_ROWS
.get(app.global_config_cursor)
.is_some_and(|r| *r == GlobalConfigRow::RefreshInterval)
{
&[
("↑↓", "row"),
("space", "cycle"),
("↵", "custom"),
("?", "help"),
]
} else {
&[("↑↓", "row"), ("space/↵", "cycle / toggle"), ("?", "help")]
}
}
Tab::Status => match app.status.focus {
StatusFocus::List => &[
("↑↓", "incident"),
("↵", "open"),
("r", "refresh"),
("a", "actions"),
("?", "help"),
],
StatusFocus::Detail => &[("↑↓", "scroll"), ("a", "actions"), ("?", "help")],
},
Tab::Plugin => {
// `f` only fixes a row that actually offers one — don't advertise it as a
// hint on rows where pressing it is a no-op.
match (app.plugin.focus, app.plugin.selected_fix().is_some()) {
(PluginFocus::List, true) => &[
("↑↓", "row"),
("↵", "detail"),
("r", "refresh"),
("f", "fix"),
("?", "help"),
],
(PluginFocus::List, false) => &[
("↑↓", "row"),
("↵", "detail"),
("r", "refresh"),
("?", "help"),
],
(PluginFocus::Detail, true) => &[
("↑↓", "scroll"),
("r", "refresh"),
("f", "fix"),
("?", "help"),
],
(PluginFocus::Detail, false) => {
&[("↑↓", "scroll"), ("r", "refresh"), ("?", "help")]
}
}
}
Tab::Fallback => match fallback_hint(app) {
FallbackHint::Empty => &[("?", "help")],
FallbackHint::ChainMember => &[
("↑↓", "move"),
("⇧↑↓", "reorder"),
("↵", "open"),
("a", "actions"),
("?", "help"),
],
FallbackHint::ChainAdd => &[("↑↓", "move"), ("↵", "add"), ("?", "help")],
FallbackHint::DetailThreshold => &[
("↑↓", "row"),
("+", "raise"),
("-", "lower"),
("↵", "type"),
("a", "actions"),
("?", "help"),
],
FallbackHint::DetailThresholdEdit => {
&[("↵", "save"), ("←→", "caret"), ("esc", "cancel")]
}
FallbackHint::DetailLastResort => &[
("↑↓", "row"),
("space/↵", "toggle"),
("a", "actions"),
("?", "help"),
],
FallbackHint::DetailRemove => &[
("↑↓", "row"),
("↵", "remove"),
("a", "actions"),
("?", "help"),
],
FallbackHint::DetailRemoveArmed => {
&[("↵", "confirm remove"), ("esc", "cancel"), ("?", "help")]
}
FallbackHint::DetailAdd => &[("↑↓", "pick"), ("↵", "add"), ("?", "help")],
},
};
// Suppress the trailing `q` hint only where `q` is fully captured by the
// screen (threshold edit / armed-remove / refresh-interval edit own the
// keyboard entirely). Every other sub-focus shows `q back` via `q_label`
// per the cloudy-tui contract.
let show_q = !((app.tab == Tab::Fallback
&& matches!(
fallback_hint(app),
FallbackHint::DetailThresholdEdit | FallbackHint::DetailRemoveArmed
))
|| (app.tab == Tab::Config && app.refresh_interval_draft.is_some()));
let mut hints: Vec<(&str, &str)> = std::iter::once(TAB_NAV)
.chain(tail.iter().copied())
.collect();
if show_q {
hints.push(("q", q_label));
}
let mut spans: Vec<Span<'_>> = Vec::new();
for (i, (key, label)) in hints.iter().enumerate() {
if i > 0 {
spans.push(Span::styled(" ", theme::faint()));
}
spans.push(Span::styled(
*key,
theme::accent().add_modifier(Modifier::BOLD),
));
spans.push(Span::raw(" "));
spans.push(Span::styled(*label, theme::dim()));
}
frame.render_widget(
Paragraph::new(Line::from(spans))
.style(theme::base())
.alignment(Alignment::Left),
area,
);
}
/// Shrink a rect by `pad` columns on each side (clamped), leaving the row intact.
fn inset_x(area: Rect, pad: u16) -> Rect {
Rect {
x: area.x.saturating_add(pad),
width: area.width.saturating_sub(pad.saturating_mul(2)),
..area
}
}
/// Render a footer alert in place of the hint bar.
/// `! <message>` — glyph in `WARNING`, message in `TEXT_DIM`.
fn draw_alert(frame: &mut Frame<'_>, area: Rect, alert: &FooterAlert) {
let FooterAlert::Warn(msg) = alert;
let spans = vec![
Span::styled("! ", Style::default().fg(theme::warning_color())),
Span::styled(msg.as_str(), theme::dim()),
];
frame.render_widget(
Paragraph::new(Line::from(spans))
.style(theme::base())
.alignment(Alignment::Left),
area,
);
}
/// Login-in-progress line. Independent of `footer_alert` so key handling that
/// clears alerts never hides it. The authorize URL and live stage render in
/// the login modal; this row is the collapsed view. The trailing hint tracks
/// what esc/q actually do this frame: with any modal open they go to the
/// modal (`q back`); collapsed, both cancel the login (`esc cancel`).
fn draw_login(
frame: &mut Frame<'_>,
area: Rect,
session: &LoginSession,
modal_open: bool,
tick: u64,
) {
let (key, action) = if modal_open {
(" q ", "back")
} else {
(" esc ", "cancel")
};
let spans = vec![
Span::styled(format!("{} ", spinner_frame(tick)), theme::accent()),
Span::styled(
format!(
"logging in '{}' — complete it in your browser",
session.name
),
theme::dim(),
),
Span::styled(key, theme::accent().add_modifier(Modifier::BOLD)),
Span::styled(action, theme::dim()),
];
frame.render_widget(
Paragraph::new(Line::from(spans))
.style(theme::base())
.alignment(Alignment::Left),
area,
);
}