croft-software 0.1.701

VSCode-style TUI written in Rust
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
//! The Source Control "⋯" title menu: a VS Code-style actions menu with
//! one level of fly-out submenus (Commit ›, Changes ›, Branch ›, Stash ›,
//! …). Opened from the `⋯` pill in the SOURCE CONTROL header.
//!
//! The widget is a thin renderer over a static menu tree. It owns no git
//! state: every leaf is an [`ScmAction`] the App dispatches in
//! `dispatch_scm_action`, and the open/expanded state plus hit-test rects
//! live in [`ScmMenuState`] (held by the App, mirroring how the commit
//! dropdown stores its rects on the panel).

use ratatui::{
    buffer::Buffer,
    layout::Rect,
    style::{Color, Style},
    widgets::{Clear, Widget},
};

/// Every leaf action reachable from the SCM "⋯" menu. The App maps each to
/// a handler (some fire immediately, some open an input modal or picker).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ScmAction {
    // Top-level leaves.
    Pull,
    Push,
    Clone,
    CheckoutTo,
    Fetch,
    ShowGitOutput,
    // Commit submenu.
    Commit,
    CommitStaged,
    CommitAll,
    CommitAmend,
    CommitAndPush,
    CommitAndSync,
    // Changes submenu.
    StageAll,
    UnstageAll,
    DiscardAll,
    // Pull, Push submenu.
    Sync,
    PullRebase,
    PushTo,
    PushForce,
    PublishBranch,
    // Branch submenu.
    CreateBranch,
    CreateBranchFrom,
    RenameBranch,
    DeleteBranch,
    Merge,
    Rebase,
    // Remote submenu.
    AddRemote,
    RemoveRemote,
    // Stash submenu.
    Stash,
    StashIncludeUntracked,
    StashStaged,
    ApplyStash,
    PopStashLatest,
    PopStashPick,
    DropStash,
    // Tags submenu.
    CreateTag,
    DeleteTag,
}

/// A leaf row: the action it fires, its label, and its codicon glyph.
#[derive(Clone, Copy, Debug)]
pub struct Leaf {
    pub action: ScmAction,
    pub label: &'static str,
    pub icon: char,
}

const fn leaf(action: ScmAction, label: &'static str, icon: char) -> Leaf {
    Leaf {
        action,
        label,
        icon,
    }
}

/// A top-level row: either a leaf, a separator, or a submenu (label + icon
/// + its leaf children).
pub enum Node {
    Item(Leaf),
    Sep,
    Sub {
        label: &'static str,
        icon: char,
        items: &'static [Leaf],
    },
}

// Codicon glyphs (Nerd Fonts `cod-*` PUA, verified against
// ryanoasis/nerd-fonts glyphnames.json v3.4.0 on 2026-06-19).
const ICON_CLOUD_DOWNLOAD: char = '\u{eac2}'; // pull
const ICON_CLOUD_UPLOAD: char = '\u{eac3}'; // push
const ICON_REPO_CLONE: char = '\u{eb3e}'; // clone
const ICON_GIT_BRANCH: char = '\u{ea96}'; // checkout / branch
const ICON_GIT_FETCH: char = '\u{ec1d}'; // fetch
const ICON_OUTPUT: char = '\u{eb9d}'; // show git output
const ICON_CHECK: char = '\u{eab2}'; // commit
const ICON_SYNC: char = '\u{ea77}'; // sync
const ICON_ADD: char = '\u{ea60}'; // add / stage
const ICON_REMOVE: char = '\u{eb3b}'; // unstage
const ICON_DISCARD: char = '\u{eae2}'; // discard
const ICON_ARROW_UP: char = '\u{eaa1}'; // push variants
const ICON_EDIT: char = '\u{ea73}'; // rename
const ICON_TRASH: char = '\u{ea81}'; // delete
const ICON_GIT_MERGE: char = '\u{eafe}'; // merge
const ICON_GIT_PR: char = '\u{ea64}'; // rebase
const ICON_BROADCAST: char = '\u{eaad}'; // remote
const ICON_ARCHIVE: char = '\u{ea98}'; // stash
const ICON_TAG: char = '\u{ea66}'; // tags
const ICON_NEW_FOLDER: char = '\u{ea80}'; // create from

/// The codicon painted on the `⋯` header pill that opens this menu.
pub const ICON_ELLIPSIS: char = '\u{ea7c}';

const COMMIT_ITEMS: &[Leaf] = &[
    leaf(ScmAction::Commit, "Commit", ICON_CHECK),
    leaf(ScmAction::CommitStaged, "Commit Staged", ICON_CHECK),
    leaf(ScmAction::CommitAll, "Commit All", ICON_CHECK),
    leaf(ScmAction::CommitAmend, "Commit (Amend)", ICON_EDIT),
    leaf(ScmAction::CommitAndPush, "Commit & Push", ICON_CLOUD_UPLOAD),
    leaf(ScmAction::CommitAndSync, "Commit & Sync", ICON_SYNC),
];

const CHANGES_ITEMS: &[Leaf] = &[
    leaf(ScmAction::StageAll, "Stage All Changes", ICON_ADD),
    leaf(ScmAction::UnstageAll, "Unstage All Changes", ICON_REMOVE),
    leaf(ScmAction::DiscardAll, "Discard All Changes", ICON_DISCARD),
];

const PULL_PUSH_ITEMS: &[Leaf] = &[
    leaf(ScmAction::Sync, "Sync", ICON_SYNC),
    leaf(ScmAction::PullRebase, "Pull (Rebase)", ICON_CLOUD_DOWNLOAD),
    leaf(ScmAction::PushTo, "Push to", ICON_ARROW_UP),
    leaf(ScmAction::PushForce, "Push (Force)", ICON_ARROW_UP),
    leaf(
        ScmAction::PublishBranch,
        "Publish Branch",
        ICON_CLOUD_UPLOAD,
    ),
];

const BRANCH_ITEMS: &[Leaf] = &[
    leaf(ScmAction::CreateBranch, "Create Branch", ICON_GIT_BRANCH),
    leaf(
        ScmAction::CreateBranchFrom,
        "Create Branch from",
        ICON_NEW_FOLDER,
    ),
    leaf(ScmAction::RenameBranch, "Rename Branch", ICON_EDIT),
    leaf(ScmAction::DeleteBranch, "Delete Branch", ICON_TRASH),
    leaf(ScmAction::Merge, "Merge", ICON_GIT_MERGE),
    leaf(ScmAction::Rebase, "Rebase", ICON_GIT_PR),
];

const REMOTE_ITEMS: &[Leaf] = &[
    leaf(ScmAction::AddRemote, "Add Remote", ICON_ADD),
    leaf(ScmAction::RemoveRemote, "Remove Remote", ICON_TRASH),
];

const STASH_ITEMS: &[Leaf] = &[
    leaf(ScmAction::Stash, "Stash", ICON_ARCHIVE),
    leaf(
        ScmAction::StashIncludeUntracked,
        "Stash (Include Untracked)",
        ICON_ARCHIVE,
    ),
    leaf(ScmAction::StashStaged, "Stash Staged", ICON_ARCHIVE),
    leaf(ScmAction::ApplyStash, "Apply Stash", ICON_ARCHIVE),
    leaf(ScmAction::PopStashLatest, "Pop Latest Stash", ICON_ARCHIVE),
    leaf(ScmAction::PopStashPick, "Pop Stash", ICON_ARCHIVE),
    leaf(ScmAction::DropStash, "Drop Stash", ICON_TRASH),
];

const TAGS_ITEMS: &[Leaf] = &[
    leaf(ScmAction::CreateTag, "Create Tag", ICON_TAG),
    leaf(ScmAction::DeleteTag, "Delete Tag", ICON_TRASH),
];

/// The full top-level menu, mirroring VS Code's SCM "⋯" menu order.
pub fn menu() -> Vec<Node> {
    vec![
        Node::Item(leaf(ScmAction::Pull, "Pull", ICON_CLOUD_DOWNLOAD)),
        Node::Item(leaf(ScmAction::Push, "Push", ICON_CLOUD_UPLOAD)),
        Node::Item(leaf(ScmAction::Clone, "Clone", ICON_REPO_CLONE)),
        Node::Item(leaf(ScmAction::CheckoutTo, "Checkout to", ICON_GIT_BRANCH)),
        Node::Item(leaf(ScmAction::Fetch, "Fetch", ICON_GIT_FETCH)),
        Node::Sep,
        Node::Sub {
            label: "Commit",
            icon: ICON_CHECK,
            items: COMMIT_ITEMS,
        },
        Node::Sub {
            label: "Changes",
            icon: ICON_ADD,
            items: CHANGES_ITEMS,
        },
        Node::Sub {
            label: "Pull, Push",
            icon: ICON_SYNC,
            items: PULL_PUSH_ITEMS,
        },
        Node::Sub {
            label: "Branch",
            icon: ICON_GIT_BRANCH,
            items: BRANCH_ITEMS,
        },
        Node::Sub {
            label: "Remote",
            icon: ICON_BROADCAST,
            items: REMOTE_ITEMS,
        },
        Node::Sub {
            label: "Stash",
            icon: ICON_ARCHIVE,
            items: STASH_ITEMS,
        },
        Node::Sub {
            label: "Tags",
            icon: ICON_TAG,
            items: TAGS_ITEMS,
        },
        Node::Sep,
        Node::Item(leaf(
            ScmAction::ShowGitOutput,
            "Show Git Output",
            ICON_OUTPUT,
        )),
    ]
}

/// What a click on a top-level row resolves to.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TopHit {
    /// A leaf row: fire this action and close.
    Action(ScmAction),
    /// A submenu row: toggle its fly-out (this is its top-level index).
    Expand(usize),
}

/// Open/closed + expansion state and the hit-test rects, owned by the App.
#[derive(Default)]
pub struct ScmMenuState {
    pub open: bool,
    /// Index (into `menu()`) of the submenu whose fly-out is showing.
    pub expanded: Option<usize>,
    pub top_hits: Vec<(Rect, TopHit)>,
    pub sub_hits: Vec<(Rect, ScmAction)>,
}

impl ScmMenuState {
    pub fn close(&mut self) {
        self.open = false;
        self.expanded = None;
        self.top_hits.clear();
        self.sub_hits.clear();
    }

    /// Resolve a click at (x, y) to a menu outcome, mutating expansion
    /// state for submenu toggles. Returns `Some(action)` only when a leaf
    /// fired (the caller then dispatches and closes). Returns `None` for a
    /// submenu toggle (menu stays open) or a miss.
    pub fn click(&mut self, x: u16, y: u16) -> ClickOutcome {
        for (rect, action) in &self.sub_hits {
            if hit(*rect, x, y) {
                return ClickOutcome::Fire(*action);
            }
        }
        for (rect, top) in &self.top_hits {
            if hit(*rect, x, y) {
                return match top {
                    TopHit::Action(a) => ClickOutcome::Fire(*a),
                    TopHit::Expand(i) => {
                        self.expanded = if self.expanded == Some(*i) {
                            None
                        } else {
                            Some(*i)
                        };
                        ClickOutcome::Toggled
                    }
                };
            }
        }
        ClickOutcome::Missed
    }
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ClickOutcome {
    Fire(ScmAction),
    Toggled,
    Missed,
}

fn hit(rect: Rect, x: u16, y: u16) -> bool {
    rect.width > 0
        && rect.height > 0
        && x >= rect.x
        && x < rect.x + rect.width
        && y >= rect.y
        && y < rect.y + rect.height
}

const BG: Color = Color::Rgb(0x25, 0x2b, 0x37);
const SUB_BG: Color = Color::Rgb(0x2b, 0x32, 0x3f);
const FG: Color = Color::Rgb(0xe6, 0xe9, 0xef);
const SEP_FG: Color = Color::Rgb(0x3b, 0x42, 0x52);
const SUB_ARROW_FG: Color = Color::Rgb(0x9a, 0xa4, 0xb2);

// Per-action icon accents, matching the Commit split-button dropdown so
// the two menus read as one design: network/sync ops blue, branch/remote
// cyan, commit/stage green, stash/tags amber, merge/rebase purple,
// destructive ops red, neutral grey.
const ACCENT_BLUE: Color = Color::Rgb(0x6c, 0xb6, 0xff);
const ACCENT_CYAN: Color = Color::Rgb(0x88, 0xc0, 0xd0);
const ACCENT_GREEN: Color = Color::Rgb(0xa3, 0xbe, 0x8c);
const ACCENT_AMBER: Color = Color::Rgb(0xeb, 0xcb, 0x8b);
const ACCENT_PURPLE: Color = Color::Rgb(0xc0, 0xa4, 0xf5);
const ACCENT_RED: Color = Color::Rgb(0xe7, 0x70, 0x70);
const ACCENT_GREY: Color = Color::Rgb(0x9a, 0xa4, 0xb2);

/// Accent colour for a leaf's icon.
fn action_color(action: ScmAction) -> Color {
    use ScmAction::*;
    match action {
        Pull | Push | Fetch | Clone | Sync | PullRebase | PushTo | PushForce | PublishBranch
        | CommitAndPush | CommitAndSync => ACCENT_BLUE,
        CheckoutTo | CreateBranch | CreateBranchFrom => ACCENT_CYAN,
        Commit | CommitStaged | CommitAll | StageAll | AddRemote => ACCENT_GREEN,
        CommitAmend | RenameBranch => ACCENT_AMBER,
        Merge | Rebase => ACCENT_PURPLE,
        DiscardAll | DeleteBranch | RemoveRemote | DropStash | DeleteTag => ACCENT_RED,
        Stash
        | StashIncludeUntracked
        | StashStaged
        | ApplyStash
        | PopStashLatest
        | PopStashPick
        | CreateTag => ACCENT_AMBER,
        UnstageAll | ShowGitOutput => ACCENT_GREY,
    }
}

/// Accent colour for a submenu parent row, by category.
fn submenu_color(label: &str) -> Color {
    match label {
        "Commit" | "Changes" => ACCENT_GREEN,
        "Pull, Push" => ACCENT_BLUE,
        "Branch" | "Remote" => ACCENT_CYAN,
        "Stash" | "Tags" => ACCENT_AMBER,
        _ => ACCENT_GREY,
    }
}

/// Width a column needs to show the longest of `labels` as
/// `[pad][icon][gap][label][gap][›][pad]`.
fn column_width(labels: impl Iterator<Item = usize>, with_arrow: bool) -> u16 {
    let arrow = if with_arrow { 2 } else { 0 };
    let max = labels.max().unwrap_or(0) as u16;
    // 1 pad + icon + 1 gap + label + arrow + 1 pad
    (1 + 1 + 1 + max + arrow + 1).max(12)
}

/// Paint the menu anchored under `anchor` within `screen`, recording hit
/// rects into `state`. The submenu fly-out renders to the right of the top
/// column (or to its left when there is no room).
pub fn render(state: &mut ScmMenuState, anchor: Rect, screen: Rect, buf: &mut Buffer) {
    state.top_hits.clear();
    state.sub_hits.clear();
    let nodes = menu();

    let top_w = column_width(
        nodes.iter().filter_map(|n| match n {
            Node::Item(l) => Some(l.label.chars().count()),
            Node::Sub { label, .. } => Some(label.chars().count()),
            Node::Sep => None,
        }),
        true,
    );
    let top_h = nodes.len() as u16;
    let top_x = anchor.x.min(screen.x + screen.width.saturating_sub(top_w));
    let top_y = (anchor.y + anchor.height).min(screen.y + screen.height.saturating_sub(top_h));
    let top_rect = Rect {
        x: top_x,
        y: top_y,
        width: top_w,
        height: top_h.min(screen.height),
    };
    Widget::render(Clear, top_rect, buf);
    fill(buf, top_rect, BG);

    for (i, node) in nodes.iter().enumerate() {
        let row_y = top_rect.y + i as u16;
        if row_y >= screen.y + screen.height {
            break;
        }
        let row = Rect {
            x: top_rect.x,
            y: row_y,
            width: top_rect.width,
            height: 1,
        };
        match node {
            Node::Sep => {
                for x in row.x + 1..row.x + row.width.saturating_sub(1) {
                    buf.set_string(x, row_y, "─", Style::default().fg(SEP_FG).bg(BG));
                }
            }
            Node::Item(l) => {
                paint_row(buf, row, l.icon, action_color(l.action), l.label, false, BG);
                state.top_hits.push((row, TopHit::Action(l.action)));
            }
            Node::Sub { label, icon, .. } => {
                let is_open = state.expanded == Some(i);
                let row_bg = if is_open { SUB_BG } else { BG };
                paint_row(buf, row, *icon, submenu_color(label), label, true, row_bg);
                state.top_hits.push((row, TopHit::Expand(i)));
            }
        }
    }

    // Fly-out submenu column.
    if let Some(i) = state.expanded
        && let Some(Node::Sub { items, .. }) = nodes.get(i)
    {
        let sub_w = column_width(items.iter().map(|l| l.label.chars().count()), false);
        let parent_y = top_rect.y + i as u16;
        // Prefer the right of the top column; fall back to its left.
        let right_x = top_rect.x + top_rect.width;
        let sub_x = if right_x + sub_w <= screen.x + screen.width {
            right_x
        } else {
            top_rect.x.saturating_sub(sub_w)
        };
        let sub_h = items.len() as u16;
        let sub_y = parent_y.min(screen.y + screen.height.saturating_sub(sub_h));
        let sub_rect = Rect {
            x: sub_x,
            y: sub_y,
            width: sub_w,
            height: sub_h.min(screen.height),
        };
        Widget::render(Clear, sub_rect, buf);
        fill(buf, sub_rect, SUB_BG);
        for (j, l) in items.iter().enumerate() {
            let row_y = sub_rect.y + j as u16;
            if row_y >= screen.y + screen.height {
                break;
            }
            let row = Rect {
                x: sub_rect.x,
                y: row_y,
                width: sub_rect.width,
                height: 1,
            };
            paint_row(
                buf,
                row,
                l.icon,
                action_color(l.action),
                l.label,
                false,
                SUB_BG,
            );
            state.sub_hits.push((row, l.action));
        }
    }
}

fn fill(buf: &mut Buffer, rect: Rect, bg: Color) {
    let style = Style::default().bg(bg);
    for ry in 0..rect.height {
        for rx in 0..rect.width {
            buf[(rect.x + rx, rect.y + ry)]
                .set_symbol(" ")
                .set_style(style);
        }
    }
}

fn paint_row(
    buf: &mut Buffer,
    row: Rect,
    icon: char,
    icon_color: Color,
    label: &str,
    submenu: bool,
    bg: Color,
) {
    let fg = Style::default().fg(FG).bg(bg);
    buf.set_string(
        row.x + 1,
        row.y,
        icon.to_string(),
        Style::default().fg(icon_color).bg(bg),
    );
    let label_x = row.x + 3;
    let avail = row.width.saturating_sub(3 + if submenu { 2 } else { 1 }) as usize;
    let shown: String = label.chars().take(avail).collect();
    buf.set_string(label_x, row.y, &shown, fg);
    if submenu && row.width >= 2 {
        buf.set_string(
            row.x + row.width - 2,
            row.y,
            "›",
            Style::default().fg(SUB_ARROW_FG).bg(bg),
        );
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn menu_has_the_expected_top_level_shape() {
        let m = menu();
        // 5 leaves + sep + 7 submenus + sep + 1 leaf = 15 nodes.
        assert_eq!(m.len(), 15);
        let subs = m.iter().filter(|n| matches!(n, Node::Sub { .. })).count();
        assert_eq!(subs, 7, "Commit/Changes/Pull-Push/Branch/Remote/Stash/Tags");
    }

    #[test]
    fn clicking_a_submenu_row_toggles_its_flyout_without_firing() {
        let mut st = ScmMenuState::default();
        let screen = Rect::new(0, 0, 120, 40);
        let anchor = Rect::new(10, 0, 2, 1);
        let mut buf = Buffer::empty(screen);
        st.open = true;
        render(&mut st, anchor, screen, &mut buf);
        // Find the "Branch" submenu's top-level index and its rect.
        let branch_idx = menu()
            .iter()
            .position(|n| matches!(n, Node::Sub { label, .. } if *label == "Branch"))
            .unwrap();
        let (rect, _) = st
            .top_hits
            .iter()
            .find(|(_, t)| *t == TopHit::Expand(branch_idx))
            .copied()
            .unwrap();
        let outcome = st.click(rect.x, rect.y);
        assert_eq!(outcome, ClickOutcome::Toggled);
        assert_eq!(st.expanded, Some(branch_idx));
    }

    #[test]
    fn clicking_a_leaf_fires_its_action() {
        let mut st = ScmMenuState::default();
        let screen = Rect::new(0, 0, 120, 40);
        let mut buf = Buffer::empty(screen);
        st.open = true;
        render(&mut st, Rect::new(10, 0, 2, 1), screen, &mut buf);
        let (rect, _) = st
            .top_hits
            .iter()
            .find(|(_, t)| *t == TopHit::Action(ScmAction::Pull))
            .copied()
            .unwrap();
        assert_eq!(
            st.click(rect.x, rect.y),
            ClickOutcome::Fire(ScmAction::Pull)
        );
    }

    #[test]
    fn leaf_icons_carry_their_per_action_accent_colour() {
        let mut st = ScmMenuState::default();
        let screen = Rect::new(0, 0, 120, 40);
        let mut buf = Buffer::empty(screen);
        st.open = true;
        render(&mut st, Rect::new(10, 0, 2, 1), screen, &mut buf);
        let (rect, _) = st
            .top_hits
            .iter()
            .find(|(_, t)| *t == TopHit::Action(ScmAction::Pull))
            .copied()
            .unwrap();
        // The icon sits one cell in from the row's left edge.
        assert_eq!(
            buf[(rect.x + 1, rect.y)].fg,
            ACCENT_BLUE,
            "the Pull icon must be painted in its blue accent, not the neutral foreground"
        );
    }

    #[test]
    fn expanded_submenu_exposes_its_leaves_as_hits() {
        let mut st = ScmMenuState::default();
        let screen = Rect::new(0, 0, 120, 40);
        let mut buf = Buffer::empty(screen);
        st.open = true;
        let stash_idx = menu()
            .iter()
            .position(|n| matches!(n, Node::Sub { label, .. } if *label == "Stash"))
            .unwrap();
        st.expanded = Some(stash_idx);
        render(&mut st, Rect::new(10, 0, 2, 1), screen, &mut buf);
        assert!(
            st.sub_hits.iter().any(|(_, a)| *a == ScmAction::DropStash),
            "the expanded Stash submenu must expose Drop Stash as a hit target"
        );
    }
}