tix-tracker 0.12.0

A terminal issue tracker: markdown + YAML frontmatter issues with a kanban TUI and CLI
Documentation
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
#[allow(clippy::wildcard_imports)]
use super::*;

impl App {
    /// Open the Config mode (F12, `s`, `b`), optionally seeding an inline
    /// prompt (e.g. `b` starts a new-board prompt). A seeded prompt belongs to
    /// the dashboards section, so that is the section it opens on.
    pub(in crate::app) fn open_settings(&mut self, prompt: Option<SettingsPrompt>) {
        self.settings = Some(SettingsModal {
            selected: 0,
            prompt,
            section: ConfigSection::Dashboards,
            ..SettingsModal::default()
        });
        self.mode = Mode::Settings;
    }

    /// Config mode keys, dispatched by the active section (tui-config-mode).
    ///
    /// The dashboards section reuses the settings rows (column checkboxes,
    /// display toggles, editor); the cycles and milestones sections reuse the
    /// planning cursor and its create/edit/delete commands. Within either
    /// section the mode is the standard two-pane shape: `h`/`l` move the focus
    /// between the section rail and the body, `j`/`k` move inside the focused
    /// pane. An inline prompt takes every text key it is given.
    pub(in crate::app) fn handle_settings_key(&mut self, key: KeyEvent) -> Result<Action> {
        let Some(section) = self.settings.as_ref().map(|m| m.section) else {
            self.mode = Mode::Board;
            return Ok(Action::None);
        };
        match section {
            ConfigSection::Dashboards => self.handle_settings_dashboards_key(key),
            ConfigSection::Cycles | ConfigSection::Milestones => {
                self.handle_settings_planning_key(key)
            }
            ConfigSection::Types | ConfigSection::CustomAttributes => {
                self.handle_settings_list_key(key)
            }
        }
    }

    /// Keys of the dashboards section: an active inline prompt takes text
    /// (`Enter` submits, `Esc` cancels); otherwise the row cursor and the
    /// column/board commands.
    pub(in crate::app) fn handle_settings_dashboards_key(
        &mut self,
        key: KeyEvent,
    ) -> Result<Action> {
        let prompt_active = self.settings.as_ref().and_then(|m| m.prompt.clone());
        let Some(p) = prompt_active else {
            return self.handle_settings_browse(key);
        };
        match key.code {
            KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => {
                if let Some(m) = self.settings.as_mut() {
                    m.prompt = None;
                }
                Ok(Action::None)
            }
            KeyCode::Enter | KeyCode::Char('y') | KeyCode::Char('Y') => {
                match p {
                    SettingsPrompt::AddColumn(name) => self.settings_commit_add_column(name),
                    SettingsPrompt::NewBoard(name) => self.settings_commit_new_board(name),
                    SettingsPrompt::RenameBoard { old, buffer } => {
                        self.settings_commit_rename_board(old, buffer)
                    }
                    SettingsPrompt::ConfirmDeleteBoard { name, .. } => {
                        self.settings_commit_delete_board(name)
                    }
                    SettingsPrompt::SetEditor(value) => self.settings_commit_editor(value),
                    SettingsPrompt::SetViewer(value) => self.settings_commit_viewer(value),
                    // These belong to the Types / Attributes sections and
                    // are never seeded here; submitting one is a no-op.
                    SettingsPrompt::AddType(_) | SettingsPrompt::AddAttribute(_) => {}
                }
                Ok(Action::None)
            }
            KeyCode::Char(c) => {
                self.settings_prompt_push(c);
                Ok(Action::None)
            }
            KeyCode::Backspace => {
                self.settings_prompt_pop();
                Ok(Action::None)
            }
            _ => Ok(Action::None),
        }
    }

    /// Type into the active text prompt. Prompts that only confirm
    /// (`ConfirmDeleteBoard`) ignore text.
    pub(in crate::app) fn settings_prompt_push(&mut self, c: char) {
        if let Some(m) = self.settings.as_mut()
            && let Some(prompt) = m.prompt.as_mut()
        {
            match prompt {
                SettingsPrompt::AddColumn(b)
                | SettingsPrompt::NewBoard(b)
                | SettingsPrompt::RenameBoard { buffer: b, .. }
                | SettingsPrompt::SetEditor(b)
                | SettingsPrompt::SetViewer(b)
                | SettingsPrompt::AddType(b)
                | SettingsPrompt::AddAttribute(b) => b.push(c),
                SettingsPrompt::ConfirmDeleteBoard { .. } => {}
            }
        }
    }

    pub(in crate::app) fn settings_prompt_pop(&mut self) {
        if let Some(m) = self.settings.as_mut()
            && let Some(prompt) = m.prompt.as_mut()
        {
            match prompt {
                SettingsPrompt::AddColumn(b)
                | SettingsPrompt::NewBoard(b)
                | SettingsPrompt::RenameBoard { buffer: b, .. }
                | SettingsPrompt::SetEditor(b)
                | SettingsPrompt::SetViewer(b)
                | SettingsPrompt::AddType(b)
                | SettingsPrompt::AddAttribute(b) => {
                    b.pop();
                }
                SettingsPrompt::ConfirmDeleteBoard { .. } => {}
            }
        }
    }

    /// Browsing the dashboards section: no inline prompt is active.
    ///
    /// The drill-down (tui-config-mode): `l`/`→` (`move_right`) steps one level
    /// deeper — from the rail into the board index, and from the index into the
    /// selected board's detail; `h`/`←` (`move_left`) steps back out and, at the
    /// rail, closes the mode. `j`/`k` (and `↓`/`↑`) move inside the current
    /// level: the section in the rail, the board in the index, the row in the
    /// detail. `Shift+J`/`Shift+K` move the selected column in the detail.
    pub(in crate::app) fn handle_settings_browse(&mut self, key: KeyEvent) -> Result<Action> {
        let level = self.settings.as_ref().map(|m| m.level).unwrap_or_default();
        match key.code {
            KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => {
                self.close_config_mode();
                Ok(Action::None)
            }
            KeyCode::Left | KeyCode::Char('h') => {
                if level == ConfigLevel::Sections {
                    self.close_config_mode();
                } else {
                    self.config_move_level(-1);
                }
                Ok(Action::None)
            }
            KeyCode::Right | KeyCode::Char('l') => {
                match level {
                    ConfigLevel::Sections => self.config_move_level(1),
                    ConfigLevel::Index => self.settings_drill_board(),
                    ConfigLevel::Detail => {}
                }
                Ok(Action::None)
            }
            KeyCode::Up | KeyCode::Char('k') => {
                match level {
                    ConfigLevel::Sections => self.config_prev_section(),
                    ConfigLevel::Index => {
                        let count = self.store.config.configs().count();
                        if let Some(m) = self.settings.as_mut() {
                            m.move_selected(-1, count);
                        }
                    }
                    ConfigLevel::Detail => {
                        let count = board_rows_len(self.active_board_config());
                        if let Some(m) = self.settings.as_mut() {
                            m.move_detail(-1, count);
                        }
                    }
                }
                Ok(Action::None)
            }
            KeyCode::Down | KeyCode::Char('j') => {
                match level {
                    ConfigLevel::Sections => self.config_next_section(),
                    ConfigLevel::Index => {
                        let count = self.store.config.configs().count();
                        if let Some(m) = self.settings.as_mut() {
                            m.move_selected(1, count);
                        }
                    }
                    ConfigLevel::Detail => {
                        let count = board_rows_len(self.active_board_config());
                        if let Some(m) = self.settings.as_mut() {
                            m.move_detail(1, count);
                        }
                    }
                }
                Ok(Action::None)
            }
            KeyCode::Char('K') => self.settings_move_column(-1),
            KeyCode::Char('J') => self.settings_move_column(1),
            KeyCode::Tab => {
                self.settings_next_board();
                Ok(Action::None)
            }
            KeyCode::BackTab => {
                self.settings_prev_board();
                Ok(Action::None)
            }
            KeyCode::Enter => match level {
                ConfigLevel::Sections => {
                    self.config_move_level(1);
                    Ok(Action::None)
                }
                ConfigLevel::Index => {
                    self.settings_drill_board();
                    Ok(Action::None)
                }
                ConfigLevel::Detail => self.settings_toggle_selected(),
            },
            KeyCode::Char(' ') => self.settings_toggle_selected(),
            KeyCode::Char('a') => {
                if let Some(m) = self.settings.as_mut() {
                    m.prompt = Some(SettingsPrompt::AddColumn(String::new()));
                }
                Ok(Action::None)
            }
            KeyCode::Char('n') => {
                if let Some(m) = self.settings.as_mut() {
                    m.prompt = Some(SettingsPrompt::NewBoard(String::new()));
                }
                Ok(Action::None)
            }
            KeyCode::Char('e') => {
                let old = self.active_board_name().to_string();
                if let Some(m) = self.settings.as_mut() {
                    m.prompt = Some(SettingsPrompt::RenameBoard {
                        old: old.clone(),
                        buffer: old,
                    });
                }
                Ok(Action::None)
            }
            KeyCode::Char('x') | KeyCode::Char('X') => {
                if self.store.config.configs().count() <= 1 {
                    self.status_msg = Some("Cannot delete the last board".to_string());
                    return Ok(Action::None);
                }
                let name = self.active_board_name().to_string();
                let referencing = Self::board_reference_count(&name);
                if let Some(m) = self.settings.as_mut() {
                    m.prompt = Some(SettingsPrompt::ConfirmDeleteBoard { name, referencing });
                }
                Ok(Action::None)
            }
            _ => Ok(Action::None),
        }
    }

    /// Keys of the cycles/milestones sections: the planning cursor and its
    /// create/edit/delete commands, plus the pane model and close.
    ///
    /// Same two panes as the dashboards section: `h`/`l` move the focus between
    /// the rail and the body, `j`/`k` move the section (rail) or the row (body),
    /// and `Enter` steps into the body from the rail then edits the selected
    /// cycle or milestone from the body.
    pub(in crate::app) fn handle_settings_planning_key(&mut self, key: KeyEvent) -> Result<Action> {
        if self.planning.is_none() {
            let mut modal = PlanningModal::new();
            modal.segment = match self.settings.as_ref().map(|m| m.section) {
                Some(ConfigSection::Milestones) => PlanningSegment::Milestones,
                _ => PlanningSegment::Cycles,
            };
            self.planning = Some(modal);
        }
        // A delete confirmation is answered before anything else, through the
        // same handler the planning surface uses.
        if let Some(prompt) = self.planning.as_ref().and_then(|m| m.prompt.clone()) {
            return self.handle_planning_confirm_key(key, prompt);
        }
        // The Milestones mode hides the section rail, so its keys always walk the
        // milestone index — the rail's `Sections` level does not exist there.
        let level = if self.milestone_mode {
            ConfigLevel::Index
        } else {
            self.settings.as_ref().map(|m| m.level).unwrap_or_default()
        };
        match key.code {
            KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => {
                self.close_config_mode();
                Ok(Action::None)
            }
            KeyCode::Left | KeyCode::Char('h') => {
                if !self.milestone_mode {
                    if level == ConfigLevel::Sections {
                        self.close_config_mode();
                    } else {
                        self.config_move_level(-1);
                    }
                }
                Ok(Action::None)
            }
            KeyCode::Right | KeyCode::Char('l') => {
                match level {
                    ConfigLevel::Sections => self.config_move_level(1),
                    ConfigLevel::Index => return self.planning_open_edit(),
                    ConfigLevel::Detail => {}
                }
                Ok(Action::None)
            }
            KeyCode::Up | KeyCode::Char('k') => {
                match level {
                    ConfigLevel::Sections => self.config_prev_section(),
                    _ => {
                        let len = self.planning_rows_len();
                        if let Some(m) = self.planning.as_mut() {
                            m.move_selected(-1, len);
                        }
                    }
                }
                Ok(Action::None)
            }
            KeyCode::Down | KeyCode::Char('j') => {
                match level {
                    ConfigLevel::Sections => self.config_next_section(),
                    _ => {
                        let len = self.planning_rows_len();
                        if let Some(m) = self.planning.as_mut() {
                            m.move_selected(1, len);
                        }
                    }
                }
                Ok(Action::None)
            }
            KeyCode::Enter => match level {
                ConfigLevel::Sections => {
                    self.config_move_level(1);
                    Ok(Action::None)
                }
                _ => self.planning_open_edit(),
            },
            KeyCode::Char('n') => {
                self.planning_open_create();
                Ok(Action::None)
            }
            KeyCode::Char('e') => self.planning_open_edit(),
            KeyCode::Char('x') | KeyCode::Char('X') => self.planning_confirm_delete(),
            // `m` opens the planning-management surface for the section on
            // screen (the Cycle mode's `m` does the same). It is bound in the
            // Milestones context; a user who rebinds it into `settings` reaches
            // the same place.
            KeyCode::Char('m') | KeyCode::Char('M') => {
                let segment = if self.milestone_mode
                    || self.settings.as_ref().map(|m| m.section) == Some(ConfigSection::Milestones)
                {
                    PlanningSegment::Milestones
                } else {
                    PlanningSegment::Cycles
                };
                self.open_planning_modal();
                if let Some(modal) = self.planning.as_mut() {
                    modal.segment = segment;
                    modal.selected = 0;
                    modal.prompt = None;
                }
                Ok(Action::None)
            }
            // `?` opens the overlay from the Milestones mode (bound there). The
            // Config mode's `settings` context does not bind `help`, so this arm
            // is reached only when a user binds `?` into that context.
            KeyCode::Char('?') => {
                self.open_help(Mode::Settings);
                Ok(Action::None)
            }
            _ => Ok(Action::None),
        }
    }

    /// Keys of the Types / Attributes sections: an active inline prompt
    /// takes text (`Enter` submits, `Esc` cancels); otherwise the row cursor plus
    /// add (`n`) and remove (`x`). The two panes mirror the other sections —
    /// `h`/`l` move focus, `j`/`k` move the section (rail) or the row (body).
    pub(in crate::app) fn handle_settings_list_key(&mut self, key: KeyEvent) -> Result<Action> {
        if let Some(prompt) = self.settings.as_ref().and_then(|m| m.prompt.clone()) {
            match key.code {
                KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => {
                    if let Some(m) = self.settings.as_mut() {
                        m.prompt = None;
                    }
                }
                KeyCode::Enter | KeyCode::Char('y') | KeyCode::Char('Y') => match prompt {
                    SettingsPrompt::AddType(value) => self.settings_commit_add_type(value),
                    SettingsPrompt::AddAttribute(value) => {
                        self.settings_commit_add_attribute(value)
                    }
                    _ => {}
                },
                KeyCode::Char(c) => self.settings_prompt_push(c),
                KeyCode::Backspace => self.settings_prompt_pop(),
                _ => {}
            }
            return Ok(Action::None);
        }
        let section = self
            .settings
            .as_ref()
            .map(|m| m.section)
            .unwrap_or_default();
        let level = self.settings.as_ref().map(|m| m.level).unwrap_or_default();
        match key.code {
            KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => {
                self.close_config_mode();
                Ok(Action::None)
            }
            KeyCode::Left | KeyCode::Char('h') => {
                if level == ConfigLevel::Sections {
                    self.close_config_mode();
                } else {
                    self.config_move_level(-1);
                }
                Ok(Action::None)
            }
            KeyCode::Right | KeyCode::Char('l') => {
                // The list sections have no detail level: the index is the leaf.
                if level == ConfigLevel::Sections {
                    self.config_move_level(1);
                }
                Ok(Action::None)
            }
            KeyCode::Up | KeyCode::Char('k') => {
                match level {
                    ConfigLevel::Sections => self.config_prev_section(),
                    _ => {
                        let len = self.settings_list_len(section);
                        if let Some(m) = self.settings.as_mut() {
                            m.move_selected(-1, len);
                        }
                    }
                }
                Ok(Action::None)
            }
            KeyCode::Down | KeyCode::Char('j') => {
                match level {
                    ConfigLevel::Sections => self.config_next_section(),
                    _ => {
                        let len = self.settings_list_len(section);
                        if let Some(m) = self.settings.as_mut() {
                            m.move_selected(1, len);
                        }
                    }
                }
                Ok(Action::None)
            }
            KeyCode::Enter => {
                // Enter steps from the rail into the index; the index's rows have
                // no Enter action (add/remove are the `n`/`x` commands).
                if level == ConfigLevel::Sections {
                    self.config_move_level(1);
                }
                Ok(Action::None)
            }
            KeyCode::Char('n') => {
                let prompt = match section {
                    ConfigSection::CustomAttributes => SettingsPrompt::AddAttribute(String::new()),
                    _ => SettingsPrompt::AddType(String::new()),
                };
                if let Some(m) = self.settings.as_mut() {
                    m.prompt = Some(prompt);
                }
                Ok(Action::None)
            }
            KeyCode::Char('x') | KeyCode::Char('X') => {
                self.settings_remove_selected(section);
                Ok(Action::None)
            }
            _ => Ok(Action::None),
        }
    }

    /// The number of rows in a Types / Attributes section.
    pub(in crate::app) fn settings_list_len(&self, section: ConfigSection) -> usize {
        match section {
            ConfigSection::Types => self.store.config.custom_types().len(),
            ConfigSection::CustomAttributes => self.store.config.attributes().len(),
            _ => 0,
        }
    }

    /// Remove the selected entry of a list section and persist. The cursor moves
    /// to the entry that took its place (the previous one at the end of the list).
    pub(in crate::app) fn settings_remove_selected(&mut self, section: ConfigSection) {
        let selected = self.settings.as_ref().map(|m| m.selected).unwrap_or(0);
        let removed = match section {
            ConfigSection::Types => {
                let mut types = self.store.config.custom_types();
                if selected >= types.len() {
                    return;
                }
                let removed = types.remove(selected);
                self.store.config.types = Some(types);
                removed
            }
            ConfigSection::CustomAttributes => {
                let mut attrs = self.store.config.attributes();
                if selected >= attrs.len() {
                    return;
                }
                let removed = attrs.remove(selected);
                self.store.config.custom_attributes.keys = attrs;
                removed
            }
            _ => return,
        };
        if !self.persist_config() {
            return;
        }
        let len = self.settings_list_len(section);
        if let Some(m) = self.settings.as_mut() {
            let target = selected.saturating_sub(1).min(len.saturating_sub(1));
            m.move_selected_to(target, len);
        }
        self.status_msg = Some(match section {
            ConfigSection::Types => format!("Removed type '{removed}'"),
            _ => format!("Removed attribute '{removed}'"),
        });
    }

    /// Add a `custom_types` entry and persist. An empty name is refused; a
    /// duplicate (case-insensitively) is refused with a message rather than
    /// silently ignored.
    pub(in crate::app) fn settings_commit_add_type(&mut self, value: String) {
        let value = value.trim().to_string();
        if value.is_empty() {
            self.status_msg = Some("Type name is required".to_string());
            return;
        }
        // `custom_types()` falls back to the default set when unset, so adding to
        // a project that never declared the key materializes the defaults plus
        // the new name — the same list `tix init` would have written.
        let mut types = self.store.config.custom_types();
        if types.iter().any(|t| t.eq_ignore_ascii_case(&value)) {
            self.status_msg = Some(format!("Type '{value}' already exists"));
            return;
        }
        types.push(value.clone());
        self.store.config.types = Some(types);
        if !self.persist_config() {
            return;
        }
        if let Some(m) = self.settings.as_mut() {
            m.prompt = None;
        }
        self.status_msg = Some(format!("Added type '{value}'"));
    }

    /// Add an attribute entry and persist, refusing a blank or duplicate name.
    /// When no `[custom_attributes]` are declared, the built-in attributes are
    /// materialized first, mirroring the Types section.
    pub(in crate::app) fn settings_commit_add_attribute(&mut self, value: String) {
        let value = value.trim().to_string();
        if value.is_empty() {
            self.status_msg = Some("Attribute name is required".to_string());
            return;
        }
        let mut attrs = self.store.config.attributes();
        if attrs.iter().any(|key| key.eq_ignore_ascii_case(&value)) {
            self.status_msg = Some(format!("Attribute '{value}' already exists"));
            return;
        }
        attrs.push(value.clone());
        self.store.config.custom_attributes.keys = attrs;
        if !self.persist_config() {
            return;
        }
        if let Some(m) = self.settings.as_mut() {
            m.prompt = None;
        }
        self.status_msg = Some(format!("Added attribute '{value}'"));
    }

    /// Leave the Config mode back to the board, dropping every section's state.
    pub(in crate::app) fn close_config_mode(&mut self) {
        self.settings = None;
        self.planning = None;
        self.planning_form = None;
        // The Milestones mode borrowed this surface; release the flag so a later
        // `s`/F12 opens Config rather than Milestones.
        self.milestone_mode = false;
        self.mode = Mode::Board;
        self.rebuild_board();
    }

    /// Switch the Config mode's active section, keeping the planning cursor in
    /// step with the cycles/milestones sections. Selecting a section also puts
    /// the focus on the rail (that is where the selection was made — a rail
    /// click, or `j`/`k` while the rail is focused).
    pub(in crate::app) fn config_set_section(&mut self, section: ConfigSection) {
        // The Milestones mode has no rail: its section is pinned, so nothing may
        // move it.
        if self.milestone_mode {
            return;
        }
        if let Some(m) = self.settings.as_mut() {
            m.set_section(section);
            m.focus(ConfigLevel::Sections);
        }
        let segment = match section {
            ConfigSection::Dashboards | ConfigSection::Types | ConfigSection::CustomAttributes => {
                return;
            }
            ConfigSection::Cycles => PlanningSegment::Cycles,
            ConfigSection::Milestones => PlanningSegment::Milestones,
        };
        let modal = self.planning.get_or_insert_with(PlanningModal::new);
        if modal.segment != segment {
            modal.segment = segment;
            modal.selected = 0;
            modal.prompt = None;
        }
    }

    pub(in crate::app) fn config_next_section(&mut self) {
        if self.milestone_mode {
            return;
        }
        if let Some(next) = self.settings.as_ref().map(|m| m.section.next()) {
            self.config_set_section(next);
        }
    }

    pub(in crate::app) fn config_prev_section(&mut self) {
        if self.milestone_mode {
            return;
        }
        if let Some(prev) = self.settings.as_ref().map(|m| m.section.prev()) {
            self.config_set_section(prev);
        }
    }

    /// Move the Config mode's drill-down level (`h`/`l`, `←`/`→`), clamped to
    /// the three levels — `Sections` at the top, `Detail` at the bottom —
    /// rather than wrapping.
    pub(in crate::app) fn config_move_level(&mut self, delta: isize) {
        if let Some(m) = self.settings.as_mut() {
            m.move_level(delta);
        }
    }

    /// Drill into the board selected in the dashboards index: make it the
    /// active board (the exact `Tab`/`BackTab` path) and show its detail.
    pub(in crate::app) fn settings_drill_board(&mut self) {
        let Some(index) = self.settings.as_ref().map(|m| m.selected) else {
            return;
        };
        if index >= self.store.config.configs().count() {
            return;
        }
        self.switch_board(index);
        if let Some(m) = self.settings.as_mut() {
            m.focus(ConfigLevel::Detail);
            m.detail_selected = 0;
        }
    }

    /// Move the selected column earlier (`delta < 0`) or later (`delta > 0`) in
    /// the active board's `columns` order and persist. A move off either end is
    /// a no-op: nothing is written, so an end-of-list press never rewrites the
    /// store. Only `columns` is reordered — `hidden_columns`, `done_column`, and
    /// `category_map` are name-keyed and order-free.
    pub(in crate::app) fn settings_move_column(&mut self, delta: isize) -> Result<Action> {
        let Some(modal) = self.settings.as_ref() else {
            return Ok(Action::None);
        };
        if modal.level != ConfigLevel::Detail {
            return Ok(Action::None);
        }
        let from = modal.detail_selected;
        let board_name = self.active_board_name().to_string();
        let Some(board_config) = self.store.config.kanban.configurations.get_mut(&board_name)
        else {
            return Ok(Action::None);
        };
        if from >= board_config.columns.len() {
            // A display or general row — not a column.
            return Ok(Action::None);
        }
        let to = from as isize + delta;
        if to < 0 || to as usize >= board_config.columns.len() {
            return Ok(Action::None);
        }
        board_config.columns.swap(from, to as usize);
        if !self.persist_config() {
            return Ok(Action::None);
        }
        self.rebuild_board();
        if let Some(m) = self.settings.as_mut() {
            m.detail_selected = to as usize;
        }
        self.status_msg = Some(format!("Moved column to position {}", to + 1));
        Ok(Action::None)
    }

    /// Apply a click that landed on the Config mode's surface. A rail entry
    /// focuses the rail (and switches section); a body row focuses the body and
    /// moves that section's row cursor — the caller runs the row's own action.
    /// This is the one place pane focus follows the pointer (D3/D6).
    pub(in crate::app) fn apply_config_click(&mut self, action: Action) {
        match action {
            Action::ConfigSection(section) => self.config_set_section(section),
            Action::SettingsRow(row) => {
                let count = self.store.config.configs().count();
                if let Some(modal) = self.settings.as_mut() {
                    modal.focus(ConfigLevel::Index);
                    modal.move_selected_to(row, count);
                }
            }
            Action::ConfigDetailRow(row) => {
                let count = board_rows_len(self.active_board_config());
                if let Some(modal) = self.settings.as_mut() {
                    modal.focus(ConfigLevel::Detail);
                    modal.move_detail_to(row, count);
                }
            }
            Action::ConfigPlanningRow(row) => {
                let len = self.planning_rows_len();
                if let Some(modal) = self.settings.as_mut() {
                    modal.focus(ConfigLevel::Index);
                }
                if let Some(modal) = self.planning.as_mut() {
                    modal.move_selected_to(row, len);
                }
            }
            Action::ConfigListRow(row) => {
                let section = self
                    .settings
                    .as_ref()
                    .map(|modal| modal.section)
                    .unwrap_or_default();
                let len = self.settings_list_len(section);
                if let Some(modal) = self.settings.as_mut() {
                    modal.focus(ConfigLevel::Index);
                    modal.move_selected_to(row, len);
                }
            }
            _ => {}
        }
    }

    /// How many issues reference `name` as a board. **Zero today**: nothing in
    /// issue frontmatter names a board (only `status`/`cycles`/`milestones`),
    /// so a board rename needs no issue cascade and a board delete has no
    /// references to report beyond the count. The count is still computed so
    /// the confirmation states a number rather than assuming one.
    pub(in crate::app) fn board_reference_count(_name: &str) -> usize {
        0
    }

    pub(in crate::app) fn settings_next_board(&mut self) {
        self.tabs.next();
        self.active_config = self.tabs.selected;
        self.switch_config();
        if let Some(m) = self.settings.as_mut() {
            m.selected = 0;
            m.detail_selected = 0;
        }
    }

    pub(in crate::app) fn settings_prev_board(&mut self) {
        self.tabs.previous();
        self.active_config = self.tabs.selected;
        self.switch_config();
        if let Some(m) = self.settings.as_mut() {
            m.selected = 0;
            m.detail_selected = 0;
        }
    }

    pub(in crate::app) fn settings_toggle_selected(&mut self) -> Result<Action> {
        let Some(modal) = self.settings.as_ref() else {
            return Ok(Action::None);
        };
        // Only the dashboard detail has activatable rows; the index rows are
        // records to drill into, not toggles.
        if modal.level != ConfigLevel::Detail {
            return Ok(Action::None);
        }
        let col_count = self.active_board_config().columns.len();
        let selected = modal.detail_selected;
        if selected >= col_count {
            return self.settings_toggle_display_row(selected - col_count);
        }
        let col = self
            .settings
            .as_ref()
            .and_then(|m| self.active_board_config().columns.get(m.detail_selected))
            .cloned();
        let Some(col) = col else {
            return Ok(Action::None);
        };
        let board_name = self.active_board_name().to_string();
        let now_hidden = {
            let board_config = self.store.config.kanban.configurations.get_mut(&board_name);
            match board_config {
                Some(bc) => {
                    if let Some(pos) = bc.hidden_columns.iter().position(|h| h == &col) {
                        bc.hidden_columns.remove(pos);
                        false
                    } else {
                        bc.hidden_columns.push(col.clone());
                        true
                    }
                }
                None => return Ok(Action::None),
            }
        };
        if !self.persist_config() {
            return Ok(Action::None);
        }
        // Same rule as the board's `c`: a hand-made visibility change drops the
        // applied view's snapshot before the rebuild (WP05, T025), so the toggle
        // takes effect and the divergence is reported rather than reconciled.
        if let Some(session) = self.view_session.as_mut() {
            session.visibility = false;
        }
        self.rebuild_board();
        let last = self.active_board_config().columns.len().saturating_sub(1);
        if let Some(m) = self.settings.as_mut()
            && m.detail_selected > last
        {
            m.detail_selected = last;
        }
        self.status_msg = Some(match now_hidden {
            true => format!("'{col}' hidden"),
            false => format!("'{col}' shown"),
        });
        Ok(Action::None)
    }

    /// Toggle/cycle one of the display rows (after the column checkboxes).
    /// Row 0 flips title wrapping, row 1 cycles the line limit through 1-5,
    /// row 2 cycles the ordering; every change persists and rebuilds the board.
    /// The general rows after those open the `$EDITOR` override prompt.
    pub(in crate::app) fn settings_toggle_display_row(&mut self, row: usize) -> Result<Action> {
        if row >= crate::ui::settings::DISPLAY_ROWS {
            // The general rows, in order: the `$EDITOR` override, then the
            // read-only viewer (tix #1507). Both are `tix.toml` settings rather
            // than per-record metadata files, and both open an inline prompt.
            let general = row - crate::ui::settings::DISPLAY_ROWS;
            let prompt = match general {
                0 => {
                    SettingsPrompt::SetEditor(self.store.config.editor.clone().unwrap_or_default())
                }
                _ => {
                    SettingsPrompt::SetViewer(self.store.config.viewer.clone().unwrap_or_default())
                }
            };
            if let Some(m) = self.settings.as_mut() {
                m.prompt = Some(prompt);
            }
            return Ok(Action::None);
        }
        let board_name = self.active_board_name().to_string();
        let action_msg = {
            let board_config = self.store.config.kanban.configurations.get_mut(&board_name);
            let Some(board_config) = board_config else {
                return Ok(Action::None);
            };
            match row {
                0 => {
                    board_config.wrap_titles = !board_config.wrap_titles;
                    if board_config.wrap_titles {
                        "Wrap titles: on".to_string()
                    } else {
                        "Wrap titles: off".to_string()
                    }
                }
                1 => {
                    board_config.title_lines = board_config.title_lines % 5 + 1;
                    format!("Title lines: {}", board_config.title_lines)
                }
                2 => {
                    board_config.order_by = board_config.order_by.next();
                    format!("Order by: {}", board_config.order_by.as_str())
                }
                _ => return Ok(Action::None),
            }
        };
        if !self.persist_config() {
            return Ok(Action::None);
        }
        self.rebuild_board();
        self.status_msg = Some(action_msg);
        Ok(Action::None)
    }

    pub(in crate::app) fn settings_commit_add_column(&mut self, name: String) {
        let name = name.trim().to_string();
        if name.is_empty() {
            self.status_msg = Some("Column name is required".to_string());
            return;
        }
        let board_name = self.active_board_name().to_string();
        let board_config = self.store.config.kanban.configurations.get_mut(&board_name);
        let Some(board_config) = board_config else {
            self.status_msg = Some("board not found".to_string());
            return;
        };
        if board_config.columns.iter().any(|c| c == &name) {
            self.status_msg = Some(format!("Column '{name}' already exists"));
            return;
        }
        board_config.columns.push(name.clone());
        if !self.persist_config() {
            return;
        }
        self.rebuild_board();
        let last = self.active_board_config().columns.len().saturating_sub(1);
        if let Some(ref mut m) = self.settings {
            m.prompt = None;
            m.selected = last;
        }
        self.status_msg = Some(format!("Added column '{name}'"));
    }

    pub(in crate::app) fn settings_commit_new_board(&mut self, name: String) {
        let name = name.trim().to_string();
        if name.is_empty() {
            self.status_msg = Some("Board name is required".to_string());
            return;
        }
        if self.store.config.kanban.configurations.contains_key(&name) {
            self.status_msg = Some(format!("Board '{name}' already exists"));
            return;
        }
        // Lazy store creation (docs-metadata-stores): a board beyond the seeded
        // set is the point the project becomes file-backed, so `docs/boards/`
        // is created here and the next save writes every board into it — the
        // one-time write-back; `tix.toml` keeps everything else.
        if let Err(e) = self.ensure_board_store() {
            self.status_msg = Some(format!("Cannot create docs/boards/: {e}"));
            return;
        }
        self.store
            .config
            .kanban
            .configurations
            .insert(name.clone(), crate::config::BoardConfiguration::default());
        if !self.persist_config() {
            return;
        }
        self.reload_tabs();
        let idx = self
            .store
            .config
            .configs()
            .position(|(n, _)| n == name.as_str())
            .unwrap_or(0);
        self.active_config = idx;
        self.tabs.selected = idx;
        self.switch_config();
        if let Some(m) = self.settings.as_mut() {
            m.prompt = None;
            m.selected = 0;
        }
        self.status_msg = Some(format!("Added board '{name}'"));
    }

    /// Make `docs/boards/` exist, materializing the file store for a project
    /// that only had legacy `tix.toml` boards. Reading never creates it; only
    /// adding a board does (`docs-metadata-stores`, lazy directory creation).
    pub(in crate::app) fn ensure_board_store(&self) -> Result<()> {
        let store = crate::board_store::BoardStore::new(&self.project_root());
        if store.exists() {
            return Ok(());
        }
        std::fs::create_dir_all(store.dir())?;
        Ok(())
    }

    /// Rename the active board: the map entry moves in place (keeping its tab
    /// position), the board file is renamed when the file store is active, and
    /// the tabs are rebuilt. Nothing in issue frontmatter names a board — only
    /// `status`/`cycles`/`milestones` — so there is **no issue cascade** to run.
    pub(in crate::app) fn settings_commit_rename_board(&mut self, old: String, new: String) {
        let new = new.trim().to_string();
        if new.is_empty() {
            self.status_msg = Some("Board name is required".to_string());
            return;
        }
        if new == old {
            if let Some(m) = self.settings.as_mut() {
                m.prompt = None;
            }
            return;
        }
        if self.store.config.kanban.configurations.contains_key(&new) {
            self.status_msg = Some(format!("Board '{new}' already exists"));
            return;
        }
        let board_store = crate::board_store::BoardStore::new(&self.project_root());
        if board_store.exists()
            && board_store.get(&old).is_ok()
            && let Err(e) = board_store.rename(&old, &new)
        {
            self.status_msg = Some(format!("Cannot rename board '{old}': {e}"));
            return;
        }
        let Some(idx) = self.store.config.kanban.configurations.get_index_of(&old) else {
            self.status_msg = Some(format!("Board '{old}' not found"));
            return;
        };
        if let Some(board) = self.store.config.kanban.configurations.shift_remove(&old) {
            self.store
                .config
                .kanban
                .configurations
                .shift_insert(idx, new.clone(), board);
        }
        if !self.persist_config() {
            return;
        }
        self.reload_tabs();
        self.active_config = idx.min(self.tabs.names.len().saturating_sub(1));
        self.tabs.selected = self.active_config;
        self.switch_config();
        if let Some(m) = self.settings.as_mut() {
            m.prompt = None;
            m.selected = 0;
        }
        self.status_msg = Some(format!("Renamed board '{old}' to '{new}'"));
    }

    /// Commit the `$EDITOR` override to `tix.toml` (a blank value clears it).
    pub(in crate::app) fn settings_commit_editor(&mut self, value: String) {
        let value = value.trim().to_string();
        self.store.config.editor = if value.is_empty() {
            None
        } else {
            Some(value.clone())
        };
        if !self.persist_config() {
            return;
        }
        if let Some(m) = self.settings.as_mut() {
            m.prompt = None;
        }
        self.status_msg = Some(match value.is_empty() {
            true => "Editor: (default)".to_string(),
            false => format!("Editor: {value}"),
        });
    }

    /// The Viewer row's label (tix #1507): the configured override, or the
    /// viewer the auto chain resolves to, or a note naming the chain when none
    /// of it is installed.
    ///
    /// Never panics and never blocks the frame: the auto probe is cached per
    /// process in [`editor::resolve_viewer`], so this is a string build on the
    /// hot path rather than a `which` walk.
    pub(in crate::app) fn viewer_label(&self) -> String {
        match self.store.config.viewer.as_deref().map(str::trim) {
            Some(name) if !name.is_empty() && name != "auto" => name.to_string(),
            _ => match editor::resolve_viewer(None) {
                Ok(name) => format!("{name} (auto)"),
                Err(_) => format!(
                    "(none — install one of {})",
                    editor::VIEWER_CANDIDATES.join(", ")
                ),
            },
        }
    }

    /// Commit the `viewer` override to `tix.toml` (a blank value clears it back
    /// to the auto chain, tix #1507).
    pub(in crate::app) fn settings_commit_viewer(&mut self, value: String) {
        let value = value.trim().to_string();
        self.store.config.viewer = if value.is_empty() {
            None
        } else {
            Some(value.clone())
        };
        if !self.persist_config() {
            return;
        }
        if let Some(m) = self.settings.as_mut() {
            m.prompt = None;
        }
        self.status_msg = Some(match value.is_empty() {
            true => "Viewer: (auto)".to_string(),
            false => format!("Viewer: {value}"),
        });
    }

    pub(in crate::app) fn settings_commit_delete_board(&mut self, name: String) {
        if self.store.config.kanban.configurations.len() <= 1 {
            self.status_msg = Some("Cannot delete the last board".to_string());
            return;
        }
        if !self.store.config.kanban.configurations.contains_key(&name) {
            self.status_msg = Some(format!("Board '{name}' not found"));
            return;
        }
        let idx = self.active_config;
        // A file store that exists is authoritative, so the file goes too: a
        // save that only dropped the map entry would leave the file behind to
        // resurrect the board on the next load.
        let board_store = crate::board_store::BoardStore::new(&self.project_root());
        if board_store.exists() {
            match board_store.delete(&name) {
                Ok(()) | Err(TixError::NotFound(_)) => {}
                Err(e) => {
                    self.status_msg = Some(format!("Cannot delete board '{name}': {e}"));
                    return;
                }
            }
        }
        self.store.config.kanban.configurations.shift_remove(&name);
        if !self.persist_config() {
            return;
        }
        self.reload_tabs();
        let count = self.store.config.kanban.configurations.len();
        let target = idx.min(count.saturating_sub(1));
        self.active_config = target;
        self.tabs.selected = target;
        self.switch_config();
        if let Some(m) = self.settings.as_mut() {
            m.prompt = None;
            m.selected = 0;
        }
        self.status_msg = Some(format!("Deleted board '{name}'"));
    }

    pub(in crate::app) fn persist_config(&mut self) -> bool {
        match self.store.config_path() {
            Ok(path) => match self.store.config.save(&path) {
                Ok(()) => true,
                Err(e) => {
                    self.status_msg = Some(format!("settings save: {e}"));
                    false
                }
            },
            Err(e) => {
                self.status_msg = Some(format!("settings path: {e}"));
                false
            }
        }
    }

    pub(in crate::app) fn reload_tabs(&mut self) {
        let names: Vec<String> = self
            .store
            .config
            .configs()
            .map(|(name, _)| name.to_string())
            .collect();
        self.tabs = BoardTabs::new(names);
    }

    pub(in crate::app) fn active_board_name(&self) -> &str {
        self.store
            .config
            .configs()
            .nth(self.active_config)
            .map(|(name, _)| name)
            .unwrap_or("default")
    }
}