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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
//! The left rail. Two stacked sections, each with a collapsible header:
//!
//! * `> WORKSPACE-NAME` — the file tree (VS-Code Explorer-style).
//! * `> GIT` — local branches (`●` marks the current one) followed by linked
//! worktrees (`⤿` marks the one we're in). Click a branch ⇒ checkout; click
//! a worktree ⇒ open a shell pane there. Right-click for the per-row menu.
//!
//! The rail itself is independently toggled by `Ctrl+B` (`tree_visible`). Both
//! section-expand states are persisted in session.json.
use ratatui::Frame;
use ratatui::layout::Rect;
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::Paragraph;
use crate::app::{App, RailSection};
use crate::focus::Focus;
use crate::git::rail::GitRailHit;
use crate::git::status::FileState;
use crate::ui::{hover_help, icons, theme};
// Tree / integrations panel section chevrons. 2026-08-08 —
// switched to nf-oct-chevron_right / chevron_down (F460 / F47C).
// User-suggested small chevrons; smaller than the mnml-baked
// F1E20/F1E21 pair we tried first, which rendered clipped in
// the user's ghostty. Historic failures (all reverted): MDI
// F01F5/F01F6 → smileys; codicon EAB4/EAA0 → chevron-UP; MDI
// F0142 → tofu. If F460/F47C also fail, fall back to baking
// our own at F1E20/F1E21 with a redrawn narrower SVG.
const CHEVRON_OPEN: &str = "\u{F47C}";
const CHEVRON_CLOSED: &str = "\u{F460}";
/// Max branches shown in the GIT section's branches sub-list when
/// `App.git_branches_expanded` is false (the default). User clicks
/// the trailing `+ N more` row to flip to "show all".
const BRANCH_LIST_CAP: usize = 8;
pub fn draw(frame: &mut Frame, app: &mut App, area: Rect) {
let rail_bg = theme::cur().bg_darker;
// `Block` actually fills every cell in `area` with the bg color;
// an empty `Paragraph` doesn't (it only writes glyphs where text
// exists). Without this, when a section shrinks frame-to-frame
// (e.g. INTEGRATIONS toggling expanded → collapsed), leftover
// text from the previous render remains visible in the cells the
// shrunk section no longer covers. See bug: stale "e" + "x" from
// "Claude Code" / "Codex" labels showing above INTEGRATIONS.
frame.render_widget(
ratatui::widgets::Block::default().style(Style::default().bg(rail_bg)),
area,
);
app.rects.tree = None;
app.rects.tree_toggle = None;
app.rects.git_section_toggle = None;
app.rects.git_rail_rows.clear();
app.rects.extra_workspace_bodies.clear();
app.rects.extra_workspace_toggles.clear();
app.rects.tree_icon_buttons.clear();
// integration_icon_rects clear moved to ui::draw entry — see
// the api-workflow-user F1+F2 fix note there. Multiple painters
// populate this vec; centralizing the clear avoids stomping.
app.rects.integration_section_toggle = None;
if area.height == 0 || area.width == 0 {
return;
}
let nerd = !app.config.ui.ascii_icons;
let width = area.width as usize;
if area.height < 2 {
return;
}
// 2026-08-09 — Ableton-style hover-help info box.
//
// R10 api-workflow SEV-2 (2026-08-10) — moved to a section-
// agnostic reservation in `ui/mod.rs` so the info box also
// renders when the user is on Http / Git / Integrations /
// Agents / etc. `area` here is ALREADY the pre-reserved body
// rect passed by the caller. Kept `hover_help_area = None` on
// this side so the existing `hover_help_finish` call sites
// (which used to draw the box) simply clear the strip rect;
// `ui/mod.rs` re-sets it via `hover_help::draw` immediately
// after the section-draw returns.
let hover_help_area: Option<Rect> = None;
// qa-feature 2026-06-30 — INTEGRATIONS + GIT sections were
// previously rendered at the bottom of the file browser as a
// shortcut, but both have dedicated activity-bar icons (the
// GitKraken-style git palette + the integrations panel) that
// give them a full panel of vertical space. Showing them
// duplicated here ate rows from the workspace tree without
// adding value. Zeroed; the workspace tree now gets the full
// rail height.
let git_needed = 0u16;
let _integration_needed = 0u16;
let integration_height = 0u16;
let git_height = 0u16;
// How many rows of GIT content didn't fit. When > 0,
// `draw_git_section` appends a `… N more` indicator on its
// last row so the user knows the list is clipped (instead of
// wondering if there are silently-hidden entries below).
// The indicator takes 1 row itself, so we subtract one more
// from the displayed count to avoid lying about how many are
// hidden.
let git_overflow_rows: u16 = if git_height < git_needed {
// git_needed counts the header but git_height also counts
// it, so the diff is content rows that didn't fit.
git_needed.saturating_sub(git_height)
} else {
0
};
// Cache for the mouse-down drag-resize handler so it can use
// these as the drag anchor.
app.rects.integration_section_h = integration_height;
app.rects.git_section_h = git_height;
// Always reserve 1 row of rail-bg below the GIT section so the
// last visible row never kisses the statusline. Doubles as the
// "no more content below" affordance — combined with the
// overflow-indicator row at the bottom of `draw_git_section`,
// the user can always tell whether they're seeing the full list
// or a clipped view.
let git_bottom_pad: u16 = 1;
let git_top_y = area.y + area.height - git_height - git_bottom_pad;
let integration_top_y = git_top_y.saturating_sub(integration_height + 1); // +1 separator
// Workspace section gets everything above the integration section
// (with a one-row separator immediately above it).
let ws_end_y = if integration_height > 0 {
integration_top_y.saturating_sub(1)
} else {
git_top_y.saturating_sub(1)
};
app.rects.workspace_picker_chevron = None;
// The clipped rect bounds the workspace-tree / extras / `+ repo`
// rows so they never spill into the GIT panel pinned below.
let ws_area = Rect {
x: area.x,
y: area.y,
width: area.width,
height: ws_end_y.saturating_sub(area.y),
};
// qa-feature 2026-07-01 — render primary + extras in a
// single stable POSITION ORDER (each carries a `.position`).
// Promoting an extra to primary now only swaps positions, so
// the visible list order never reshuffles. The primary is
// just an entry with `PrimaryOrExtra::Primary`; extras are
// referenced by their `extra_workspaces` index.
enum Slot {
Primary,
Extra(usize),
}
let mut slots: Vec<(usize, Slot)> = Vec::with_capacity(app.extra_workspaces.len() + 1);
slots.push((app.primary_position, Slot::Primary));
for (i, w) in app.extra_workspaces.iter().enumerate() {
slots.push((w.position, Slot::Extra(i)));
}
slots.sort_by_key(|(p, _)| *p);
let mut next_y = area.y;
for (slot_idx, (_pos, slot)) in slots.iter().enumerate() {
if next_y >= ws_end_y {
break;
}
// Insert a blank separator row between workspaces (same
// convention the old primary+extras loop used).
if slot_idx > 0 {
if next_y + 1 >= ws_end_y {
break;
}
next_y += 1;
}
match slot {
Slot::Primary => {
next_y = draw_primary_workspace_section(frame, app, ws_area, next_y, nerd, rail_bg);
}
Slot::Extra(i) => {
next_y = draw_extra_workspace_section(frame, app, ws_area, next_y, *i, nerd);
}
}
}
// ── `+ Add workspace` row — sits ONE row below the last
// workspace so it visually belongs to the group. Extends
// down only when an expanded workspace pushes the last
// row further; when nothing's expanded, the chip stays
// right under the last collapsed extra with 1 cell of
// padding (user preference — was briefly pinned to
// ws_end_y - 1 but that left a huge dead zone below the
// workspaces when nothing was expanded).
if next_y + 1 < ws_end_y {
draw_add_repo_row(frame, app, area, next_y + 1, nerd, rail_bg);
}
// ── INTEGRATIONS section: pinned just above GIT (with a blank
// separator row between). Only rendered if there's space + the
// user has configured at least one integration icon.
if integration_height > 0 {
draw_integration_section(
frame,
app,
area,
integration_top_y,
integration_height,
nerd,
rail_bg,
);
}
// ── GIT section: pinned to bottom. Render at git_top_y regardless of
// where the workspace section ended; the separator row above it is
// left blank by the row-0 bg fill at the top of `draw`.
// qa-fix 2026-06-30 — GIT section was still rendering here
// even though git_height was zeroed in the layout math. The
// earlier "remove GIT from file browser" commit only prevented
// *body* rendering; the header + chip cluster kept painting.
// Skip the whole section when git_height == 0.
if git_height == 0 {
hover_help_finish(frame, app, hover_help_area);
return;
}
let git_header_y = git_top_y;
if git_header_y >= area.y + area.height {
hover_help_finish(frame, app, hover_help_area);
return;
}
let triangle = app.config.ui.expand_indicator == "triangle";
let chev = section_chev_with_pref(app.git_section_expanded, nerd, triangle);
// Multi-repo workspaces append `· <repo-name>` to the GIT header so
// the user knows which repo the rail is currently scoped to. Single-
// repo case keeps the bare "GIT" label.
let multi_repo_chip = if app.repos.len() > 1 {
app.repos
.get(app.active_repo)
.map(|r| format!(" · {}", r.name))
.unwrap_or_default()
} else {
String::new()
};
let chev_str = format!(" {chev} ");
let label_str = format!("GIT{multi_repo_chip}");
let header_used = chev_str.chars().count() + label_str.chars().count();
// Right-aligned cluster of one-click git op chips. Each is 3 cells
// (`' <glyph> '`). Drop chips from the right until the cluster fits
// in the remaining width with at least one space of separation.
// Order matches the GitGraph toolbar so the visual language is
// consistent.
let t = theme::cur();
type ChipSpec = (
&'static str,
&'static str,
crate::GitRailHeaderAction,
ratatui::style::Color,
);
let chips_full: [ChipSpec; 6] = [
("\u{EB37}", "↺", crate::GitRailHeaderAction::Fetch, t.cyan),
("\u{EA9A}", "↓", crate::GitRailHeaderAction::Pull, t.green),
("\u{EAA1}", "↑", crate::GitRailHeaderAction::Push, t.blue),
(
"\u{EA60}",
"+",
crate::GitRailHeaderAction::StageAll,
t.green,
),
(
"\u{F012C}",
"✓",
crate::GitRailHeaderAction::Commit,
t.green,
),
(
"\u{F062C}",
"⎇",
crate::GitRailHeaderAction::Graph,
t.yellow,
),
];
// Decide how many chips fit. Chips render as `" {glyph} "` — 3 chars,
// but Nerd Font glyphs (EB37/EA9A/EAA1/EA60/F012C/F062C above) are
// 2 display columns wide, so the on-screen span is 4 cells in nerd
// mode. Same click-rect misalignment as the workspace-header chips
// (see `workspace_header_chips`); reviewer flagged this cluster
//2026-08-16 for having the identical unfixed bug.
let chip_w = if nerd { 4usize } else { 3usize };
let min_separation = 1usize;
let chip_count = {
let mut n = chips_full.len();
while n > 0 && header_used + min_separation + n * chip_w > width {
n -= 1;
}
n
};
let chips_used = chip_count * chip_w;
let pad_between = width.saturating_sub(header_used + chips_used);
app.rects.rail_git_header_buttons.clear();
// #polish 2026-07-06 — register a click rect for the
// `· <repo-name>` chip so users can click it to open the
// repo switcher instead of digging into the palette.
app.rects.git_repo_chip = None;
if !multi_repo_chip.is_empty() {
let chip_start = area.x + chev_str.chars().count() as u16 + 3; // 3 = "GIT"
app.rects.git_repo_chip = Some(Rect {
x: chip_start,
y: git_header_y,
width: multi_repo_chip.chars().count() as u16,
height: 1,
});
}
let mut spans: Vec<Span<'static>> = Vec::with_capacity(3 + chip_count);
spans.push(Span::styled(
chev_str,
Style::default().fg(t.comment).bg(rail_bg),
));
spans.push(Span::styled(
label_str,
Style::default()
.fg(t.fg)
.bg(rail_bg)
.add_modifier(Modifier::BOLD),
));
spans.push(Span::styled(
" ".repeat(pad_between),
Style::default().bg(rail_bg),
));
// Translate chip-cluster cells into screen-relative rects as we paint.
let cluster_start_x = area.x + (header_used + pad_between) as u16;
for (i, (glyph_nerd, glyph_ascii, action, fg)) in chips_full.iter().take(chip_count).enumerate()
{
let glyph = if nerd { *glyph_nerd } else { *glyph_ascii };
spans.push(Span::styled(
format!(" {glyph} "),
Style::default().fg(*fg).bg(rail_bg),
));
let chip_x = cluster_start_x + (i * chip_w) as u16;
app.rects.rail_git_header_buttons.push((
Rect {
x: chip_x,
y: git_header_y,
width: chip_w as u16,
height: 1,
},
*action,
));
}
let git_header_rect = Rect {
x: area.x,
y: git_header_y,
width: area.width,
height: 1,
};
frame.render_widget(Paragraph::new(Line::from(spans)), git_header_rect);
app.rects.git_section_toggle = Some(git_header_rect);
if !app.git_section_expanded {
hover_help_finish(frame, app, hover_help_area);
return;
}
let body_y = git_header_y + 1;
if body_y >= area.y + area.height {
hover_help_finish(frame, app, hover_help_area);
return;
}
draw_git_section(frame, app, area, body_y, nerd, git_overflow_rows);
hover_help_finish(frame, app, hover_help_area);
}
/// Paint the bottom-of-left-panel hover-help info box after the tree
/// has drawn. Nothing when the toggle is off or the panel was too
/// short to reserve the rows.
fn hover_help_finish(frame: &mut Frame, app: &mut App, area: Option<Rect>) {
if let Some(r) = area {
hover_help::draw(frame, app, r);
} else {
app.rects.hover_help_strip = None;
}
}
/// The four per-workspace action chips that hang off the right edge of
/// every workspace/repo header row. Click dispatches a palette command
/// by id; the cluster reads `+ file · + folder · ↺ refresh · ↕ collapse`
/// from left to right.
/// Per-workspace action chips. The fourth chip is a toggle whose glyph
/// + dispatch flip with the tree's current expansion state:
/// - any dir expanded → ` collapse-all` (EAC5)
/// - everything closed → ` expand-all` (EBD9)
///
/// The toggle dispatches `tree.toggle_collapse_all` either way; the
/// glyph swap is purely visual.
fn workspace_action_chip_specs(
app: &App,
) -> [(
&'static str,
&'static str,
&'static str,
ratatui::style::Color,
); 5] {
let t = theme::cur();
let (collapse_glyph, collapse_ascii) = if app.tree.is_fully_collapsed() {
("\u{F0AB4}", "↧") // expand-all
} else {
("\u{EAC5}", "↕") // collapse-all
};
[
// 2026-06-24 — user-reported swap: the visually-rendered
// glyphs in mnml's patched font are folder-shape (EA80,
// blue) + file-shape (EA7F, yellow), but the upstream
// codicon mapping is the opposite. Match command to
// visible icon, not to upstream codepoint name.
("\u{EA80}", "d+", "file.new_folder", t.blue),
("\u{EA7F}", "f+", "file.new", t.yellow),
("\u{EB37}", "↺", "tree.refresh", t.cyan),
// 2026-06-30 — pull (↓) chip. Codicon EAA1 was arrow-UP
// (my mistake). Codicon EA9A is actual arrow-down —
// matches git's universal pull=down convention.
("\u{EA9A}", "↓", "git.pull", t.green),
(
collapse_glyph,
collapse_ascii,
"tree.toggle_collapse_all",
t.teal,
),
]
}
/// Right-aligned action-chip cluster for a workspace header row. Caller
/// supplies the header's already-painted prefix width (chevron + label)
/// so this helper can compute the gap-pad span and chip positions.
/// Returns the spans to append to the header's `Line`; also pushes each
/// chip's screen-rect + command-id into `app.rects.tree_icon_buttons`.
///
/// Drops trailing chips when the header is too narrow to host the full
/// cluster with at least one space of separation from the label.
///
/// 2026-08-05 — chips are now ALWAYS visible (user asked for it).
/// Painted on a distinct `bg2` backdrop so the cluster reads as a
/// deliberate control strip, not phantom whitespace. This resolves
/// the original 2026-07-14 concern (mouse-round-12 SEV-2 F1: cold
/// clicks on "empty" strip silently fired file.new_folder / git.pull
/// / tree.refresh because rects were live but glyphs blended in) —
/// visible = clickable, no invisible hit surface.
fn workspace_header_chips(
app: &mut App,
header_rect: Rect,
label_used: usize,
nerd: bool,
rail_bg: ratatui::style::Color,
) -> Vec<Span<'static>> {
let chip_bg = rail_bg;
let chips = workspace_action_chip_specs(app);
let width = header_rect.width as usize;
// 2026-08-16 — Nerd Font glyphs (EA80/EA7F/EB37/EA9A/…) are 2 display
// columns wide, so the rendered `" {glyph} "` span occupies 4 cells
// (space + wide glyph + space). Prior chip_w=3 for both modes made the
// rect narrower than the glyph AND advanced the next chip start under
// the previous chip's trailing space, so clicks landed 1-N cells right
// of the visible icon. Match the actual rendered width per-mode.
let chip_w = if nerd { 4usize } else { 3usize };
let min_separation = 1usize;
let chip_count = {
let mut n = chips.len();
while n > 0 && label_used + min_separation + n * chip_w > width {
n -= 1;
}
n
};
let chips_used = chip_count * chip_w;
let pad = width.saturating_sub(label_used + chips_used);
let mut spans: Vec<Span<'static>> = Vec::with_capacity(1 + chip_count);
spans.push(Span::styled(" ".repeat(pad), Style::default().bg(rail_bg)));
let cluster_start_x = header_rect.x + (label_used + pad) as u16;
for (i, (glyph_nerd, glyph_ascii, cmd_id, fg)) in chips.iter().take(chip_count).enumerate() {
let glyph = if nerd { *glyph_nerd } else { *glyph_ascii };
spans.push(Span::styled(
format!(" {glyph} "),
Style::default().fg(*fg).bg(chip_bg),
));
let chip_x = cluster_start_x + (i * chip_w) as u16;
app.rects.tree_icon_buttons.push((
Rect {
x: chip_x,
y: header_rect.y,
width: chip_w as u16,
height: 1,
},
*cmd_id,
));
}
spans
}
/// Single right-aligned `+ repo` chip on its own row — sits below the
/// last workspace section's content, above the GIT separator. Replaces
/// the old top-of-rail "add workspace" chip.
fn draw_add_repo_row(
frame: &mut Frame,
app: &mut App,
area: Rect,
y: u16,
nerd: bool,
rail_bg: ratatui::style::Color,
) {
let width = area.width as usize;
let glyph = if nerd { "\u{F0419}" } else { "+" };
// 2026-06-24 user feedback: bare `+` chip sitting too close to
// the last workspace row + no text label meant the affordance
// was easy to miss. Two changes:
// - Paint a 1-row blank gap above this row (handled at the
// CALL SITE — bump `y` before drawing).
// - Show the glyph + a dim " Add workspace" label so the
// button telegraphs what it does.
let label = " Add workspace";
let chip_glyph_w = if nerd { 2usize } else { 1usize };
let label_w = label.chars().count();
let right_margin = 1usize;
let total = chip_glyph_w + label_w + right_margin;
if width < total + 1 {
return;
}
let pad = width.saturating_sub(total);
let row_rect = Rect {
x: area.x,
y,
width: area.width,
height: 1,
};
frame.render_widget(
Paragraph::new(Line::from(vec![
Span::styled(" ".repeat(pad), Style::default().bg(rail_bg)),
Span::styled(
glyph.to_string(),
Style::default().fg(theme::cur().green).bg(rail_bg),
),
Span::styled(
label.to_string(),
Style::default().fg(theme::cur().comment).bg(rail_bg),
),
])),
row_rect,
);
// Click rect spans the glyph + the label so the user can hit
// either part.
app.rects.tree_icon_buttons.push((
Rect {
x: area.x + pad as u16,
y,
width: (chip_glyph_w + label_w) as u16,
height: 1,
},
"view.add_workspace",
));
}
/// Original-config indices of the integration icons that should
/// render in the sidebar — built-ins always show; `:term X`
/// entries only show when `X` is detected on PATH or a well-known
/// install dir. Preserving the original index matters because the
/// hover/click rect map uses it to look the icon up again.
fn visible_integration_indices(app: &App) -> Vec<usize> {
// design-critic Issue 1 — palette-bar and rail must apply the
// SAME filter or the user gets ghosts (chip shows in one
// surface but not the other). Both surfaces now gate on
// (a) `enabled=true` AND (b) binary present (or built-in).
app.config
.ui
.integration_icons
.iter()
.enumerate()
.filter_map(|(i, ic)| {
if !ic.enabled {
return None;
}
match crate::integration_detect::integration_binary_for_command(&ic.command) {
None => Some(i), // built-in palette command — always available
Some(bin) if crate::integration_detect::is_binary_installed(bin) => Some(i),
Some(_) => None,
}
})
.collect()
}
/// Render the INTEGRATIONS section: a `> INTEGRATIONS` header (using
/// the same chevron + label pattern as GIT) followed by a grid of
/// plain-glyph icons. Each icon row is `chip_w` cells per slot; no
/// chip background — just colored glyphs spaced inside the rail.
fn draw_integration_section(
frame: &mut Frame,
app: &mut App,
area: Rect,
start_y: u16,
height: u16,
nerd: bool,
rail_bg: ratatui::style::Color,
) {
if height == 0 {
return;
}
let t = theme::cur();
let width = area.width as usize;
// Header row: `> INTEGRATIONS …… + `
// (the `+` chip on the right mirrors the GIT section's add-repo
// chip — clicking it opens the discovery overlay.)
// 2026-07-03 — dropped the `+` chip that opened the discovery
// overlay. The activity-bar side panel (Installed / Marketplace
// tabs, filter, per-row Enable/Edit/Move-up/Remove menu) already
// covers browse + enable + edit + install, so the overlay was
// just a redundant second copy. The `integrations.add` command
// is still callable from the palette for muscle-memory users.
let triangle = app.config.ui.expand_indicator == "triangle";
let chev = section_chev_with_pref(app.integration_section_expanded, nerd, triangle);
let chev_str = format!(" {chev} ");
let label = "INTEGRATIONS".to_string();
let used = chev_str.chars().count() + label.chars().count();
let pad = width.saturating_sub(used);
let header_rect = Rect {
x: area.x,
y: start_y,
width: area.width,
height: 1,
};
frame.render_widget(
Paragraph::new(Line::from(vec![
Span::styled(chev_str, Style::default().fg(t.comment).bg(rail_bg)),
Span::styled(
label,
Style::default()
.fg(t.fg)
.bg(rail_bg)
.add_modifier(Modifier::BOLD),
),
Span::styled(" ".repeat(pad), Style::default().bg(rail_bg)),
])),
header_rect,
);
// Whole header row toggles collapse now that the `+` chip is
// gone (no need to reserve trailing cells for a separate hit
// rect).
app.rects.integration_section_toggle = Some(Rect {
x: area.x,
y: start_y,
width: area.width,
height: 1,
});
let max_y = start_y + height;
// ── Collapsed: a horizontal row of icon-only chips below the
// header. Each chip is 4 cells wide; the wide-glyph rows
// (Claude / Codex) trim a trailing space to keep the visual
// cell-count consistent with 1-cell glyphs.
if !app.integration_section_expanded {
// Only render icons whose underlying binary is detected on
// PATH / well-known dirs (built-ins always pass). The original
// config index is preserved so click/hover rect lookups still
// resolve to the right `integration_icons[i]` entry.
let visible = visible_integration_indices(app);
let n = visible.len();
if n == 0 {
// #polish 2026-07-06 — expanded-empty hint row (paints
// when there ARE configured integrations but none of
// their binaries detected on PATH). Explains why the
// section reads empty.
if start_y + 1 < max_y {
let hint_rect = Rect {
x: area.x,
y: start_y + 1,
width: area.width,
height: 1,
};
frame.render_widget(
Paragraph::new(Line::from(vec![
Span::styled(" ", Style::default().bg(rail_bg)),
Span::styled(
"no binaries on PATH",
Style::default()
.fg(t.comment)
.bg(rail_bg)
.add_modifier(Modifier::DIM),
),
]))
.style(Style::default().bg(rail_bg)),
hint_rect,
);
}
return;
}
const CHIP_W: usize = 4;
let per_row = (width / CHIP_W).max(1);
let icons: Vec<(usize, String, String, String)> = visible
.iter()
.map(|&i| {
let ic = &app.config.ui.integration_icons[i];
(i, ic.glyph.clone(), ic.fallback.clone(), ic.color.clone())
})
.collect();
for (row_y, chunk) in (start_y + 1..).zip(icons.chunks(per_row)) {
if row_y >= max_y {
break;
}
let mut spans: Vec<Span<'static>> = Vec::with_capacity(chunk.len() + 1);
for (slot_i, (i, glyph, fallback, color)) in chunk.iter().enumerate() {
let g = if nerd {
glyph.as_str()
} else {
fallback.as_str()
};
let fg = crate::ui::theme::color_from_slot(color.as_str(), &t);
// Same wide-glyph trick used in the expanded layout:
// Claude / Codex glyphs render 2-cell wide, so drop a
// trailing space to keep the visual chip width
// consistent.
let wide_glyph = matches!(
glyph.as_str(),
"\u{F8B0}" | "\u{F8B1}" | "\u{F1E00}" | "\u{F1E01}"
);
let chip_text = if wide_glyph {
format!(" {g} ")
} else {
format!(" {g} ")
};
spans.push(Span::styled(chip_text, Style::default().fg(fg).bg(rail_bg)));
let chip_x = area.x + (slot_i * CHIP_W) as u16;
app.rects.integration_icon_rects.push((
Rect {
x: chip_x,
y: row_y,
width: CHIP_W as u16,
height: 1,
},
*i,
));
}
let used = chunk.len() * CHIP_W;
spans.push(Span::styled(
" ".repeat(width.saturating_sub(used)),
Style::default().bg(rail_bg),
));
let row_rect = Rect {
x: area.x,
y: row_y,
width: area.width,
height: 1,
};
frame.render_widget(Paragraph::new(Line::from(spans)), row_rect);
}
return;
}
// ── Expanded: one icon per row with its label, full width.
// The grid layout drifts out of alignment with Nerd-Font icons
// that render as 2-cell-wide glyphs (PUA + MDI codepoints in
// non-Mono variants), causing tooltips to attach to the wrong
// icon — but the vertical layout sidesteps that since each row
// only contains one icon. Each row is also wider, so the
// human-readable name fits next to the glyph — easier to scan
// than a 7-glyph chip grid.
//
// Filtering note: same as the collapsed view, only render rows
// whose binary is installed (or built-in palette commands). The
// original config index is preserved for the click rect.
let visible = visible_integration_indices(app);
let icons: Vec<(usize, String, String, String, String)> = visible
.iter()
.map(|&i| {
let ic = &app.config.ui.integration_icons[i];
let label = ic.label.clone().unwrap_or_else(|| ic.id.clone());
(
i,
ic.glyph.clone(),
ic.fallback.clone(),
ic.color.clone(),
label,
)
})
.collect();
for (row_y, (i, glyph, fallback, color, label)) in (start_y + 1..).zip(icons.iter()) {
if row_y >= max_y {
break;
}
let g = if nerd {
glyph.as_str()
} else {
fallback.as_str()
};
let fg = crate::ui::theme::color_from_slot(color.as_str(), &t);
// 2-cell left indent so INTEGRATIONS rows visually nest under
// the section header (matches the GIT section's ` marker `
// indent). Single-space gap after the glyph keeps the
// icon-to-label spacing uniform across wide / narrow glyphs.
let icon_part = format!(" {g} ");
// Truncate the label to fit the rail width (icon takes 4
// cells, leaving width - 4 for the label).
let label_cells = width.saturating_sub(icon_part.chars().count());
let label_display: String = label.chars().take(label_cells).collect();
let used = icon_part.chars().count() + label_display.chars().count();
let pad = width.saturating_sub(used);
let spans = vec![
Span::styled(icon_part, Style::default().fg(fg).bg(rail_bg)),
Span::styled(label_display, Style::default().fg(t.fg).bg(rail_bg)),
Span::styled(" ".repeat(pad), Style::default().bg(rail_bg)),
];
let row_rect = Rect {
x: area.x,
y: row_y,
width: area.width,
height: 1,
};
frame.render_widget(Paragraph::new(Line::from(spans)), row_rect);
// The hit-rect is the WHOLE row — clicking the label or the
// icon fires the integration's command.
app.rects.integration_icon_rects.push((row_rect, *i));
}
}
/// Return the section-header expand glyph, honoring `[ui]
/// expand_indicator`.
/// 2026-08-18 (#970) — R8 tester finding: setting
/// `expand_indicator = "triangle"` on non-tree render sites already
/// swapped via `expand_glyph()` (ui/mod.rs), but the file tree kept
/// its chevron helper hardcoded to chevrons. This helper takes the
/// pref and returns the small triangle glyphs (`▾` / `▸`) when
/// `use_triangle` is true, matching the other render sites.
fn section_chev_with_pref(expanded: bool, nerd: bool, use_triangle: bool) -> &'static str {
if use_triangle {
return if expanded { "▾" } else { "▸" };
}
// 2026-07-12 — the Unicode fallback also upgrades to the
// BLACK triangles (`▼` / `▶`) so the ascii_icons path stays
// visibly larger than the small `▾` / `▸` variants when the
// Nerd Font's `menu-down` / `menu-right` isn't available.
if expanded {
if nerd { CHEVRON_OPEN } else { "▼" }
} else if nerd {
CHEVRON_CLOSED
} else {
"▶"
}
}
/// qa-feature 2026-07-01 — Draw the PRIMARY workspace section at
/// `start_y` (header + optional expanded file list). Returns the
/// row past the last one drawn. Split out from the old top-of-tree
/// path so the caller can position the primary at any slot in the
/// unified `primary + extras` position list, not just row 0.
fn draw_primary_workspace_section(
frame: &mut Frame,
app: &mut App,
area: Rect,
start_y: u16,
nerd: bool,
rail_bg: ratatui::style::Color,
) -> u16 {
let area_end = area.y + area.height;
if start_y >= area_end {
return start_y;
}
let ws_name = app
.workspace
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("workspace")
.to_string();
let triangle = app.config.ui.expand_indicator == "triangle";
let chev = section_chev_with_pref(app.tree_root_expanded, nerd, triangle);
let chev_str = format!(" {chev} ");
const CURRENT_DOT_W: usize = 2;
const CHIP_RESERVE: usize = 5 * 3 + 1;
let chrome_used = chev_str.chars().count() + CURRENT_DOT_W + CHIP_RESERVE;
let max_name_w = (area.width as usize).saturating_sub(chrome_used);
let ws_name = crate::ui::clip_to_cells(&ws_name, max_name_w.max(4));
let header_used = chev_str.chars().count() + CURRENT_DOT_W + ws_name.chars().count();
let header_rect = Rect {
x: area.x,
y: start_y,
width: area.width,
height: 1,
};
let chip_spans = workspace_header_chips(app, header_rect, header_used, nerd, rail_bg);
let name_x = area.x + chev_str.chars().count() as u16 + CURRENT_DOT_W as u16;
app.rects.workspace_name_rect = Some(Rect {
x: name_x,
y: start_y,
width: ws_name.chars().count() as u16,
height: 1,
});
// #polish 2026-07-06 — italicize the workspace name when
// hidden files are visible, so users see the mode at a
// glance. Bold + italic combined stays legible; italic alone
// would fight the bold weight the header uses.
let mut name_style = Style::default()
.fg(theme::cur().green)
.bg(rail_bg)
.add_modifier(Modifier::BOLD);
if app.tree.show_hidden {
name_style = name_style.add_modifier(Modifier::ITALIC);
}
let mut spans = vec![Span::styled(
chev_str,
Style::default().fg(theme::cur().comment).bg(rail_bg),
)];
// R6 R2 opt-out 2026-08-09 — `[ui] show_workspace_dots = false`
// suppresses the `● ` / `○ ` markers to the left of workspace-
// root rows. Row still expands/collapses via the chevron; the
// active-vs-inactive distinction is signaled by the label's
// color/weight (bold green for active — set below).
if app.config.ui.show_workspace_dots {
spans.push(Span::styled(
"● ",
Style::default().fg(theme::cur().green).bg(rail_bg),
));
}
spans.push(Span::styled(ws_name.clone(), name_style));
spans.extend(chip_spans);
frame.render_widget(Paragraph::new(Line::from(spans)), header_rect);
app.rects.tree_toggle = Some(header_rect);
// File list — only when the primary is expanded and there's room.
let mut next_y = start_y + 1;
if app.tree_root_expanded && next_y < area_end {
let body_area = Rect {
x: area.x,
y: area.y,
width: area.width,
height: area_end.saturating_sub(area.y),
};
next_y = draw_workspace_files(frame, app, body_area, next_y, nerd);
}
next_y
}
/// Draw the WORKSPACE section's file list starting at `start_y`; returns the
/// row immediately past the last one drawn (so the GIT section follows on).
fn draw_workspace_files(
frame: &mut Frame,
app: &mut App,
area: Rect,
start_y: u16,
nerd: bool,
) -> u16 {
let rail_bg = theme::cur().bg_darker;
let width = area.width as usize;
let avail = (area.y + area.height).saturating_sub(start_y);
if avail == 0 {
return start_y;
}
// The outer layout in `draw()` already carves out GIT + INTEGRATIONS
// heights from the workspace area before passing it in here, so
// `avail` is exactly the workspace's allotted height. Earlier code
// tried to reserve a chunk inside this fn for GIT too — that
// double-counting left a visible empty zone above INTEGRATIONS
// when GIT was expanded (file list stopped short of `ws_end_y`).
let h = avail as usize;
if h == 0 {
return start_y;
}
let mut inner = Rect {
x: area.x,
y: start_y,
width: area.width,
height: h as u16,
};
// #polish 2026-07-07 — track the total rows consumed BEFORE the
// file list (filter + `..` up-nav) so the returned `next_y` is
// `start_y + shift + drew`, not just `start_y + drew`. Was:
// callers (`+ Add workspace` row, extra-workspace section
// headers, etc.) landed 1–2 rows too high when both prelude
// rows were visible, overlapping the tail of the tree body.
let mut shift: u16 = 0;
// Filter line — when the tree's in filter mode or has a sticky filter,
// reserve the top row of the tree section for a `/ <query>` input.
let show_filter = app.tree.filter_mode || !app.tree.filter.is_empty();
if show_filter && inner.height >= 2 {
let t = theme::cur();
let cursor_glyph = if app.tree.filter_mode { "█" } else { "" };
let line = Line::from(vec![
Span::styled(" / ", Style::default().fg(t.yellow).bg(rail_bg)),
Span::styled(
app.tree.filter.clone(),
Style::default().fg(t.fg).bg(rail_bg),
),
Span::styled(
cursor_glyph.to_string(),
Style::default().fg(t.yellow).bg(rail_bg),
),
]);
let filter_rect = Rect {
x: inner.x,
y: inner.y,
width: inner.width,
height: 1,
};
frame.render_widget(
Paragraph::new(line).style(Style::default().bg(rail_bg)),
filter_rect,
);
inner = Rect {
x: inner.x,
y: inner.y + 1,
width: inner.width,
height: inner.height - 1,
};
shift += 1;
}
// `..` up-navigation row — always sits above the file list so
// users can climb out of the current workspace root without the
// "Add workspace" prompt. Hidden when we're at filesystem root
// (nothing above) OR in the empty-workspace splash state (its
// own layout owns the whole rect). 2026-07-07.
let show_up = app.workspace.parent().is_some() && !is_empty_workspace(app);
if show_up && inner.height >= 2 {
let t = theme::cur();
let parent_name = app
.workspace
.parent()
.and_then(|p| p.file_name())
.and_then(|n| n.to_str())
.map(|s| s.to_string())
.unwrap_or_else(|| "/".to_string());
let clipped_parent = crate::ui::clip_to_cells(
&parent_name,
(inner.width as usize).saturating_sub(6).max(4),
);
let up_line = Line::from(vec![
Span::styled(" ", Style::default().bg(rail_bg)),
Span::styled(
"..",
Style::default()
.fg(t.comment)
.bg(rail_bg)
.add_modifier(Modifier::BOLD),
),
Span::styled(" ", Style::default().bg(rail_bg)),
Span::styled(clipped_parent, Style::default().fg(t.comment).bg(rail_bg)),
]);
let up_rect = Rect {
x: inner.x,
y: inner.y,
width: inner.width,
height: 1,
};
frame.render_widget(Paragraph::new(up_line), up_rect);
app.rects.tree_up_row = Some(up_rect);
inner = Rect {
x: inner.x,
y: inner.y + 1,
width: inner.width,
height: inner.height - 1,
};
shift += 1;
}
app.rects.tree = Some(inner);
let h = inner.height as usize;
if h == 0 {
return start_y + shift + inner.height;
}
// Empty-workspace state: when mnml is launched without a real
// workspace (workspace path == $HOME), show a vscode-style empty
// panel with `Open file` / `Open folder` actions instead of the
// tree contents. Registers click-rects on tree_icon_buttons so
// mouse handling fires the same commands as the keychords.
if is_empty_workspace(app) {
draw_empty_workspace_state(frame, app, inner);
return start_y + shift + inner.height;
}
let rows = app.tree.visible_rows();
let cursor = app.tree.cursor();
if cursor < app.tree.scroll {
app.tree.scroll = cursor;
} else if cursor >= app.tree.scroll + h {
app.tree.scroll = cursor + 1 - h;
}
let max_scroll = rows.len().saturating_sub(h.min(rows.len()));
app.tree.scroll = app.tree.scroll.min(max_scroll);
app.rects.tree_scroll = app.tree.scroll;
let git_files = &app.git.snapshot().files;
let focused = app.focus == Focus::Tree && app.rail_section == RailSection::Workspace;
// Pre-compute a per-row "is this a repo dir?" lookup for the multi-repo
// case. Only check depth-0 dirs (sub-repos aren't supported by
// discover_repos and matching wouldn't fire), and only when there's
// more than one repo (single-repo workspaces — including ones where
// the workspace itself is the repo — don't get repo decoration so
// the tree looks unchanged).
let multi_repo = app.repos.len() > 1;
let active_repo_path = app.repos.get(app.active_repo).map(|r| r.path.clone());
// Reserve the rightmost column for a scrollbar when the tree overflows
// its viewport (matches the list-pane convention — see `ui::scrollbar`).
let needs_sb = rows.len() > h;
let sb_w: u16 = if needs_sb { 1 } else { 0 };
let mut lines: Vec<Line> = Vec::with_capacity(h);
const ROOT_INDENT: &str = " ";
let triangle = app.config.ui.expand_indicator == "triangle";
for (vi, row) in rows.iter().enumerate().skip(app.tree.scroll).take(h) {
let is_cursor = vi == cursor;
let is_repo_row = multi_repo
&& row.is_dir
&& row.depth == 0
&& app.repos.iter().any(|r| r.path == row.path);
let is_active_repo = is_repo_row && active_repo_path.as_ref() == Some(&row.path);
let (glyph, icon_color) = if is_repo_row {
if nerd {
if row.is_expanded {
icons::REPO_OPEN
} else {
icons::REPO_CLOSED
}
} else if row.is_expanded {
icons::REPO_OPEN_ASCII
} else {
icons::REPO_CLOSED_ASCII
}
} else {
icons::for_path(&row.path, row.is_dir, row.is_expanded, nerd)
};
// #970 f/u (2026-08-20) — split the leading ROOT_INDENT off
// from the depth-based indent so the leftmost pad col paints
// in rail_bg regardless of cursor state. Without this the
// row-highlight gray on a selected row bled into the col
// immediately right of the activity bar, reading as "the
// highlight is stuck onto the activity-bar column". Users
// want that leading col to keep the panel's own dark bg.
let depth_indent = " ".repeat(row.depth);
// Split chevron + icon so the chevron renders in a muted grey
// (VS Code / NvChad tree style) while the folder/file icon keeps
// its devicon color.
let (chev_part, icon_part) = if nerd && row.is_dir {
let c = section_chev_with_pref(row.is_expanded, nerd, triangle);
(format!("{depth_indent}{c} "), format!("{glyph} "))
} else if nerd {
// File row — pad the chevron column with spaces so icons
// align with sibling dir rows.
(format!("{depth_indent} "), format!("{glyph} "))
} else {
(depth_indent.clone(), format!("{glyph} "))
};
let prefix_width =
ROOT_INDENT.chars().count() + chev_part.chars().count() + icon_part.chars().count();
let git_state = if row.is_dir {
None
} else {
git_files.get(&row.path).copied()
};
// #polish 2026-07-06 — dirty-in-editor detection. Walks
// panes for an Editor buffer whose path matches this row
// and has unsaved changes. When true, the badge letter
// gets replaced with `●` (dot) so users see it needs a
// save. Same signal VS Code shows on tree rows.
let is_dirty_in_editor = !row.is_dir
&& app.panes.iter().any(|p| match p {
crate::pane::Pane::Editor(b) => b.dirty && b.path.as_ref() == Some(&row.path),
_ => false,
});
let name_color = if is_repo_row {
theme::cur().yellow
} else if row.is_dir {
theme::cur().blue
} else {
match git_state {
Some(FileState::Modified) => theme::cur().yellow,
Some(FileState::Staged | FileState::Untracked) => theme::cur().green,
Some(FileState::Conflicted) => theme::cur().red,
None => theme::cur().fg,
}
};
let bg = row_bg(is_cursor, focused, rail_bg);
let mut name_style = Style::default().fg(name_color).bg(bg);
if row.is_dir || (is_cursor && focused) {
name_style = name_style.add_modifier(Modifier::BOLD);
}
// Non-active repo dirs render slightly dimmed to make the active
// one pop visually (matches the `●` / `○` convention).
if is_repo_row && !is_active_repo {
name_style = name_style.add_modifier(Modifier::DIM);
}
// Hidden entries (filename starts with `.`) render dimmed when
// they're visible — only happens when `show_hidden = true`, but
// the dim hint is useful regardless to tell users "this is a
// dotfile / dot-dir".
let is_hidden = row.name.starts_with('.');
if is_hidden {
name_style = name_style.add_modifier(Modifier::DIM);
}
let prefix_color = if is_repo_row {
theme::cur().yellow
} else if row.is_dir {
// TEMP: yellow folder icons (test); was `theme::cur().blue`.
// Restore the blue branch when reverting.
theme::cur().yellow
} else {
icon_color
};
// Right-aligned 1-char git-state badge (vim-fugitive style): M / A / ? / !.
// Reserves 2 trailing cells (`<letter> `) when there's a state to show.
// #polish 2026-07-06 — dirty-in-editor wins over git state.
// A `●` badge means "unsaved edits in mnml"; git badges
// reflect on-disk state which the editor will change on
// save. Users care more about the pending save first.
let (badge, badge_color) = if is_dirty_in_editor {
("●", theme::cur().orange)
} else {
match git_state {
Some(FileState::Modified) => ("M", theme::cur().yellow),
Some(FileState::Staged) => ("A", theme::cur().green),
Some(FileState::Untracked) => ("?", theme::cur().green),
Some(FileState::Conflicted) => ("!", theme::cur().red),
None => ("", theme::cur().fg),
}
};
let badge_width = if badge.is_empty() { 0 } else { 2 };
// Repo dirs get a leading `● ` (active) or `○ ` (non-active) marker
// before the name — same convention the git rail uses for branches.
// Reserves 2 cells regardless of state so name columns align across
// active and non-active repo rows.
// R6 R2 opt-out — same `show_workspace_dots` gate as the
// primary workspace-header row above.
let (repo_marker, repo_marker_color) = if is_repo_row && app.config.ui.show_workspace_dots {
if is_active_repo {
("● ", theme::cur().green)
} else {
("○ ", theme::cur().comment)
}
} else {
("", theme::cur().fg)
};
let repo_marker_width = repo_marker.chars().count();
let used = prefix_width + repo_marker_width + row.name.chars().count() + badge_width;
// Keep the badge clear of the reserved scrollbar column.
let pad = width.saturating_sub(sb_w as usize).saturating_sub(used);
// #970 f/u (2026-08-20) — leading 1 cell of ROOT_INDENT
// painted with rail_bg so the highlight bg never bleeds
// into the col immediately right of the activity bar.
// Second cell keeps row_bg so the highlight still reads as
// wide as the row — pulling both cells off looked over-
// trimmed (2026-08-20 user follow-up).
let mut spans = vec![
Span::styled(" ", Style::default().bg(rail_bg)),
Span::styled(" ", Style::default().bg(bg)),
Span::styled(chev_part, Style::default().fg(theme::cur().comment).bg(bg)),
Span::styled(icon_part, Style::default().fg(prefix_color).bg(bg)),
];
if !repo_marker.is_empty() {
spans.push(Span::styled(
repo_marker,
Style::default().fg(repo_marker_color).bg(bg),
));
}
spans.push(Span::styled(row.name.clone(), name_style));
spans.push(Span::styled(" ".repeat(pad), Style::default().bg(bg)));
if !badge.is_empty() {
spans.push(Span::styled(
format!("{badge} "),
Style::default().fg(badge_color).bg(bg),
));
}
lines.push(Line::from(spans));
}
let drew = lines.len() as u16;
let body = Rect {
width: inner.width.saturating_sub(sb_w),
..inner
};
frame.render_widget(Paragraph::new(lines), body);
if needs_sb {
let sb_area = Rect {
x: inner.x + body.width,
y: inner.y,
width: sb_w,
height: inner.height,
};
crate::ui::scrollbar::paint_simple_scrollbar(
frame,
sb_area,
&theme::cur(),
rows.len(),
h,
app.tree.scroll,
);
// qa-feature 2026-07-01 — the visible scrollbar is 1
// cell wide, which is nearly impossible to grab with a
// mouse (user reported "can't drag"). Widen the click
// hit rect to include 1 cell to the left of the visible
// bar so the drag catches even when the click lands
// slightly off the exact column. The row padding always
// fills the cell right before the bar, so this doesn't
// steal clicks from filename text.
let hit_extra_left: u16 = 1;
let hit_x = sb_area.x.saturating_sub(hit_extra_left);
let hit_width = sb_area.x + sb_area.width - hit_x;
let hit_area = Rect {
x: hit_x,
y: sb_area.y,
width: hit_width,
height: sb_area.height,
};
app.rects.scrollbars.push(crate::app::ScrollbarHit {
area: hit_area,
pane_id: 0,
total: rows.len(),
viewport: h,
kind: crate::app::ScrollbarKind::Tree,
});
}
// Hover preview: when the cursor's on an image row and the cache
// is warm, paint a small card at the bottom-left of the tree area.
// The image escape lands post-`terminal.draw()` so it covers the
// qa-feature 2026-07-02 — tree image thumbnail removed
// entirely. When the user navigates to an image (via keyboard
// arrow or click), the full image already opens in a pane, so
// the small thumbnail on the rail was redundant either
// way. Callers left the `inner` unchanged; the thumbnail
// function is gone.
let _ = inner;
start_y + shift + drew
}
/// Draw one extra-workspace section starting at `start_y`. Renders a
/// collapsible `> name` header; if the section is expanded, renders a
/// file-list slot beneath it (bounded by available rail height minus
/// the pinned `Add workspace` chip + separator). Returns the row past
/// the last drawn.
fn draw_extra_workspace_section(
frame: &mut Frame,
app: &mut App,
area: Rect,
start_y: u16,
ws_idx: usize,
nerd: bool,
) -> u16 {
let rail_bg = theme::cur().bg_darker;
let width = area.width as usize;
let area_end = area.y + area.height;
if start_y >= area_end {
return start_y;
}
// qa-feature 2026-07-01 — separator between workspaces is now
// added by the caller (draw_tree_section's slot loop) so the
// primary + extras share a single stable ordering. This
// function now paints its header at `start_y` directly.
let header_y = start_y;
let (name, expanded) = {
let ws = &app.extra_workspaces[ws_idx];
(ws.name.clone(), ws.expanded)
};
let triangle = app.config.ui.expand_indicator == "triangle";
let chev = section_chev_with_pref(expanded, nerd, triangle);
let chev_str = format!(" {chev} ");
// qa-feature 2026-07-01 — extras no longer render the
// right-side action chip cluster. The `workspace_header_chips`
// helper pushes rects into `app.rects.tree_icon_buttons`
// keyed only by command id — not by workspace — so a click
// on an extra's chip would fire the command against the
// PRIMARY tree (and the `collapse` glyph on each extra row
// even read `app.tree.is_fully_collapsed()`, the primary's
// state, so all rows flipped together). Extras keep the
// left-side ○ + name + section chevron.
let name = crate::ui::clip_to_cells(&name, (area.width as usize).saturating_sub(4).max(4));
let header_rect = Rect {
x: area.x,
y: header_y,
width: area.width,
height: 1,
};
let mut spans = vec![Span::styled(
chev_str,
Style::default().fg(theme::cur().comment).bg(rail_bg),
)];
// R6 R2 opt-out — same gate as the primary/repo rows.
if app.config.ui.show_workspace_dots {
spans.push(Span::styled(
"○ ",
Style::default().fg(theme::cur().comment).bg(rail_bg),
));
}
spans.push(Span::styled(
name.clone(),
Style::default()
.fg(theme::cur().fg)
.bg(rail_bg)
.add_modifier(Modifier::BOLD),
));
frame.render_widget(Paragraph::new(Line::from(spans)), header_rect);
app.rects
.extra_workspace_toggles
.push((header_rect, ws_idx));
// qa-feature 2026-07-01 — register the `○` marker as its own
// click target so a click there promotes this extra to primary
// (same as right-click → Set as workspace). The dot sits right
// after the section chevron (` ▶ ` = 3 chars) and the marker
// itself is `○ ` = 2 chars.
// chev_str is ` ▶ ` / ` ▼ ` = 3 cells.
const CHEV_STR_W: u16 = 3;
let dot_rect = Rect {
x: area.x + CHEV_STR_W,
y: header_y,
width: 2,
height: 1,
};
app.rects
.extra_workspace_promote_dots
.push((dot_rect, ws_idx));
let _ = width;
if !expanded {
return header_y + 1;
}
let body_y = header_y + 1;
if body_y >= area_end {
return header_y + 1;
}
let avail = (area_end - body_y) as usize;
// qa-feature 2026-07-01 — reserve 2 rows at the bottom for
// the pinned `Add workspace` chip + its separator (the chip
// sits at `ws_end_y - 1`). Extras take the rest of the rail
// instead of a fixed 32-row cap (which left the tail of a
// tall terminal empty).
let reserved_for_add: usize = 2;
let h = avail.saturating_sub(reserved_for_add);
if h == 0 {
return body_y;
}
// qa-feature 2026-07-01 — extras render a scrollbar when
// their tree overflows. Prior to this the tree would just
// clip below the visible window and the user had no way to
// see there was more (nor to grab a scroll thumb).
let rows_precount = app.extra_workspaces[ws_idx].tree.visible_rows().len();
let needs_sb = rows_precount > h;
let sb_w: u16 = if needs_sb { 1 } else { 0 };
let body_rect = Rect {
x: area.x,
y: body_y,
width: area.width.saturating_sub(sb_w),
height: h as u16,
};
app.rects.extra_workspace_bodies.push((
body_rect,
ws_idx,
app.extra_workspaces[ws_idx].tree.scroll,
));
// Auto-scroll to keep the cursor in view. Matches the primary
// tree's behaviour in `draw_workspace_files`. Without this,
// `move_up`/`move_down` (driven by mouse wheel or arrow keys)
// changes the cursor but the visible window doesn't follow —
// so the user can scroll past the visible 12 rows and never
// see what they "scrolled" to.
let rows = app.extra_workspaces[ws_idx].tree.visible_rows();
let cursor = app.extra_workspaces[ws_idx].tree.cursor();
if cursor < app.extra_workspaces[ws_idx].tree.scroll {
app.extra_workspaces[ws_idx].tree.scroll = cursor;
} else if cursor >= app.extra_workspaces[ws_idx].tree.scroll + h {
app.extra_workspaces[ws_idx].tree.scroll = cursor + 1 - h;
}
let max_scroll = rows.len().saturating_sub(h.min(rows.len()));
let scroll = app.extra_workspaces[ws_idx].tree.scroll.min(max_scroll);
app.extra_workspaces[ws_idx].tree.scroll = scroll;
let multi_repo = app.repos.len() > 1;
let active_repo_path = app.repos.get(app.active_repo).map(|r| r.path.clone());
// Focus state for the cursor highlight: rail focused on the
// tree AND `focused_extra_ws` points at THIS workspace. The
// primary tree's `focused` checks Focus::Tree +
// RailSection::Workspace; we do the analogous check via the
// dedicated extra-workspace focus field.
let focused =
matches!(app.focus, crate::focus::Focus::Tree) && app.focused_extra_ws == Some(ws_idx);
let cursor = app.extra_workspaces[ws_idx].tree.cursor();
let triangle = app.config.ui.expand_indicator == "triangle";
let mut lines: Vec<Line> = Vec::with_capacity(h);
const ROOT_INDENT: &str = " ";
for (vi, row) in rows.iter().enumerate().skip(scroll).take(h) {
let is_cursor = vi == cursor;
let row_bg_col = row_bg(is_cursor, focused, rail_bg);
let is_repo_row = multi_repo
&& row.is_dir
&& row.depth == 0
&& app.repos.iter().any(|r| r.path == row.path);
let is_active_repo = is_repo_row && active_repo_path.as_ref() == Some(&row.path);
let (glyph, icon_color) = if is_repo_row {
if nerd {
if row.is_expanded {
icons::REPO_OPEN
} else {
icons::REPO_CLOSED
}
} else if row.is_expanded {
icons::REPO_OPEN_ASCII
} else {
icons::REPO_CLOSED_ASCII
}
} else {
icons::for_path(&row.path, row.is_dir, row.is_expanded, nerd)
};
// #970 f/u (2026-08-20) — see draw_workspace_files.
let depth_indent = " ".repeat(row.depth);
let (chev_part, icon_part) = if nerd && row.is_dir {
let c = section_chev_with_pref(row.is_expanded, nerd, triangle);
(format!("{depth_indent}{c} "), format!("{glyph} "))
} else if nerd {
(format!("{depth_indent} "), format!("{glyph} "))
} else {
(depth_indent.clone(), format!("{glyph} "))
};
let prefix_width =
ROOT_INDENT.chars().count() + chev_part.chars().count() + icon_part.chars().count();
let name_color = if is_repo_row {
theme::cur().yellow
} else if row.is_dir {
theme::cur().blue
} else {
theme::cur().fg
};
let mut name_style = Style::default().fg(name_color).bg(row_bg_col);
if row.is_dir || (is_cursor && focused) {
name_style = name_style.add_modifier(Modifier::BOLD);
}
if is_repo_row && !is_active_repo {
name_style = name_style.add_modifier(Modifier::DIM);
}
if row.name.starts_with('.') {
name_style = name_style.add_modifier(Modifier::DIM);
}
let prefix_color = if is_repo_row {
theme::cur().yellow
} else if row.is_dir {
// TEMP: yellow folder icons (test); was `theme::cur().blue`.
// Restore the blue branch when reverting.
theme::cur().yellow
} else {
icon_color
};
// R6 R2 opt-out — same `show_workspace_dots` gate as the
// primary workspace-header row above.
let (repo_marker, repo_marker_color) = if is_repo_row && app.config.ui.show_workspace_dots {
if is_active_repo {
("● ", theme::cur().green)
} else {
("○ ", theme::cur().comment)
}
} else {
("", theme::cur().fg)
};
let used = prefix_width + repo_marker.chars().count() + row.name.chars().count();
let pad_n = (width.saturating_sub(sb_w as usize)).saturating_sub(used);
// #970 f/u (2026-08-20) — 1 cell of rail_bg then 1 cell of
// row bg. See draw_workspace_files.
let mut spans = vec![
Span::styled(" ", Style::default().bg(rail_bg)),
Span::styled(" ", Style::default().bg(row_bg_col)),
Span::styled(
chev_part,
Style::default().fg(theme::cur().comment).bg(row_bg_col),
),
Span::styled(icon_part, Style::default().fg(prefix_color).bg(row_bg_col)),
];
if !repo_marker.is_empty() {
spans.push(Span::styled(
repo_marker,
Style::default().fg(repo_marker_color).bg(row_bg_col),
));
}
spans.push(Span::styled(row.name.clone(), name_style));
spans.push(Span::styled(
" ".repeat(pad_n),
Style::default().bg(row_bg_col),
));
lines.push(Line::from(spans));
}
let drew = lines.len() as u16;
frame.render_widget(Paragraph::new(lines), body_rect);
if needs_sb {
let sb_area = Rect {
x: body_rect.x + body_rect.width,
y: body_y,
width: sb_w,
height: h as u16,
};
crate::ui::scrollbar::paint_simple_scrollbar(
frame,
sb_area,
&theme::cur(),
rows_precount,
h,
scroll,
);
// Widen the click hit rect 1 cell to the left (padding
// fills that cell, so no text overlap) so the drag
// grabs even when the click lands slightly off-column.
let hit_extra_left: u16 = 1;
let hit_x = sb_area.x.saturating_sub(hit_extra_left);
let hit_width = sb_area.x + sb_area.width - hit_x;
let hit_area = Rect {
x: hit_x,
y: sb_area.y,
width: hit_width,
height: sb_area.height,
};
app.rects.scrollbars.push(crate::app::ScrollbarHit {
area: hit_area,
pane_id: 0,
total: rows_precount,
viewport: h,
kind: crate::app::ScrollbarKind::ExtraTree(ws_idx),
});
}
body_y + drew
}
/// Draw the GIT section: a "branches" sub-label, the branch rows, a
/// "worktrees" sub-label, the worktree rows. Sub-labels are dim, not
/// selectable. Records click-rects in `app.rects.git_rail_rows`.
fn draw_git_section(
frame: &mut Frame,
app: &mut App,
area: Rect,
start_y: u16,
_nerd: bool,
overflow_rows: u16,
) {
let rail_bg = theme::cur().bg_darker;
let width = area.width as usize;
let avail = (area.y + area.height).saturating_sub(start_y) as usize;
if avail == 0 {
return;
}
let focused = app.focus == Focus::Tree && app.rail_section == RailSection::Git;
let cursor_row = app.git_rail.cursor;
let nb = app.git_rail.branches.len();
let mut lines: Vec<Line> = Vec::with_capacity(avail);
let mut row_y = start_y;
let mut row_count_drawn: usize = 0; // counts only selectable rows
const INDENT: &str = " ";
// ── branches sub-section ──
if !app.git_rail.branches.is_empty() {
// Sub-label (dim, not selectable).
push_sublabel(&mut lines, "branches", width, rail_bg);
row_y += 1;
if (row_y - start_y) as usize >= avail {
frame.render_widget(Paragraph::new(lines), git_body_rect(area, start_y));
return;
}
// Cap to `BRANCH_LIST_CAP` when collapsed so a 100-branch
// monorepo doesn't drown the rail; user clicks the trailing
// `+ N more` row to expand.
let total_branches = app.git_rail.branches.len();
let cap = if app.git_branches_expanded {
total_branches
} else {
total_branches.min(BRANCH_LIST_CAP)
};
let always_show_current = !app.git_branches_expanded && total_branches > BRANCH_LIST_CAP;
for (i, br) in app.git_rail.branches.iter().enumerate() {
if (row_y - start_y) as usize >= avail {
break;
}
// When collapsed: render first `cap` branches PLUS the
// current branch (if it'd otherwise be hidden) so the
// user never loses sight of where they are.
let in_cap = i < cap;
let force_show = always_show_current && br.is_current && !in_cap;
if !in_cap && !force_show {
continue;
}
let is_cur_row = row_count_drawn == cursor_row;
let bg = row_bg(is_cur_row, focused, rail_bg);
let marker = if br.is_current { "●" } else { "○" };
let marker_color = if br.is_current {
theme::cur().green
} else {
theme::cur().fg
};
let name = &br.name;
let prefix = format!("{INDENT}{marker} ");
let used = prefix.chars().count() + name.chars().count();
let pad = width.saturating_sub(used);
let mut name_style = Style::default().fg(theme::cur().fg).bg(bg);
if br.is_current {
name_style = name_style.add_modifier(Modifier::BOLD);
}
lines.push(Line::from(vec![
Span::styled(prefix, Style::default().fg(marker_color).bg(bg)),
Span::styled(name.clone(), name_style),
Span::styled(" ".repeat(pad), Style::default().bg(bg)),
]));
app.rects.git_rail_rows.push((
Rect {
x: area.x,
y: row_y,
width: area.width,
height: 1,
},
GitRailHit::Branch(i),
));
row_y += 1;
row_count_drawn += 1;
}
// `+ N more` / `show less` toggle row (only when there's
// something to toggle).
if total_branches > BRANCH_LIST_CAP && (row_y - start_y) as usize <= avail {
let toggle_text = if app.git_branches_expanded {
" show less".to_string()
} else {
format!(" + {} more", total_branches - cap)
};
let pad = width.saturating_sub(toggle_text.chars().count());
lines.push(Line::from(vec![
Span::styled(
toggle_text,
Style::default()
.fg(theme::cur().comment)
.bg(rail_bg)
.add_modifier(Modifier::ITALIC),
),
Span::styled(" ".repeat(pad), Style::default().bg(rail_bg)),
]));
app.rects.git_rail_rows.push((
Rect {
x: area.x,
y: row_y,
width: area.width,
height: 1,
},
GitRailHit::ToggleBranches,
));
row_y += 1;
}
}
// ── worktrees sub-section ──
if !app.git_rail.worktrees.is_empty() && ((row_y - start_y) as usize) < avail {
push_sublabel(&mut lines, "worktrees", width, rail_bg);
row_y += 1;
for (i, wt) in app.git_rail.worktrees.iter().enumerate() {
if (row_y - start_y) as usize >= avail {
break;
}
let row_idx = nb + i;
let is_cur_row = row_idx == cursor_row;
let bg = row_bg(is_cur_row, focused, rail_bg);
let marker = if wt.is_current { "⤿" } else { "·" };
let marker_color = if wt.is_current {
theme::cur().yellow
} else {
theme::cur().fg
};
let label = if wt.label.is_empty() {
"(detached)".to_string()
} else {
wt.label.clone()
};
let dir = wt
.path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("?")
.to_string();
let shown = if label == dir || label.starts_with('(') {
label.clone()
} else {
format!("{label} ({dir})")
};
let prefix = format!("{INDENT}{marker} ");
let used = prefix.chars().count() + shown.chars().count();
let pad = width.saturating_sub(used);
let mut name_style = Style::default().fg(theme::cur().fg).bg(bg);
if wt.is_current {
name_style = name_style.add_modifier(Modifier::BOLD);
}
lines.push(Line::from(vec![
Span::styled(prefix, Style::default().fg(marker_color).bg(bg)),
Span::styled(shown, name_style),
Span::styled(" ".repeat(pad), Style::default().bg(bg)),
]));
app.rects.git_rail_rows.push((
Rect {
x: area.x,
y: row_y,
width: area.width,
height: 1,
},
GitRailHit::Worktree(i),
));
row_y += 1;
}
}
// ── pulls sub-section (open PRs / MRs for the current repo) ──
if !app.git_rail.pulls.is_empty() && ((row_y - start_y) as usize) < avail {
push_sublabel(&mut lines, "open prs", width, rail_bg);
row_y += 1;
let nb_and_nw = nb + app.git_rail.worktrees.len();
for (i, pr) in app.git_rail.pulls.iter().enumerate() {
if (row_y - start_y) as usize >= avail {
break;
}
let row_idx = nb_and_nw + i;
let is_cur_row = row_idx == cursor_row;
let bg = row_bg(is_cur_row, focused, rail_bg);
// Pick a per-host color so the glyph telegraphs which host the
// PR came from.
let host_color = match pr.host_tag {
"BB" => theme::cur().blue,
"GH" => theme::cur().fg,
"GL" => theme::cur().orange,
"AZ" => theme::cur().cyan,
_ => theme::cur().fg,
};
// The branch-marker convention: ● for the PR on the current branch,
// ○ otherwise — mirrors the branches sub-section.
let marker = if pr.is_current_branch { "●" } else { "○" };
// Truncate the title hard so wide titles don't blow out the row.
let avail_for_title =
width.saturating_sub(2 + 1 + 1 + pr.number_label.chars().count() + 1);
let title_disp = truncate_chars(&pr.title, avail_for_title);
let prefix = format!(" {marker} ");
let head = format!("{} ", pr.number_label);
let used = prefix.chars().count() + head.chars().count() + title_disp.chars().count();
let pad = width.saturating_sub(used);
let mut title_style = Style::default().fg(theme::cur().fg).bg(bg);
if pr.is_current_branch {
title_style = title_style.add_modifier(Modifier::BOLD);
}
lines.push(Line::from(vec![
Span::styled(prefix, Style::default().fg(host_color).bg(bg)),
Span::styled(head, Style::default().fg(host_color).bg(bg)),
Span::styled(title_disp, title_style),
Span::styled(" ".repeat(pad), Style::default().bg(bg)),
]));
app.rects.git_rail_rows.push((
Rect {
x: area.x,
y: row_y,
width: area.width,
height: 1,
},
GitRailHit::Pull(i),
));
row_y += 1;
}
}
// #polish 2026-07-06 — stashes + tags sub-sections. Both were
// palette-only before, hidden from mouse-first users. Rendered
// in the same shape as branches/worktrees.
let nb_and_nw = nb + app.git_rail.worktrees.len();
let npulls = app.git_rail.pulls.len();
// ── stashes sub-section ──
if !app.git_rail.stashes.is_empty() && ((row_y - start_y) as usize) < avail {
push_sublabel(&mut lines, "stashes", width, rail_bg);
row_y += 1;
for (i, st) in app.git_rail.stashes.iter().enumerate() {
if (row_y - start_y) as usize >= avail {
break;
}
let row_idx = nb_and_nw + npulls + i;
let is_cur_row = row_idx == cursor_row;
let bg = row_bg(is_cur_row, focused, rail_bg);
// Short label — `stash@{0} summary…`
let label = format!("{} {}", st.id, st.summary);
let prefix = format!("{INDENT}\u{1FAA3} "); // 🪣 stash bucket
let ascii_prefix = format!("{INDENT}s ");
let prefix_str = if _nerd {
prefix.as_str()
} else {
ascii_prefix.as_str()
};
let max_label = width.saturating_sub(prefix_str.chars().count());
let label_disp = truncate_chars(&label, max_label);
let used = prefix_str.chars().count() + label_disp.chars().count();
let pad = width.saturating_sub(used);
lines.push(Line::from(vec![
Span::styled(
prefix_str.to_string(),
Style::default().fg(theme::cur().purple).bg(bg),
),
Span::styled(label_disp, Style::default().fg(theme::cur().fg).bg(bg)),
Span::styled(" ".repeat(pad), Style::default().bg(bg)),
]));
app.rects.git_rail_rows.push((
Rect {
x: area.x,
y: row_y,
width: area.width,
height: 1,
},
GitRailHit::Stash(i),
));
row_y += 1;
}
}
// ── tags sub-section ──
let nstashes = app.git_rail.stashes.len();
if !app.git_rail.tags.is_empty() && ((row_y - start_y) as usize) < avail {
push_sublabel(&mut lines, "tags", width, rail_bg);
row_y += 1;
for (i, name) in app.git_rail.tags.iter().enumerate() {
if (row_y - start_y) as usize >= avail {
break;
}
let row_idx = nb_and_nw + npulls + nstashes + i;
let is_cur_row = row_idx == cursor_row;
let bg = row_bg(is_cur_row, focused, rail_bg);
let prefix = format!("{INDENT}\u{F02B2} "); // nerd-md-tag
let ascii_prefix = format!("{INDENT}# ");
let prefix_str = if _nerd {
prefix.as_str()
} else {
ascii_prefix.as_str()
};
let max_label = width.saturating_sub(prefix_str.chars().count());
let name_disp = truncate_chars(name, max_label);
let used = prefix_str.chars().count() + name_disp.chars().count();
let pad = width.saturating_sub(used);
lines.push(Line::from(vec![
Span::styled(
prefix_str.to_string(),
Style::default().fg(theme::cur().cyan).bg(bg),
),
Span::styled(name_disp, Style::default().fg(theme::cur().fg).bg(bg)),
Span::styled(" ".repeat(pad), Style::default().bg(bg)),
]));
app.rects.git_rail_rows.push((
Rect {
x: area.x,
y: row_y,
width: area.width,
height: 1,
},
GitRailHit::Tag(i),
));
row_y += 1;
}
}
if app.git_rail.is_empty() {
// Friendly placeholder so the user sees the section even outside a repo.
push_sublabel(&mut lines, "no git repo here", width, rail_bg);
}
// When content didn't fit (`overflow_rows > 0`), the last
// visible row becomes a `… N more` indicator so the user can
// tell they're looking at a clipped view. We replace the LAST
// line in `lines` (not append), otherwise the indicator itself
// would overflow. The displayed count accounts for the row the
// indicator occupies (one row of content is now an indicator
// row, so `overflow + 1` items are effectively hidden).
if overflow_rows > 0 && !lines.is_empty() {
let hidden = overflow_rows as usize + 1;
let s = format!(" … {hidden} more");
let pad = width.saturating_sub(s.chars().count());
let last_idx = lines.len() - 1;
lines[last_idx] = Line::from(vec![
Span::styled(
s,
Style::default()
.fg(theme::cur().comment)
.bg(rail_bg)
.add_modifier(Modifier::ITALIC),
),
Span::styled(" ".repeat(pad), Style::default().bg(rail_bg)),
]);
}
let body = git_body_rect(area, start_y);
frame.render_widget(Paragraph::new(lines), body);
}
fn truncate_chars(s: &str, max: usize) -> String {
if max == 0 {
return String::new();
}
let count = s.chars().count();
if count <= max {
return s.to_string();
}
if max <= 1 {
return s.chars().take(max).collect();
}
let mut out: String = s.chars().take(max - 1).collect();
out.push('…');
out
}
fn git_body_rect(area: Rect, start_y: u16) -> Rect {
Rect {
x: area.x,
y: start_y,
width: area.width,
height: area.height.saturating_sub(start_y - area.y),
}
}
fn push_sublabel(lines: &mut Vec<Line>, text: &str, width: usize, bg: ratatui::style::Color) {
let s = format!(" {text}");
let pad = width.saturating_sub(s.chars().count());
lines.push(Line::from(vec![
Span::styled(s, Style::default().fg(theme::cur().comment).bg(bg)),
Span::styled(" ".repeat(pad), Style::default().bg(bg)),
]));
}
fn row_bg(is_cursor: bool, focused: bool, rail_bg: ratatui::style::Color) -> ratatui::style::Color {
if is_cursor {
if focused {
theme::cur().bg2
} else {
theme::cur().bg
}
} else {
rail_bg
}
}
/// True when mnml was launched without a real workspace — its
/// workspace path equals the OS home directory. Triggers the
/// vscode-style empty-state panel in the file tree area so the
/// rail doesn't show the user's entire $HOME as if it were a
/// project.
fn is_empty_workspace(app: &App) -> bool {
let Some(home) = std::env::var_os("HOME") else {
return false;
};
let home = std::path::PathBuf::from(home);
// Canonicalize both sides — `app.workspace` is already canonical
// (set via canonicalize() at launch / add_workspace_runtime), so
// we only have to canonicalize $HOME to match.
let home_c = std::fs::canonicalize(&home).unwrap_or(home);
app.workspace == home_c
}
/// Paint the vscode-style empty-state panel into `inner`. Lines:
/// No workspace open
/// (blank)
/// ▸ Open file… (registers a click rect → view.discovery)
/// ▸ Open folder… (registers a click rect → view.add_workspace)
fn draw_empty_workspace_state(frame: &mut Frame, app: &mut App, inner: Rect) {
let t = theme::cur();
let rail_bg = t.bg_darker;
// Build the action list. Include "Open default workspace" only
// when one is configured and it's a different path than the
// current (empty) workspace — otherwise the entry would be a
// no-op.
let mut lines: Vec<(String, Option<&'static str>, ratatui::style::Color)> = vec![
("No workspace open".to_string(), None, t.comment),
(String::new(), None, t.comment),
("▸ Open file…".to_string(), Some("view.discovery"), t.fg),
(
"▸ Open folder…".to_string(),
Some("view.add_workspace"),
t.fg,
),
(
"▸ Switch workspace…".to_string(),
Some("view.switch_workspace"),
t.fg,
),
(
"▸ Manage workspaces…".to_string(),
Some("view.manage_workspaces"),
t.fg,
),
];
if let Some(dw) = &app.config.default_workspace
&& dw != &app.workspace
{
let label = dw
.file_name()
.map(|s| s.to_string_lossy().into_owned())
.unwrap_or_else(|| dw.to_string_lossy().into_owned());
lines.push((
format!("▸ Open default workspace ({label})"),
Some("view.open_default_workspace"),
t.fg,
));
}
for (i, (text, cmd, color)) in lines.iter().enumerate() {
let y = inner.y + i as u16;
if y >= inner.y + inner.height {
break;
}
let row = Rect {
x: inner.x,
y,
width: inner.width,
height: 1,
};
let style = Style::default().fg(*color).bg(rail_bg);
let para_text = format!(" {text}");
frame.render_widget(
Paragraph::new(Line::from(Span::styled(para_text, style)))
.style(Style::default().bg(rail_bg)),
row,
);
if let Some(cmd_id) = cmd {
app.rects.tree_icon_buttons.push((row, *cmd_id));
}
}
}
#[cfg(test)]
mod tests {
use super::*;
/// Render-assertion: paint the rail into a `TestBackend` and check
/// that the workspace's files actually land in the file tree.
#[test]
fn draw_paints_workspace_files() {
use ratatui::Terminal;
use ratatui::backend::TestBackend;
let d = tempfile::tempdir().unwrap();
let ws = d.path().to_path_buf();
// Create the files before App::new so the tree picks them up.
std::fs::write(ws.join("alpha.txt"), "a\n").unwrap();
std::fs::write(ws.join("beta.txt"), "b\n").unwrap();
let mut app = App::new(ws.clone(), crate::config::Config::default()).unwrap();
let mut term = Terminal::new(TestBackend::new(32, 24)).unwrap();
term.draw(|f| draw(f, &mut app, f.area())).unwrap();
let buf = term.backend().buffer();
let mut screen = String::new();
for y in 0..buf.area.height {
for x in 0..buf.area.width {
screen.push_str(buf[(x, y)].symbol());
}
screen.push('\n');
}
assert!(
screen.contains("alpha.txt"),
"tree missing alpha.txt:\n{screen}"
);
assert!(
screen.contains("beta.txt"),
"tree missing beta.txt:\n{screen}"
);
}
/// Click-rect audit: for every `tree_icon_buttons` rect, every
/// non-empty cell of the visible chip cluster must be INSIDE
/// the registered rect. A non-empty cell immediately adjacent
/// (left or right, same row) to the rect means the rendered
/// chip extends beyond its click target — clicking the visible
/// glyph would miss the dispatch. This catches the wide-glyph
/// display-cell off-by-one that hid the workspace `+` chip from
/// clicks for a long debug session on 2026-06-19.
#[test]
fn audit_tree_icon_button_rects_cover_visible_chip() {
use ratatui::Terminal;
use ratatui::backend::TestBackend;
let d = tempfile::tempdir().unwrap();
let ws = d.path().to_path_buf();
std::fs::write(ws.join("alpha.txt"), "a\n").unwrap();
let mut app = App::new(ws.clone(), crate::config::Config::default()).unwrap();
let mut term = Terminal::new(TestBackend::new(80, 24)).unwrap();
term.draw(|f| crate::ui::draw(f, &mut app)).unwrap();
let buf = term.backend().buffer();
let is_visible = |x: u16, y: u16| -> bool {
x < buf.area.width && y < buf.area.height && !buf[(x, y)].symbol().trim().is_empty()
};
// Guard: if the TestBackend's width clipped every chip out
// (e.g. a tempdir name wider than the chip-cluster slot
// makes `chip_count` drop to 0), the loop below passes
// vacuously without exercising anything. Reviewer-flagged
// 2026-06-19: airtight the test against that case so a
// future width regression can't silently mask the audit.
assert!(
!app.rects.tree_icon_buttons.is_empty(),
"audit precondition: tree_icon_buttons was empty — \
the 80×24 TestBackend isn't wide enough to render any \
chip (workspace name `{ws}` may be too long for the \
header cluster). Test would pass vacuously.",
ws = ws.file_name().unwrap_or_default().to_string_lossy(),
);
// Helper: does (x, y) fall inside ANY registered rect?
// Used to distinguish "chip overflow into empty space" (a
// real off-by-one bug) from "chip cluster is adjacent so
// the next chip's own glyph is at right_x" (fine, it's
// that chip's own hit surface). 2026-08-16 — needed after
// chip_w bumped to 4 in nerd mode to match the visual
// wide-glyph width; ratatui's buffer still allocates only
// 1 cell for the (unicode-width narrow) PUA glyph, so the
// next chip's glyph appears at prev.right_x in the buffer.
let rect_contains = |x: u16, y: u16| -> bool {
app.rects
.tree_icon_buttons
.iter()
.any(|(r, _)| x >= r.x && x < r.x + r.width && y >= r.y && y < r.y + r.height)
};
for (rect, label) in &app.rects.tree_icon_buttons {
// Check the cell IMMEDIATELY left and right of the rect
// on the same rows. A non-empty adjacent cell means the
// chip extends past the registered hit area — UNLESS
// that adjacent cell is itself inside a neighboring
// registered rect (chips are painted adjacent, so the
// next chip's own glyph is a legitimate neighbor).
for y in rect.y..rect.y.saturating_add(rect.height) {
if rect.x > 0 && is_visible(rect.x - 1, y) && !rect_contains(rect.x - 1, y) {
panic!(
"tree_icon_button rect `{label}` at ({x},{y},{w}x{h}): visible glyph at ({lx},{y}) is OUTSIDE the rect (off-by-one to the left)",
x = rect.x,
w = rect.width,
h = rect.height,
lx = rect.x - 1,
);
}
let right_x = rect.x + rect.width;
// 2026-07-08 — the rail's rightmost column is now a
// dedicated resize divider (`│`) sibling to the
// scrollbar. A chip that ends at the tree-body
// right edge will legitimately have that divider
// glyph one cell past its rect; that's the
// divider column, not an off-by-one chip render.
let right_glyph = if right_x < buf.area.width {
buf[(right_x, y)].symbol()
} else {
""
};
let is_divider = right_glyph == "│" || right_glyph == "┃";
if is_visible(right_x, y) && !is_divider && !rect_contains(right_x, y) {
panic!(
"tree_icon_button rect `{label}` at ({x},{y},{w}x{h}): visible glyph at ({rx},{y}) is OUTSIDE the rect (off-by-one to the right)",
x = rect.x,
w = rect.width,
h = rect.height,
rx = right_x,
);
}
}
}
}
}