clauth 0.9.0

Manage multiple Claude Code accounts, monitor 5h/7d usage with configurable auto-switch and delegation with an MCP plugin. CLI + TUI.
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
//! Modal dialogs — stacking layer above the screen.

use ratatui::Frame;
use ratatui::layout::{Alignment, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::symbols::border;
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Clear, Padding, Paragraph};

use crate::profile::DivergenceChoice;

use super::super::app::{
    ActionMenuState, App, ConfirmAction, ConfirmState, DivergenceForm, DivergenceTargetForm,
    EnvCollisionChoice, EnvCollisionForm, InputState, LoginStage, Modal, Tab,
};
use super::super::theme;
use super::format::spinner_frame;
use super::panes::{bold_when, head_cols};

pub(super) fn draw(frame: &mut Frame<'_>, area: Rect, app: &App, modal: &Modal) {
    match modal {
        Modal::Confirm(state) => draw_confirm(frame, area, state),
        Modal::Divergence(form) => draw_divergence(frame, area, form),
        Modal::CaptureName(form) => draw_capture_name(frame, area, &form.input),
        Modal::DivergenceTarget(form) => draw_divergence_target(frame, area, form),
        Modal::Help => draw_help(frame, area, app),
        Modal::ActionMenu(state) => draw_action_menu(frame, area, state),
        Modal::EnvCollision(form) => draw_env_collision(frame, area, form),
        Modal::Login => draw_login_progress(frame, area, app),
    }
}

/// In-flight login progress. Renders live from `App::login` (the URL and the
/// stage land async), so the modal variant carries no state of its own. The
/// browser opens on its own; the modal offers an `r` retry instead of a
/// pasteable URL, since a wrapped ~440-char authorize link isn't clickable and
/// clips in compact mode. A headless host uses `clauth login` (CLI) instead.
fn draw_login_progress(frame: &mut Frame<'_>, area: Rect, app: &App) {
    let Some(session) = app.login.as_ref() else {
        return; // login ended this frame; the modal pops on the next drain
    };
    let stage = match session.stage {
        LoginStage::WaitingBrowser => "waiting for the browser login",
        LoginStage::ExchangingCode => "exchanging the code for tokens",
        LoginStage::Verifying => "verifying the minted token",
    };
    let mut lines: Vec<Line<'_>> = vec![
        Line::from(Span::styled(
            format!("logging in '{}'", session.name),
            theme::body(),
        )),
        Line::from(""),
        Line::from(vec![
            Span::styled(
                format!("{} ", spinner_frame(app.tick_count)),
                theme::accent(),
            ),
            Span::styled(stage, theme::dim()),
        ]),
        Line::from(""),
    ];
    match session.url {
        // The URL is known once the worker announced it, so the retry is live.
        Some(_) => {
            lines.push(Line::from(Span::styled(
                "complete the login in your browser",
                theme::dim(),
            )));
            lines.push(Line::from(""));
            lines.push(Line::from(vec![
                Span::styled("r", theme::accent().add_modifier(Modifier::BOLD)),
                Span::styled("  open the browser again", theme::dim()),
            ]));
        }
        None => lines.push(Line::from(Span::styled(
            "opening your browser…",
            theme::dim(),
        ))),
    }
    draw_modal(frame, area, "LOGIN", lines);
}

fn centered(area: Rect, width: u16, height: u16) -> Rect {
    let w = width.min(area.width.saturating_sub(4));
    let h = height.min(area.height.saturating_sub(4));
    Rect {
        x: area.x + (area.width.saturating_sub(w)) / 2,
        y: area.y + (area.height.saturating_sub(h)) / 2,
        width: w,
        height: h,
    }
}

/// Modal sized to content: snaps to widest line/title, exact line count.
/// Chrome = rounded border (1) + `Padding::new(2,2,1,1)` = 6 cols, 4 rows.
fn draw_modal(frame: &mut Frame<'_>, area: Rect, title: &str, lines: Vec<Line<'_>>) {
    let content_w = lines.iter().map(Line::width).max().unwrap_or(0) as u16;
    let w = (content_w + 6)
        .max(title.chars().count() as u16 + 4)
        .min(area.width.saturating_sub(4));
    let h = (lines.len() as u16 + 4).min(area.height.saturating_sub(4));

    let rect = centered(area, w, h);
    frame.render_widget(Clear, rect);
    let block = modal_block(title);
    let inner = block.inner(rect);
    frame.render_widget(block, rect);
    frame.render_widget(Paragraph::new(lines).style(theme::base()), inner);
}

/// Rounded `ACCENT_2` border, uppercase italic dim title, base `BG` fill.
fn modal_block(title: impl Into<String>) -> Block<'static> {
    let title_line = Line::from(vec![
        Span::raw(" "),
        Span::styled(
            title.into().to_uppercase(),
            Style::default()
                .fg(theme::text_dim_color())
                .add_modifier(Modifier::ITALIC),
        ),
        Span::raw(" "),
    ]);
    Block::default()
        .borders(Borders::ALL)
        .border_set(border::ROUNDED)
        .border_style(Style::default().fg(theme::accent_2_color()))
        .title(title_line)
        .style(theme::base())
        .padding(Padding::new(2, 2, 1, 1))
}

fn draw_confirm(frame: &mut Frame<'_>, area: Rect, state: &ConfirmState) {
    let title = match state.on_confirm {
        ConfirmAction::CaptureConflict(..) => "CONFIRM",
        ConfirmAction::CaptureOverwrite(..) => "CONFIRM",
        ConfirmAction::AdoptDivergence(..) => "CONFIRM",
        ConfirmAction::Switch(_) => "CONFIRM",
        ConfirmAction::DiscardDivergence(_) => "CONFIRM",
        ConfirmAction::RotateAll => "CONFIRM",
        ConfirmAction::RotateOne(_) => "CONFIRM",
        ConfirmAction::WireMcpServers => "CONFIRM",
        ConfirmAction::RelinkCredentials(_) => "CONFIRM",
        ConfirmAction::BlankCredentials(_) => "CONFIRM",
        ConfirmAction::RestartLogin(..) => "CONFIRM",
    };

    // Destructive/global ops carry a DANGER cue on their confirm button.
    // `CaptureOverwrite` replaces an existing profile's credentials in
    // place — irreversible like the other destructive actions here.
    let destructive = matches!(
        state.on_confirm,
        ConfirmAction::Switch(_)
            | ConfirmAction::RotateAll
            | ConfirmAction::RotateOne(_)
            | ConfirmAction::CaptureOverwrite(..)
            | ConfirmAction::AdoptDivergence(..)
            | ConfirmAction::BlankCredentials(_)
    );

    let mut lines: Vec<Line<'_>> = vec![Line::from(Span::styled(
        state.message.clone(),
        theme::body(),
    ))];
    if let Some(detail) = &state.detail {
        lines.push(Line::from(Span::styled(detail.clone(), theme::dim())));
    }
    lines.push(Line::from(""));
    lines.push(choice_buttons(state.choice, destructive).alignment(Alignment::Right));

    draw_modal(frame, area, title, lines);
}

fn choice_buttons(choice: bool, destructive_confirm: bool) -> Line<'static> {
    Line::from(vec![
        modal_button(" cancel ", !choice),
        Span::raw("   "),
        if destructive_confirm {
            danger_button(" confirm ", choice)
        } else {
            modal_button(" confirm ", choice)
        },
    ])
}

fn modal_button(label: &str, focused: bool) -> Span<'static> {
    if focused {
        Span::styled(
            label.to_string(),
            Style::default().fg(theme::bg()).bg(theme::text_color()),
        )
    } else {
        Span::styled(label.to_string(), theme::dim())
    }
}

/// Destructive variant of `modal_button`: DANGER fg unfocused, inverse DANGER block
/// focused. Same bar-less house style as `modal_button` (no `▐`/`▌`).
fn danger_button(label: &str, focused: bool) -> Span<'static> {
    if focused {
        Span::styled(
            label.to_string(),
            Style::default().fg(theme::bg()).bg(theme::danger_color()),
        )
    } else {
        Span::styled(label.to_string(), theme::danger())
    }
}

fn draw_divergence(frame: &mut Frame<'_>, area: Rect, form: &DivergenceForm) {
    let options = DivergenceForm::options();
    let cursor = form.cursor.min(options.len() - 1);

    let mut lines: Vec<Line<'_>> = vec![
        Line::from(vec![
            Span::styled("the live login no longer matches ", theme::dim()),
            Span::styled(
                format!("'{}'", form.active),
                Style::default().fg(theme::accent_color()),
            ),
            Span::styled(".", theme::dim()),
        ]),
        Line::from(""),
    ];

    for (i, option) in options.iter().enumerate() {
        let selected = i == cursor;
        lines.push(option_line(
            selected,
            divergence_option_text(*option, &form.active),
        ));
    }

    draw_modal(frame, area, "DIVERGENCE", lines);
}

fn divergence_option_text(option: DivergenceChoice, active: &str) -> String {
    match option {
        DivergenceChoice::Overwrite => format!("overwrite '{active}' with this login"),
        DivergenceChoice::NewProfile => "save this login to another profile…".to_string(),
        DivergenceChoice::Discard => format!("discard this login and restore '{active}'"),
    }
}

/// Arrow-selected menu row shared by the Divergence and target-picker modals:
/// `❯ ` accent when selected, two-space indent + dim otherwise.
fn option_line(selected: bool, label: String) -> Line<'static> {
    let arrow = if selected {
        Span::styled("\u{276f} ", theme::accent())
    } else {
        Span::raw("  ")
    };
    let style = if selected {
        theme::accent()
    } else {
        theme::dim()
    };
    Line::from(vec![arrow, Span::styled(label, style)])
}

fn draw_divergence_target(frame: &mut Frame<'_>, area: Rect, form: &DivergenceTargetForm) {
    let cursor = form.cursor.min(form.targets.len());

    let mut lines: Vec<Line<'_>> = vec![
        Line::from(Span::styled("where to save the login?", theme::dim())),
        Line::from(""),
        option_line(cursor == 0, "+ new profile".to_string()),
    ];
    for (i, name) in form.targets.iter().enumerate() {
        lines.push(option_line(cursor == i + 1, format!("overwrite '{name}'")));
    }

    draw_modal(frame, area, "SAVE LOGIN", lines);
}

fn draw_env_collision(frame: &mut Frame<'_>, area: Rect, form: &EnvCollisionForm) {
    let options = EnvCollisionForm::options();
    let cursor = form.cursor.min(options.len() - 1);

    let mut lines: Vec<Line<'_>> = vec![
        Line::from(vec![
            Span::styled(
                format!("'{}'", form.key),
                Style::default().fg(theme::accent_color()),
            ),
            Span::styled(" is already used by ", theme::dim()),
            Span::styled(form.reason.clone(), theme::body()),
            Span::styled(".", theme::dim()),
        ]),
        Line::from(""),
    ];

    for (i, option) in options.iter().enumerate() {
        let selected = i == cursor;
        let arrow = if selected {
            Span::styled("\u{276f} ", theme::accent())
        } else {
            Span::raw("  ")
        };
        let (label, detail) = env_collision_option_text(*option, form);
        let label_style = if selected {
            theme::accent()
        } else {
            theme::dim()
        };
        lines.push(Line::from(vec![arrow, Span::styled(label, label_style)]));
        lines.push(Line::from(vec![
            Span::raw("    "),
            Span::styled(detail, theme::dim()),
        ]));
    }

    draw_modal(frame, area, "KEY IN USE", lines);
}

fn env_collision_option_text(
    choice: EnvCollisionChoice,
    form: &EnvCollisionForm,
) -> (String, String) {
    match choice {
        EnvCollisionChoice::Overwrite => (
            "add the custom field anyway".to_string(),
            format!("this account's value overrides {}", form.reason),
        ),
        EnvCollisionChoice::KeepExisting => (
            "keep the existing value".to_string(),
            if form.existing_idx.is_some() {
                "jump to the existing custom field".to_string()
            } else {
                "leave it untouched; don't add the field".to_string()
            },
        ),
        EnvCollisionChoice::Cancel => ("cancel".to_string(), "back out, no change".to_string()),
    }
}

fn draw_capture_name(frame: &mut Frame<'_>, area: Rect, input: &InputState) {
    let lines = vec![
        Line::from(Span::styled(
            "stores the live ~/.claude/.credentials.json under this profile.",
            theme::dim(),
        )),
        Line::from(""),
        labelled_input("name", input, true),
    ];

    // Replicate draw_modal's geometry to place the native terminal cursor on the
    // input line (index 2 in the vec).  Chrome = border (1) + padding (2 left, 1 top).
    let title = "CAPTURE";
    let content_w = lines.iter().map(Line::width).max().unwrap_or(0) as u16;
    let w = (content_w + 6)
        .max(title.chars().count() as u16 + 4)
        .min(area.width.saturating_sub(4));
    let h = (lines.len() as u16 + 4).min(area.height.saturating_sub(4));
    let rect = {
        let cw = w.min(area.width.saturating_sub(4));
        let ch = h.min(area.height.saturating_sub(4));
        Rect {
            x: area.x + (area.width.saturating_sub(cw)) / 2,
            y: area.y + (area.height.saturating_sub(ch)) / 2,
            width: cw,
            height: ch,
        }
    };
    // inner = rect + border (1) + padding left/top (2, 1)
    let inner_x = rect.x.saturating_add(3);
    let inner_y = rect.y.saturating_add(2);

    draw_modal(frame, area, title, lines);

    // x = edit gutter "✎ " (2) + label "name" (4) + " " (1) + cols before caret
    let cx = inner_x.saturating_add(2 + 4 + 1 + head_cols(input) as u16);
    let cy = inner_y.saturating_add(2); // line index 2
    frame.set_cursor_position((cx, cy));
}

/// Per-tab rows for the KEYS help modal, beneath the shared `tabs`/`global`
/// sections. A standalone builder (not inlined into `draw_help`) so tests can
/// enumerate every tab's real content without rendering a frame — see
/// `every_sub_focus_tab_documents_esc_in_help`.
fn tab_specific_rows(tab: Tab) -> Vec<(&'static str, &'static [(&'static str, &'static str)])> {
    match tab {
        Tab::Overview => vec![(
            "accounts",
            &[
                ("\u{2191}\u{2193}", "move cursor"),
                ("\u{21b5}", "switch to selected account (confirm)"),
                ("shift \u{2191}\u{2193}", "reorder account up / down"),
            ][..],
        )],
        Tab::Usage => vec![(
            "usage",
            &[
                ("\u{2191}\u{2193}", "pick account to inspect"),
                ("r", "refresh account"),
                ("e", "toggle estimates"),
                ("p", "toggle pace marker"),
            ][..],
        )],
        Tab::Tokens => vec![(
            "tokens",
            &[
                ("\u{21b5}", "open per-model breakdown"),
                ("\u{2191}\u{2193}", "pick model (in breakdown)"),
                ("c", "count cache in token figures"),
                (
                    "t",
                    "cycle period \u{b7} lifetime / daily / weekly / monthly",
                ),
                ("r", "reload on-disk stats"),
                ("esc", "back to dashboard"),
            ][..],
        )],
        Tab::Setup => vec![(
            "setup",
            &[
                ("\u{2191}\u{2193}", "pick account / + new, then a row"),
                ("\u{21b5}", "open settings · edit field · flip toggle"),
                ("\u{21b5} on a field", "edit inline; \u{21b5} again saves"),
                ("space", "cycle the model preset (model row)"),
                ("env", "+ add env · \u{21b5} edits a value · a removes"),
                ("delete", "\u{21b5} once to arm, again to confirm"),
                ("esc", "stop editing / back to account list"),
            ][..],
        )],
        Tab::Config => vec![(
            "config",
            &[
                ("\u{2191}\u{2193}", "move between settings"),
                ("space", "cycle the focused setting"),
                (
                    "\u{21b5}",
                    "same as space · custom value on refresh interval",
                ),
            ][..],
        )],
        Tab::Status => vec![(
            "status",
            &[
                ("\u{2191}\u{2193}", "pick incident / scroll detail"),
                ("\u{21b5}", "open incident timeline"),
                ("r", "refresh the feed"),
                ("esc", "back to the list"),
            ][..],
        )],
        Tab::Plugin => vec![(
            "plugin",
            &[
                ("\u{2191}\u{2193}", "pick check · scroll detail"),
                ("\u{21b5}", "open the selected row's detail"),
                ("f", "apply the selected row's fix"),
                ("r", "re-run all checks"),
                ("esc", "back to the list"),
            ][..],
        )],
        Tab::Fallback => vec![(
            "fallback chain",
            &[
                ("\u{2191}\u{2193}", "move cursor / detail row"),
                ("shift \u{2191}\u{2193}", "reorder member = priority"),
                (
                    "\u{21b5}",
                    "open \u{00b7} edit threshold \u{00b7} toggle last resort \u{00b7} remove \u{00b7} add",
                ),
                ("+ / -", "step threshold by 5"),
                ("\u{21b5}", "type a threshold, \u{21b5} saves"),
                ("esc", "back / cancel edit"),
            ][..],
        )],
    }
}

fn draw_help(frame: &mut Frame<'_>, area: Rect, app: &App) {
    let title = "KEYS";

    let tab_specific = tab_specific_rows(app.tab);

    let nav: &[(&str, &str)] = &[(
        "\u{2190} \u{2192} \u{00b7} tab",
        "previous / next tab (shift tab: previous)",
    )];

    let global_all: &[(&str, &str)] = &[
        ("n", "new account"),
        ("r", "refresh usage now"),
        ("t", "rotate all tokens"),
        ("?", "toggle this help"),
        ("a", "actions"),
        ("x", "dismiss toast / alert"),
        ("q", "back / quit"),
        ("esc", "back within a sub-view (no-op at the top level)"),
        ("\u{2303}c", "quit from anywhere"),
    ];
    // A key the current tab redefines is documented in its own section above;
    // keeping the global sense too would contradict it (`t` cycles the period
    // and `r` reloads stats on Tokens, `r` refreshes one account on Usage).
    let shadowed: Vec<&str> = tab_specific
        .iter()
        .flat_map(|(_, rows)| rows.iter().map(|(k, _)| *k))
        .collect();
    let global: Vec<(&str, &str)> = global_all
        .iter()
        .copied()
        .filter(|(k, _)| !shadowed.contains(k))
        .collect();

    let mut lines: Vec<Line<'_>> = Vec::new();
    lines.extend(key_section("tabs", nav));
    for (section, entries) in &tab_specific {
        lines.extend(key_section(section, entries));
    }
    lines.extend(key_section("global", &global));
    lines.pop(); // trim trailing blank from last section
    draw_modal(frame, area, title, lines);
}

fn key_section(title: &str, pairs: &[(&str, &str)]) -> Vec<Line<'static>> {
    let mut lines = vec![
        Line::from(Span::styled(
            title.to_uppercase(),
            Style::default().fg(theme::text_dim_color()),
        )),
        Line::from(""),
    ];
    for (key, desc) in pairs {
        lines.push(help_row(key, desc));
    }
    lines.push(Line::from(""));
    lines
}

fn help_row(key: &str, desc: &str) -> Line<'static> {
    // Always leave at least 1 space — `{:<18}` emits no padding at the width.
    const KEY_W: usize = 18;
    let pad = KEY_W.saturating_sub(key.chars().count()).max(1);
    Line::from(vec![
        Span::styled(
            format!("  {key}{}", " ".repeat(pad)),
            Style::default().fg(theme::accent_color()).bold(),
        ),
        Span::styled(desc.to_string(), Style::default().fg(theme::text_color())),
    ])
}

fn labelled_input(label: &str, input: &InputState, focused: bool) -> Line<'static> {
    // When focused the native terminal cursor owns the caret — no block highlight.
    // Unfocused fields still render with plain text styling (no BG_SUNKEN tint).
    // A focused field carries the `✎` edit-mode gutter glyph (same as form rows);
    // the 2-col gutter is accounted for in the caller's cursor-x math.
    let value_style = if focused {
        Style::default()
            .fg(theme::text_color())
            .bg(theme::bg_sunken())
    } else {
        Style::default().fg(theme::text_color())
    };
    let gutter = if focused {
        Span::styled(format!("{} ", theme::edit_glyph()), theme::accent())
    } else {
        Span::raw("  ")
    };
    Line::from(vec![
        gutter,
        Span::styled(label.to_string(), theme::label()),
        Span::raw(" "),
        Span::styled(input.value.clone(), value_style),
    ])
}

fn draw_action_menu(frame: &mut Frame<'_>, area: Rect, state: &ActionMenuState) {
    const HOTKEY_W: u16 = 1; // 1 char for hotkey letter, or 1 space if none
    const GUTTER: u16 = 2; // "❯ " or "  "

    // Render rows with right-aligned hotkeys — can't use draw_modal because that
    // wraps all lines in one Paragraph, preventing per-row background tinting.
    // Custom draw: measure → size → clear → border → per-row widgets.
    let max_label_w = state
        .items
        .iter()
        .map(|item| item.label.chars().count())
        .max()
        .unwrap_or(0) as u16;
    let content_w = GUTTER + max_label_w + 3 + HOTKEY_W;
    let title = "actions";
    let w = (content_w + 6)
        .max(title.chars().count() as u16 + 4)
        .min(area.width.saturating_sub(4));
    // items rows + 4 chrome (border + padding)
    let h = (state.items.len() as u16 + 4).min(area.height.saturating_sub(4));

    let rect = centered(area, w, h);
    frame.render_widget(Clear, rect);
    let block = modal_block(title);
    let inner = block.inner(rect);
    frame.render_widget(block, rect);

    let inner_w = inner.width;
    for (i, item) in state.items.iter().enumerate() {
        let focused = i == state.cursor;
        let y = inner.y + i as u16;
        if y >= inner.y + inner.height {
            break;
        }
        let row_area = Rect {
            y,
            height: 1,
            ..inner
        };

        let label_style = bold_when(Style::default().fg(theme::text_color()), focused);
        let row_bg = if focused {
            Style::default().bg(theme::bg_hover())
        } else {
            theme::base()
        };
        let glyph = if focused {
            Span::styled("", Style::default().fg(theme::accent_color()).bold())
        } else {
            Span::styled("  ", Style::default())
        };
        let label_len = item.label.chars().count() as u16;
        let pad = inner_w
            .saturating_sub(GUTTER)
            .saturating_sub(label_len)
            .saturating_sub(HOTKEY_W);
        let padding = Span::styled(" ".repeat(pad as usize), Style::default());
        let hotkey_span = match item.hotkey {
            Some(c) => Span::styled(c.to_string(), Style::default().fg(theme::text_dim_color())),
            None => Span::styled(
                " ".to_string(),
                Style::default().fg(theme::text_dim_color()),
            ),
        };
        let line = Line::from(vec![
            glyph,
            Span::styled(item.label.to_string(), label_style),
            padding,
            hotkey_span,
        ])
        .style(row_bg);
        frame.render_widget(Paragraph::new(line).style(row_bg), row_area);
    }
}

#[cfg(test)]
#[path = "../../../tests/inline/tui_render_modals.rs"]
mod tests;