mnml-rs 0.2.22

A NvChad-style terminal IDE in Rust — vim or standard editing, LSP, git, and an embedded HTTP client. Final Rust release; the project continues in Zig at the same repository.
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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
//! One glyph per menu row — the `MenuAction → glyph` table.
//!
//! User ask: "all rows on all dropdowns and right click menus and such
//! should have glyphs for each one like we did for menubar."
//!
//! A shared visual-constant module rather than a `match` buried in the
//! renderer, for the same reason `search_glyph` / `refresh_glyph` /
//! `action_button` are: two call sites already paint menu rows (the menu
//! and its submenu), and any future one must agree with them.
//!
//! **Grouped by meaning, not by variant.** Actions that do the same kind
//! of thing share a glyph — every delete is `` , every copy is `` —
//! so the menu reads as a small vocabulary the user learns once, instead
//! of 132 individually-chosen icons they have to learn separately.
//!
//! Returning `""` is a legitimate answer, not a gap: a row whose glyph
//! would be arbitrary is better left blank than given a misleading one.
//! `is_empty()` callers pad the column so blank rows still align.

use crate::context_menu::MenuAction;

/// Nerd Font glyph for a menu row, or `""` when none fits.
///
/// ASCII mode is the caller's decision — it passes the result through
/// [`for_action_ascii`] instead, which returns `""` for everything so an
/// `ascii_icons` user's menus look exactly as they did before.
pub fn for_action(a: &MenuAction) -> &'static str {
    use MenuAction as M;
    match a {
        // ── Open / reveal / navigate ──
        M::OpenPath(..)
        | M::OpenPathAsText(..)
        | M::OpenFilesPane(..)
        | M::OpenCloudAgentRunDetail(..)
        | M::OpenCloudWatchPane { .. }
        | M::OpenS3Pane { .. }
        | M::DiffOpenAtRevision { .. }
        | M::JumpToEnvVar(..) => "\u{f07c}", // folder-open
        M::OpenInSplit(..) | M::SplitTabInto(..) | M::HostInBottomPanel(..) => "\u{f0db}", // columns
        M::RevealInFinder(..) => "\u{f002}",                                               // search
        // A TREE glyph, not the search magnifier — the two reveal rows
        // sit next to each other, so identical icons would make the
        // distinction the labels draw invisible at a glance.
        M::RevealInTree(..) => "\u{f0e8}", // sitemap
        M::OpenExternally(..) | M::OpenUrl(..) => "\u{f08e}", // external-link
        M::OpenBookmarks(..) => "\u{f02e}", // bookmark
        M::OpenTerminal(..) | M::GitWorktreeShell(..) => "\u{f120}", // terminal
        M::PreviewMarkdown(..) => "\u{f06e}", // eye — matches the Preview chip

        // ── Clipboard ──
        M::CopyPath(..)
        | M::CopyText(..)
        | M::CopyIntegrationId(..)
        | M::FileCopy(..)
        | M::FilesCopyMarked(..)
        | M::FileDuplicate(..) => "\u{f0c5}", // copy
        M::FileCut(..) | M::FilesCutMarked(..) => "\u{f0c4}", // scissors
        M::FilePaste(..) => "\u{f0ea}",                       // paste
        M::FileMoveTo(..) => "\u{f0b2}",                      // arrows

        // ── Create ──
        M::NewFile(..) => "\u{f15b}",   // file
        M::NewFolder(..) => "\u{f07b}", // folder
        M::NewAiLaunchProfile(..) | M::GitNewBranchFrom(..) => "\u{f067}", // plus

        // ── Edit / configure ──
        M::Rename(..)
        | M::RenameSession(..)
        | M::SessionRename(..)
        | M::WorkspaceEditName(..)
        | M::WorkspaceEditPath(..)
        | M::WorkspaceEditGroup(..)
        | M::EditIntegration(..)
        | M::SetEnvVarValue(..)
        | M::ConfigureIntegration(..)
        | M::SetIntegrationLauncher(..) => "\u{f044}", // pencil

        // ── Destructive ──
        M::Delete(..)
        | M::RemoveIntegration(..)
        | M::RemoveAiLaunchProfile(..)
        | M::RemovePrimaryWorkspace
        | M::WorkspaceDelete(..)
        | M::GitDeleteBranch(..)
        | M::GitTagDelete(..)
        | M::GitStashDrop(..)
        | M::GitWorktreeRemove(..)
        | M::RemoveIntegrationFromActivityBar(..) => "\u{f1f8}", // trash
        M::CloseTab(..)
        | M::CloseOtherTabs(..)
        | M::CloseAllTabs
        | M::CloseOtherRightPanelTabs(..)
        | M::CloseAllRightPanelTabs
        | M::SessionClose(..)
        | M::StopManagedSession(..) => "\u{f00d}", // times

        // ── Pin / hide ──
        M::PinTab(..) | M::PlusMenuPin(..) | M::PlusMenuUnpin(..) | M::SessionTogglePin(..) => {
            "\u{f08d}" // thumbtack
        }
        M::PlusMenuHide(..) => "\u{f070}", // eye-slash

        // ── Git ──
        M::GitSwitchRepo(..) | M::GitReopenRepo(..) => "\u{f1d3}", // git
        M::GitCheckoutBranch(..)
        | M::GitRemoteCheckout(..)
        | M::GitMergeBranchInto(..)
        | M::GitRebaseCurrentOnto(..) => "\u{f126}", // code-fork
        M::GitStageFile(..) => "\u{f067}",                         // plus
        M::GitUnstageFile(..) => "\u{f068}",                       // minus
        M::GitDiscardFile(..) => "\u{f0e2}",                       // undo
        M::GitIgnoreFile(..) | M::GitIgnoreExtension(..) => "\u{f070}", // eye-slash
        M::GitStashFile(..) | M::GitStashPop(..) | M::GitStashApply(..) => "\u{f187}", // archive

        // ── Ordering ──
        M::SessionMoveUp(..)
        | M::WorkspaceMoveUp(..)
        | M::ExtraWorkspaceMoveUp(..)
        | M::MoveIntegrationUp(..)
        | M::MovePinnedIntegrationUp(..) => "\u{f062}", // arrow-up
        M::SessionMoveDown(..)
        | M::WorkspaceMoveDown(..)
        | M::ExtraWorkspaceMoveDown(..)
        | M::MoveIntegrationDown(..)
        | M::MovePinnedIntegrationDown(..) => "\u{f063}", // arrow-down
        M::SessionMoveToTop(..)
        | M::MoveIntegrationToTop(..)
        | M::MovePinnedIntegrationToTop(..) => "\u{f102}", // angle-double-up
        M::SessionMoveToBottom(..)
        | M::MoveIntegrationToBottom(..)
        | M::MovePinnedIntegrationToBottom(..) => "\u{f103}", // angle-double-down
        M::SessionSortAuto | M::ReorderStatuslineSegment(..) => "\u{f0dc}", // sort

        // ── Toggles ──
        M::ToggleIntegrationEnabled(..)
        | M::ToggleIntegrationPaletteBar(..)
        | M::ToggleLauncherEnabled(..)
        | M::SetIntegrationAutoUpdate(..)
        | M::FilesToggleMark(..) => "\u{f205}", // toggle-on

        // ── Workspace ──
        M::SetAsWorkspace(..)
        | M::SetDefaultWorkspace
        | M::SetDefaultWorkspaceAt(..)
        | M::WorkspaceSetDefault(..)
        | M::SwitchToExtraWorkspace(..) => "\u{f0c9}", // bars

        // ── Tree ──
        M::TreeExpandRecursive(..) => "\u{f0fe}", // plus-square
        M::TreeCollapseRecursive(..) => "\u{f146}", // minus-square

        // ── Terminal / process ──
        M::TogglePanelAutoRefresh(..) => "\u{f021}", // refresh
        M::MarkMessagesSeen => "\u{f00c}",           // check
        M::CopyLastMessage | M::CopyAllMessages => "\u{f0c5}", // copy
        M::SetPanelSort(..) => "\u{f0dc}",           // sort
        M::PtyRestart(..) => "\u{f021}",             // refresh
        M::PtyInterrupt(..) => "\u{f04d}",           // stop
        M::PtyClear(..) => "\u{f12d}",               // eraser

        // ── Run ──
        // `Command` is a generic wrapper used by dozens of rows, so one
        // glyph here rendered whole menus as a single repeated icon
        // (user: "i see too much repetition... its like we quit trying"
        // — the pty menu was twelve identical play triangles). Derive
        // it from the command id instead.
        M::Command(id) => command_glyph(id),
        M::RunCmd(..) => "\u{f04b}", // play
        // Agents / skills / slash-commands offered on a TODO row.
        M::TodoAction { .. } => "\u{F06A9}",     // robot
        M::RunIntegrationDiag(..) => "\u{f0f1}", // stethoscope

        // ── Info ──
        M::ShowIntegrationDetails(..) | M::ShowIntegrationManifest(..) => "\u{f05a}", // info-circle
        M::ShowIntegrationInMarketplace(..) => "\u{f07a}", // shopping-cart
        M::UpdateIntegration(..) => "\u{f019}",            // download

        // ── Appearance ──
        M::SetTheme(..) | M::SessionSetColor(..) => "\u{f043}", // tint
        M::OpenGlyphBuilderForCp(..) | M::RebakeGlyphForCp(..) => "\u{f031}", // font

        // ── Save ──
        M::SavePane(..) => "\u{f0c7}", // save

        // ── AI ──
        M::OpenAiSessionWithProfile(..) | M::SetAiDefaultProfile(..) => "\u{f0e7}", // bolt

        M::AddIntegrationToActivityBar(..) | M::LaunchPinnedIntegration(..) => "\u{f0fe}",

        // A submenu already carries its `▸` affordance on the right; a
        // glyph on the left as well would double-mark the same fact.
        M::Submenu => "",

        // Deliberately blank — a positional/contextual action whose glyph
        // would be invented rather than meaningful.
        M::SetRightPanelTab(..) | M::SetTopBarClusterMode(..) | M::DiffHunkAction { .. } => "",
    }
}

/// Glyph for a `MenuAction::Command(id)` row, keyed off the command id.
///
/// ACTION FIRST, then domain. A command id is `namespace.action`, and
/// the action is what the row DOES — so `editor.undo` is an undo, not
/// an edit, and `git.push` is a push, not a generic git operation.
///
/// The first version matched substrings against the WHOLE id in one
/// ordered pass, which let a namespace swallow everything under it:
/// `("git", …)` claimed all fifty git commands, `("edit", …)` claimed
/// every `editor.*`, and 339 of 789 commands (43%) fell through to a
/// play triangle. The result was menus that were a column of one icon
/// — the exact complaint the table was added to fix, relocated.
fn command_glyph(id: &str) -> &'static str {
    // Matched against the LAST dotted segment.
    const ACTION: &[(&str, &str)] = &[
        // 2026-09-03 — SESSIONS' sort rows go through
        // `MenuAction::Command("sessions.sort_auto")`, not
        // `SetPanelSort`, so they fell through to the play-triangle
        // fallback and rendered `▶ ✓ State` beside the list panels'
        // `✓ Newest first`. Same menu shape, two different icons.
        ("sort", "\u{f0dc}"),
        ("undo", "\u{f0e2}"),
        ("redo", "\u{f01e}"),
        ("paste", "\u{f0ea}"),
        ("copy", "\u{f0c5}"),
        ("yank", "\u{f0c5}"),
        ("cut", "\u{f0c4}"),
        ("clear", "\u{f12d}"),
        ("restart", "\u{f021}"),
        ("refresh", "\u{f021}"),
        ("reload", "\u{f021}"),
        ("reset", "\u{f0e2}"),
        ("close", "\u{f00d}"),
        ("quit", "\u{f00d}"),
        ("kill", "\u{f00d}"),
        ("stop", "\u{f04d}"),
        ("delete", "\u{f1f8}"),
        ("remove", "\u{f1f8}"),
        ("trash", "\u{f1f8}"),
        ("save", "\u{f0c7}"),
        ("write", "\u{f0c7}"),
        ("definition", "\u{eab5}"),
        ("references", "\u{f0c1}"),
        ("hover", "\u{f05a}"),
        ("symbol", "\u{f1b3}"),
        ("rename", "\u{f044}"),
        ("format", "\u{f036}"),
        ("comment", "\u{f075}"),
        ("indent", "\u{f03c}"),
        ("fold", "\u{f0d7}"),
        ("select", "\u{f0c9}"),
        ("goto", "\u{eab5}"),
        ("jump", "\u{eab5}"),
        ("commit", "\u{f1d3}"),
        ("push", "\u{f062}"),
        ("pull", "\u{f063}"),
        ("fetch", "\u{f063}"),
        ("stash", "\u{f187}"),
        ("branch", "\u{f126}"),
        ("merge", "\u{f126}"),
        ("rebase", "\u{f126}"),
        ("diff", "\u{f0db}"),
        ("stage", "\u{f067}"),
        ("unstage", "\u{f068}"),
        ("new", "\u{f067}"),
        ("open", "\u{f07c}"),
        ("reveal", "\u{f002}"),
        ("find", "\u{f002}"),
        ("search", "\u{f002}"),
        ("grep", "\u{f002}"),
        ("theme", "\u{f043}"),
        ("toggle", "\u{f205}"),
        ("dock", "\u{f0db}"),
        ("split", "\u{f0db}"),
        ("equalize", "\u{f0db}"),
        ("maximize", "\u{f065}"),
        ("zoom", "\u{f065}"),
        ("settings", "\u{f013}"),
        ("config", "\u{f013}"),
        ("help", "\u{f059}"),
        ("about", "\u{f05a}"),
        ("pin", "\u{f08d}"),
        ("hide", "\u{f070}"),
        ("show", "\u{f06e}"),
        ("run", "\u{f04b}"),
        ("test", "\u{f0c3}"),
        ("build", "\u{f0ad}"),
        ("install", "\u{f019}"),
        ("update", "\u{f019}"),
        ("next", "\u{f061}"),
        ("prev", "\u{f060}"),
    ];
    // Matched against the FIRST dotted segment, only when the action
    // says nothing. A domain icon is a weaker answer than an action
    // one, so it must never outrank it.
    const DOMAIN: &[(&str, &str)] = &[
        ("git", "\u{f1d3}"),
        ("ai", "\u{F06A9}"),
        ("browser", "\u{f0ac}"),
        ("http", "\u{f1d8}"),
        ("term", "\u{f120}"),
        ("pty", "\u{f120}"),
        ("tools", "\u{f120}"),
        ("lsp", "\u{f085}"),
        ("dap", "\u{f188}"),
        ("debug", "\u{f188}"),
        ("files", "\u{f07b}"),
        ("tree", "\u{f07b}"),
        ("buffer", "\u{f15b}"),
        ("tab", "\u{f15b}"),
        ("editor", "\u{f044}"),
        ("view", "\u{f06e}"),
        ("window", "\u{f0db}"),
        ("picker", "\u{f002}"),
        ("notes", "\u{f249}"),
        ("todos", "\u{f046}"),
        ("findings", "\u{F1623}"),
        ("integrations", "\u{f12e}"),
        ("cloud", "\u{f0c2}"),
        ("mixr", "\u{f001}"),
    ];

    let lower = id.to_ascii_lowercase();
    let (ns, action) = match lower.split_once('.') {
        Some((a, b)) => (a, b.rsplit('.').next().unwrap_or(b)),
        None => ("", lower.as_str()),
    };
    for (needle, glyph) in ACTION {
        if action.contains(needle) {
            return glyph;
        }
    }
    for (needle, glyph) in DOMAIN {
        if ns == *needle {
            return glyph;
        }
    }
    "\u{f04b}"
}

/// ASCII mode gets no glyphs at all.
///
/// The alternative — an ASCII stand-in per family — would need a legend
/// to be readable, and `ascii_icons` exists for terminals that cannot
/// render these codepoints, not for users who want a denser menu.
pub fn for_action_ascii(_a: &MenuAction) -> &'static str {
    ""
}

/// Width of the glyph column, in cells: glyph + a 2-cell gap, matching
/// `menu_bar`'s `icon_col_w` — the spacing the user singled out as the
/// one that reads correctly.
pub const COLUMN_W: usize = 3;

/// The glyph column a menu row paints, honouring `ascii_icons`.
///
/// ALWAYS [`COLUMN_W`] cells in nerd mode, even for a row with no
/// glyph. A variable-width column was the bug behind rows looking
/// randomly indented: a label already carrying its own `✓ ` prefix
/// ended up a gutter deeper than its neighbours.
/// The glyph column, preferring an EXPLICIT icon over the action
/// table. `MenuItem::with_icon` sets one for rows the table cannot
/// identify — submenu parents and integration rows.
pub fn column_for(icon: Option<&str>, a: &MenuAction, ascii: bool) -> String {
    if ascii {
        return String::new();
    }
    match icon {
        Some(g) if !g.is_empty() => format!("{g}{}", " ".repeat(COLUMN_W - 1)),
        _ => column(a, ascii),
    }
}

pub fn column(a: &MenuAction, ascii: bool) -> String {
    if ascii {
        return String::new();
    }
    let g = for_action(a);
    if g.is_empty() {
        " ".repeat(COLUMN_W)
    } else {
        format!("{g}{}", " ".repeat(COLUMN_W - 1))
    }
}

/// Write the menu-glyph audit document and return its path.
///
/// A REAL function, not a `#[ignore]`d test: the user asked for "an
/// easier way to do the audit list in future, shouldn't be that hard".
/// `menu.glyph_audit` in the palette calls this and opens the result.
///
/// Enumerates EVERY registered command, not a hand-picked sample.
///
/// The first version sampled 26 of 132 `MenuAction` variants and 10
/// command ids while its own header claimed it was "generated from the
/// live table so it cannot drift" — so it reported a healthy
/// vocabulary while the git chip menu was ten identical logos and the
/// LSP menu was seven play triangles. A sampling audit that claims
/// completeness is worse than no audit: it answers the question
/// wrongly and confidently.
pub fn write_audit(dir: &std::path::Path) -> std::io::Result<std::path::PathBuf> {
    use std::collections::BTreeMap;

    // Every registered command id, resolved through the real table.
    let mut by_glyph: BTreeMap<&'static str, Vec<(&'static str, &'static str)>> = BTreeMap::new();
    for c in crate::command::registry().all() {
        by_glyph
            .entry(command_glyph(c.id))
            .or_default()
            .push((c.id, c.title));
    }
    let total: usize = by_glyph.values().map(|v| v.len()).sum();

    // Worst offenders first — a menu is unreadable when many of its
    // rows share one icon, so size of group is the thing to look at.
    let mut groups: Vec<(&'static str, usize)> =
        by_glyph.iter().map(|(g, v)| (*g, v.len())).collect();
    groups.sort_by_key(|(_, n)| std::cmp::Reverse(*n));

    let mut out = format!(
        "# Menu glyph audit\n\n\
         Regenerate with the `menu.glyph_audit` palette command.\n\n\
         {total} registered commands resolved through `command_glyph`, \
         grouped by the glyph they land on. EVERY command is listed — \
         this is not a sample.\n\n\
         A large group is the thing to look for: it means that many menu \
         rows draw the same icon, which is what makes a menu read as a \
         column of one symbol.\n\n\
         ## Group sizes\n\n"
    );
    for (g, n) in &groups {
        let shown = if g.is_empty() {
            "(none)".to_string()
        } else {
            format!("`{g}` {g}")
        };
        out.push_str(&format!("- {shown} — **{n}**\n"));
    }

    out.push_str("\n## Every command, by glyph\n");
    for (g, n) in &groups {
        let shown = if g.is_empty() {
            "(none)".to_string()
        } else {
            format!("`{g}`  {g}")
        };
        out.push_str(&format!("\n### {shown} — {n} command(s)\n\n"));
        let mut rows = by_glyph[g].clone();
        rows.sort();
        for (id, title) in rows {
            out.push_str(&format!(
                "- `{}{}` — `{id}`\n",
                column_for(None, &crate::context_menu::MenuAction::Command(id), false),
                title
            ));
        }
    }

    std::fs::create_dir_all(dir)?;
    let path = dir.join("menu-glyph-audit.md");
    std::fs::write(&path, out)?;
    Ok(path)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::context_menu::MenuAction as M;

    /// The point of the table: same KIND of action, same glyph. If these
    /// drift apart the menu stops being a small learnable vocabulary and
    /// becomes 132 unrelated icons.
    #[test]
    fn actions_of_the_same_kind_share_a_glyph() {
        assert_eq!(
            for_action(&M::CopyPath("/a".to_string())),
            for_action(&M::CopyText("x".into())),
            "two copy actions disagree on their glyph"
        );
        assert_eq!(
            for_action(&M::CloseAllTabs),
            for_action(&M::CloseOtherTabs(0)),
            "two close actions disagree on their glyph"
        );
    }

    /// Different kinds must NOT collide, or the glyph column carries no
    /// information — a test that only checked "every row has a glyph"
    /// would pass on a table that returned one icon for everything.
    #[test]
    fn different_kinds_do_not_share_a_glyph() {
        let copy = for_action(&M::CopyText("x".into()));
        let del = for_action(&M::Delete(std::path::PathBuf::from("/a")));
        let save = for_action(&M::SavePane(0));
        assert_ne!(copy, del, "copy and delete share a glyph");
        assert_ne!(copy, save, "copy and save share a glyph");
        assert_ne!(del, save, "delete and save share a glyph");
    }

    /// The ACTION must beat the NAMESPACE.
    ///
    /// Matching the whole id in one pass let a namespace swallow
    /// everything under it: `editor.undo` resolved to a pencil because
    /// "edit" matched, and all fifty git commands drew one logo.
    #[test]
    fn the_action_outranks_the_namespace() {
        assert_ne!(
            command_glyph("editor.undo"),
            command_glyph("editor.indent_line"),
            "every editor.* command still collapses to one namespace icon"
        );
        assert_ne!(
            command_glyph("git.push"),
            command_glyph("git.pull"),
            "push and pull share an icon — the git namespace is winning"
        );
        assert_ne!(
            command_glyph("editor.undo"),
            command_glyph("editor.redo"),
            "undo and redo share an icon, and they are opposites"
        );
    }

    /// No single glyph may claim a large share of the command surface.
    ///
    /// This is the measurable form of "a menu should not be a column of
    /// one repeated icon". Before the action/domain split, the play
    /// triangle held 339 of 789 commands — 43% — and menus built from
    /// those ids rendered as exactly that.
    #[test]
    fn no_glyph_claims_a_large_share_of_all_commands() {
        use std::collections::BTreeMap;
        let mut by: BTreeMap<&str, usize> = BTreeMap::new();
        let mut total = 0usize;
        for c in crate::command::registry().all() {
            *by.entry(command_glyph(c.id)).or_default() += 1;
            total += 1;
        }
        let (worst, n) = by.iter().max_by_key(|(_, n)| **n).unwrap();
        let share = (*n as f64) / (total as f64);
        assert!(
            share < 0.20,
            "{worst:?} covers {n}/{total} commands ({:.0}%) — menus built \
             from these ids will read as a column of one icon",
            share * 100.0
        );
    }

    /// A go-to-definition row must draw the same glyph wherever it
    /// appears. The menu bar hand-picks `\u{eab5}`; the table used to
    /// give the editor's own menu a play triangle for the same action.
    #[test]
    fn goto_definition_matches_the_menu_bars_hand_picked_glyph() {
        assert_eq!(
            command_glyph("lsp.goto_definition"),
            "\u{eab5}",
            "the same action draws two different glyphs depending on \
             which menu you opened it from"
        );
    }

    /// An EXPLICIT icon must win over the action table.
    ///
    /// Without this, a submenu parent rendered blank (its action is
    /// `Submenu`, which identifies nothing) and every integration row
    /// rendered the same play triangle (all generic `RunCmd`) — fifteen
    /// identical icons in one menu.
    #[test]
    fn an_explicit_icon_overrides_the_action_table() {
        let a = M::Submenu;
        assert_eq!(for_action(&a), "", "setup: Submenu has no table glyph");
        let col = column_for(Some("\u{f12e}"), &a, false);
        assert!(
            col.starts_with('\u{f12e}'),
            "the explicit icon was ignored: {col:?}"
        );
        assert_eq!(
            col.chars().count(),
            COLUMN_W,
            "an explicit icon broke the column width: {col:?}"
        );
    }

    /// Distinct integration glyphs must stay distinct — that is the
    /// entire complaint being fixed.
    #[test]
    fn distinct_explicit_icons_do_not_collapse() {
        let a = M::RunCmd("x".into());
        let one = column_for(Some("\u{f09b}"), &a, false);
        let two = column_for(Some("\u{f1d3}"), &a, false);
        assert_ne!(one, two, "two integrations rendered the same icon");
    }

    /// No explicit icon falls through to the table, so rows that never
    /// set one are unaffected.
    #[test]
    fn no_explicit_icon_falls_through_to_the_table() {
        let a = M::SavePane(0);
        assert_eq!(column_for(None, &a, false), column(&a, false));
        assert_eq!(column_for(Some(""), &a, false), column(&a, false));
    }

    /// ASCII mode still paints nothing, explicit icon or not.
    #[test]
    fn an_explicit_icon_is_still_suppressed_in_ascii_mode() {
        assert_eq!(column_for(Some("\u{f12e}"), &M::Submenu, true), "");
    }

    /// ASCII mode must be untouched — `ascii_icons` exists for terminals
    /// that cannot render these codepoints.
    #[test]
    fn ascii_mode_emits_no_glyph_column() {
        let a = M::CopyText("x".into());
        assert_eq!(column(&a, true), "", "ascii mode painted a glyph");
        assert!(!column(&a, false).is_empty(), "nerd mode painted nothing");
    }

    /// EVERY row's column is the same width, glyph or not.
    ///
    /// This test previously asserted the opposite — that a glyph-less
    /// row emitted NOTHING — which is precisely the bug the user saw:
    /// rows whose label already carried a `✓ ` prefix sat a gutter
    /// deeper than their neighbours, so the menu looked randomly
    /// indented. A variable-width column cannot align.
    #[test]
    fn every_row_reserves_the_same_glyph_column_width() {
        assert_eq!(for_action(&M::Submenu), "", "setup: expected a blank row");
        let blank = column(&M::Submenu, false);
        let full = column(&M::SavePane(0), false);
        assert_eq!(
            blank.chars().count(),
            COLUMN_W,
            "a glyph-less row did not reserve the column: {blank:?}"
        );
        assert_eq!(
            full.chars().count(),
            COLUMN_W,
            "a glyph row did not reserve the column: {full:?}"
        );
        assert!(
            blank.trim().is_empty(),
            "the blank column painted something: {blank:?}"
        );
        assert!(
            full.ends_with("  "),
            "no 2-cell gap after the glyph: {full:?}"
        );
    }

    /// `MenuAction::Command` is a generic wrapper behind dozens of rows.
    /// One glyph for all of them turned whole menus into a column of the
    /// same repeated icon ("i see too much repetition... its like we
    /// quit trying"), so ids must resolve to DIFFERENT glyphs.
    #[test]
    fn command_rows_do_not_all_collapse_to_one_glyph() {
        let ids = [
            "pty.clear",
            "pty.restart",
            "pane.close",
            "window.dock_left",
            "window.maximize_width",
            "edit.paste",
        ];
        let glyphs: std::collections::HashSet<&str> =
            ids.iter().map(|i| command_glyph(i)).collect();
        assert!(
            glyphs.len() >= 5,
            "{} ids collapsed to {} glyph(s) — the pty menu was twelve \
             identical play triangles for exactly this reason",
            ids.len(),
            glyphs.len()
        );
    }

    /// An id the table does not know still gets an honest fallback
    /// rather than a blank or a wrong-but-specific icon.
    #[test]
    fn an_unmapped_command_falls_back_rather_than_blank() {
        let g = command_glyph("something.entirely.unmapped");
        assert!(!g.is_empty(), "unmapped command produced no glyph");
    }
}

#[cfg(test)]
mod sort_row_glyph_tests {
    use super::*;
    use crate::context_menu::MenuAction as M;

    /// The two sort menus must carry the SAME icon.
    ///
    /// The list panels' rows are `MenuAction::SetPanelSort`, which has
    /// an explicit entry; SESSIONS' rows are
    /// `MenuAction::Command("sessions.sort_auto")`, which fell through
    /// to the play-triangle fallback. Identical menus, one row with a
    /// sort icon and one with `▶`.
    #[test]
    fn both_sort_menus_use_the_same_glyph() {
        let panel = column_for(None, &M::SetPanelSort("todos".into(), "name".into()), false);
        let sessions = column_for(None, &M::Command("sessions.sort_auto"), false);
        assert_eq!(
            panel.trim(),
            sessions.trim(),
            "the two sort menus render different icons"
        );
        assert_ne!(
            sessions.trim(),
            "\u{f04b}",
            "the sessions sort row is still on the play-triangle fallback"
        );
    }
}