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
#[allow(clippy::wildcard_imports)]
use super::*;
mod board_view;
mod capacity;
mod dialogs;
mod forms;
mod help;
mod inputs;
mod layout;
mod repos;
mod stats;
#[allow(clippy::wildcard_imports)]
use board_view::*;
#[allow(clippy::wildcard_imports)]
use dialogs::*;
#[allow(clippy::wildcard_imports)]
use forms::*;
#[allow(clippy::wildcard_imports)]
use help::*;
#[allow(clippy::wildcard_imports)]
use inputs::*;
#[allow(clippy::wildcard_imports)]
use layout::*;
#[allow(clippy::wildcard_imports)]
use repos::*;
#[allow(clippy::wildcard_imports)]
use stats::*;

pub(in crate::app) use capacity::{
    capacity_cell, capacity_detail, capacity_fields, capacity_row, issue_estimate_line,
};
pub(in crate::app) use dialogs::{confirm_delete_buttons, confirm_delete_prompt};
pub(in crate::app) use layout::{filter_band_height, open_in_browser};
pub(in crate::app) use repos::run_child_tix;
pub(in crate::app) use stats::{HealthRow, feed_minutes};

pub(in crate::app) const HINT_HEIGHT: u16 = 1;

/// The height of the unread-mentions indicator row (OpenSpec change
/// `issue-mentions`), reserved only when there is something to say.
pub(in crate::app) const MENTION_HEIGHT: u16 = 1;

/// The height the unread-mentions indicator row occupies in `app`'s frame: one row
/// when the local user has unread mentions, none otherwise.
///
/// One helper because two places must agree: `render_board` reserves the row and
/// `board_mouse_area` hit-tests around it, and a hit test that disagreed with the
/// layout would select the wrong card — the same reason `filter_band_height` exists.
pub(in crate::app) fn mention_row_height(app: &App) -> u16 {
    if app.one_shot || app.unread_mentions == 0 {
        0
    } else {
        MENTION_HEIGHT
    }
}
/// Two rows: one for the tab labels, one for the tab bar's bottom border
/// (`BoardTabs` renders a `Block` with `Borders::BOTTOM`, which consumes the
/// last row). With height 1 the labels would never render.
pub(in crate::app) const TAB_HEIGHT: u16 = 2;
/// Single-row active-filter indicator shown directly beneath the tab bar
/// (board-filtering FR-01); zero rows when no filter is active (D-05).
pub(in crate::app) const FILTER_HEIGHT: u16 = 1;
/// Full-width row directly beneath the tab bar showing the currently hovered
/// issue's title (hovered-issue title line FR).
pub(in crate::app) const HOVER_HEIGHT: u16 = 1;
pub(in crate::app) const RENDER_FALLBACK_WIDTH: u16 = 80;
pub(in crate::app) const RENDER_FALLBACK_HEIGHT: u16 = 24;
/// Spare rows kept blank below a one-shot render so the board fits on screen
/// instead of consuming the full terminal height.
pub(in crate::app) const RENDER_BOTTOM_MARGIN: u16 = 4;
#[allow(clippy::too_many_lines)]
pub fn render(app: &App, f: &mut ratatui::Frame, area: Rect) {
    app.frame_hit_regions.borrow_mut().clear();
    // The vertical mode navigation takes the left column, and the active mode's
    // content is everything to its right (tui-mode-navigation). `frame_size`
    // tracks the *content* rect so board/tab hit-testing stays aligned with what
    // was drawn. One-shot `tix render` never shows the navigation, so its
    // contract is unchanged.
    let content = if !app.one_shot && app.nav_display != NavDisplay::Off {
        let nav_width = app.nav_width();
        if area.width > nav_width {
            let nav_area = Rect {
                width: nav_width,
                ..area
            };
            crate::ui::nav::render(app, f, nav_area);
            Rect {
                x: area.x + nav_width,
                width: area.width - nav_width,
                ..area
            }
        } else {
            area
        }
    } else {
        area
    };
    app.frame_size.set(content);
    // Every arm below draws into the content rect, so the geometry it records for
    // mouse hit-testing matches `frame_size`.
    let area = content;
    match &app.mode {
        Mode::Board => render_board(app, f, area, commandbar::MODE_BOARD),
        Mode::BulkModal => {
            // The board renders underneath, as it does under every other modal, so
            // the user can see the cards they marked and the columns they are in.
            render_board(app, f, area, commandbar::MODE_BOARD);
            if let Some(modal) = app.bulk.as_ref() {
                crate::ui::bulk::render(f, area, modal);
            }
        }
        Mode::TriageInbox => {
            // The inbox is the mode's content, not a card floating over the
            // board (tui-mode-navigation): the vertical navigation highlights
            // Triage and the mode occupies the whole content area.
            if let Some(state) = app.triage.as_ref() {
                crate::ui::triage::render(app, f, area, state);
            } else {
                render_board(app, f, area, commandbar::MODE_BOARD);
            }
        }
        Mode::Cycle => {
            // The cycle listing is the mode's content (tui-cycle-mode): the
            // vertical navigation highlights Cycle and the mode owns the area,
            // as the triage inbox does.
            if let Some(state) = app.cycle_state.as_ref() {
                let groups = app.cycle_groups();
                crate::ui::cycle::render(app, f, area, state, &groups);
            } else {
                render_board(app, f, area, commandbar::MODE_BOARD);
            }
        }
        Mode::Repos => render_repos(app, f, area),
        Mode::Stats => render_stats(app, f, area),
        Mode::HealthForm => {
            // The page renders underneath, as the board does under every other modal,
            // so the row the form is about stays on screen while its fields are typed.
            render_stats(app, f, area);
            render_health_form(app, f, area);
        }
        Mode::TimeForm => {
            // The Time tab renders underneath, so the entry rows a correction or a
            // deletion is about stay on screen while the form's fields are typed.
            render_stats(app, f, area);
            render_time_form(app, f, area);
        }
        Mode::TimeFilterForm => {
            render_stats(app, f, area);
            render_time_filter_form(app, f, area);
        }
        Mode::WipOverride { .. } => {
            // The board renders underneath, so the card being refused is still on
            // screen while its reason is typed.
            render_board(app, f, area, commandbar::MODE_BOARD);
            crate::ui::wip_override::render(app, f, area);
        }
        Mode::MentionNotice => {
            // The board renders underneath, as it does under every other modal.
            render_board(app, f, area, commandbar::MODE_BOARD);
            crate::ui::mentions::render_notice(app, f, area);
        }
        Mode::Mentions => {
            render_board(app, f, area, commandbar::MODE_BOARD);
            crate::ui::mentions::render_view(app, f, area);
        }
        Mode::RecurringWarning => {
            // The board renders underneath, as it does under every other modal, so
            // the cards the warning is about are still on screen.
            render_board(app, f, area, commandbar::MODE_BOARD);
            crate::ui::recurring_warning::render(app, f, area);
        }
        Mode::Schedule => crate::ui::schedule::render(app, f, area),
        Mode::Library => crate::ui::library::render(app, f, area),
        Mode::Portfolio => crate::ui::portfolio::render(app, f, area),
        Mode::RolloverDialog => {
            render_board(app, f, area, commandbar::MODE_BOARD);
            if let Some(dialog) = app.rollover_dialog.as_ref() {
                let rect = crate::ui::modal::modal_rect(area);
                f.render_widget(Clear, rect);
                let mut lines = Vec::new();
                lines.push(Line::from(Span::styled(
                    "Rollover needed",
                    Style::default()
                        .fg(Color::Yellow)
                        .add_modifier(Modifier::BOLD),
                )));
                for (from, to, count) in &dialog.plans {
                    lines.push(Line::from(format!(
                        "{count} issue(s): \"{from}\" -> \"{to}\""
                    )));
                }
                lines.push(Line::from(""));
                lines.push(Line::from(format!(
                    "{}: Do rollover | {}: Toggle choice | {}: Ignore",
                    app.bindings.label(
                        InputContext::Rollover,
                        crate::keybindings::TuiAction::Submit
                    ),
                    app.bindings.label(
                        InputContext::Rollover,
                        crate::keybindings::TuiAction::Previous
                    ),
                    app.bindings.label(
                        InputContext::Rollover,
                        crate::keybindings::TuiAction::Cancel
                    ),
                )));
                lines.push(Line::from(match dialog.choice {
                    crate::ui::dialog::DialogChoice::DoRollover => "> Do rollover | Ignore",
                    crate::ui::dialog::DialogChoice::Ignore => "Do rollover | > Ignore",
                }));
                let para = Paragraph::new(lines).block(
                    Block::default()
                        .borders(Borders::ALL)
                        .title("Rollover needed")
                        .style(Style::default().fg(Color::Yellow)),
                );
                f.render_widget(para, rect);
            }
        }
        Mode::Detail => render_detail(app, f, area, commandbar::MODE_DETAIL),
        Mode::Form => {
            // The form is the New Issue **mode's content**, not a modal floating
            // over the board (tui-new-issue-mode): it fills the area beside the
            // navigation, exactly as Triage and Cycle do.
            if let Some(fr) = &app.form {
                form::render_with_bindings(fr, f, area, &app.bindings, InputContext::Form);
                // Record the Template row so a click opens the picker. The row rect
                // comes from `form`, the same arithmetic the renderer and the caret
                // use, rather than a second copy of "border plus ring index".
                if let Some(row) = form::field_row_rect(area, form::FormFocus::Template) {
                    app.record_region(row, Action::TemplateOpen);
                }
                if let Some(picker) = &app.form_picker {
                    render_form_picker(app, picker, f, area, &app.bindings);
                } else {
                    // With nothing drawn over the form, the form owns the caret
                    // (#1486). Under a picker the overlay owns it instead, and a
                    // caret on the row behind it would point at the wrong surface.
                    form::place_caret(fr, f, area);
                }
            }
        }
        Mode::ConfirmDelete => {
            if area.height < 2 {
                return;
            }
            board::render(
                &app.board,
                f,
                area,
                &None,
                app.drag_preview_col,
                board::BoardDisplay::from(app.active_board_config()),
                &app.theme,
                Some(&app.wip),
                app.capacity_summaries(),
                app.marked_numbers(),
            );
            let title = app.confirm_delete_target.as_deref().unwrap_or("?");
            let prompt_area = confirm_delete_prompt(area);
            let prompt = Paragraph::new(vec![
                Line::from(Span::styled(
                    format!("Delete '{title}'? [y/N]"),
                    Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
                )),
                Line::from(""),
                Line::from("  [Yes]   [No]  "),
            ])
            .block(
                Block::default()
                    .borders(Borders::ALL)
                    .title("Confirm")
                    .style(Style::default().fg(Color::Red)),
            );
            f.render_widget(prompt, prompt_area);
            // Record the Yes / No button cells as click regions (D6): the run
            // loop maps them to the same `y` / cancel branches as the keys.
            let (yes, no) = confirm_delete_buttons(prompt_area);
            app.record_region(yes, Action::ConfirmDeleteYes);
            app.record_region(no, Action::ConfirmDeleteNo);
        }
        Mode::ConfirmArchive { filenames, restore } => {
            if area.height < 2 {
                return;
            }
            board::render(
                &app.board,
                f,
                area,
                &None,
                app.drag_preview_col,
                board::BoardDisplay::from(app.active_board_config()),
                &app.theme,
                Some(&app.wip),
                app.capacity_summaries(),
                app.marked_numbers(),
            );
            let verb = if *restore { "Restore" } else { "Archive" };
            let subject = if filenames.len() == 1 {
                format!("'{}'", filenames[0])
            } else {
                format!("{} issues", filenames.len())
            };
            let prompt_area = confirm_delete_prompt(area);
            let prompt = Paragraph::new(vec![Line::from(Span::styled(
                format!("{verb} {subject}? [y/N]"),
                Style::default()
                    .fg(Color::Yellow)
                    .add_modifier(Modifier::BOLD),
            ))])
            .block(
                Block::default()
                    .borders(Borders::ALL)
                    .title("Confirm")
                    .style(Style::default().fg(Color::Yellow)),
            );
            f.render_widget(prompt, prompt_area);
        }
        Mode::ConfirmBlockedMove { warning, .. } => {
            if area.height < 3 {
                return;
            }
            board::render(
                &app.board,
                f,
                area,
                &None,
                app.drag_preview_col,
                board::BoardDisplay::from(app.active_board_config()),
                &app.theme,
                Some(&app.wip),
                app.capacity_summaries(),
                app.marked_numbers(),
            );
            let prompt_area = Rect {
                y: area.y + area.height - 2,
                height: 2,
                ..area
            };
            // The warning is the shared text, so this prompt and the CLI's
            // `tix move` refusal cannot describe the same situation differently.
            let prompt = Paragraph::new(vec![
                Line::from(Span::styled(
                    format!("{warning} — move anyway? [y/N]"),
                    Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
                )),
                Line::from("  The decision is recorded in the issue's History."),
            ])
            .block(
                Block::default()
                    .borders(Borders::ALL)
                    .title("Blocked move")
                    .style(Style::default().fg(Color::Red)),
            );
            f.render_widget(prompt, prompt_area);
        }
        Mode::MoveIntoDone { buffer, .. } => {
            if area.height < 3 {
                return;
            }
            let prompt_area = Rect {
                y: area.y + area.height - 1,
                height: 1,
                ..area
            };
            let block_area = Rect {
                height: area.height - 1,
                ..area
            };
            board::render(
                &app.board,
                f,
                block_area,
                &app.status_msg,
                app.drag_preview_col,
                board::BoardDisplay::from(app.active_board_config()),
                &app.theme,
                Some(&app.wip),
                app.capacity_summaries(),
                app.marked_numbers(),
            );
            let prompt_text = format!("Commit hash: {buffer}_");
            let prompt = Paragraph::new(Line::from(Span::styled(
                prompt_text,
                Style::default().fg(Color::Yellow),
            )));
            f.render_widget(prompt, prompt_area);
        }
        // WP05: the reasoned-override prompt. `reason` is the **shared** service
        // diagnostic, rendered verbatim, so this prompt and the CLI's refusal
        // describe the same situation in the same words
        // (`contracts/surface-parity.md` §2 — parity includes the message).
        Mode::TransitionReason { buffer, reason, .. } => {
            if area.height < 3 {
                return;
            }
            let block_area = Rect {
                height: area.height - 1,
                ..area
            };
            board::render(
                &app.board,
                f,
                block_area,
                &app.status_msg,
                app.drag_preview_col,
                board::BoardDisplay::from(app.active_board_config()),
                &app.theme,
                Some(&app.wip),
                app.capacity_summaries(),
                app.marked_numbers(),
            );
            let prompt_area = Rect {
                y: area.y + area.height - 1,
                height: 1,
                ..area
            };
            let prompt = Paragraph::new(Line::from(Span::styled(
                format!("Reason (required): {buffer}_"),
                Style::default().fg(Color::Yellow),
            )));
            f.render_widget(prompt, prompt_area);
            // The refusal is shown above the board rather than in the one-line
            // prompt, because it is a full sentence with a backtick-quoted column
            // and a command spelling, and truncating it would leave the user with a
            // rule and no route.
            if area.height >= 5 {
                let notice = Rect {
                    y: area.y,
                    height: 3,
                    ..area
                };
                let text = Paragraph::new(vec![
                    Line::from(Span::styled(
                        "Blocked by the transition policy",
                        Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
                    )),
                    Line::from(reason.clone()),
                ])
                .block(
                    Block::default()
                        .borders(Borders::ALL)
                        .title("Override required"),
                );
                f.render_widget(text, notice);
            }
        }
        Mode::Help { return_to } => render_help(app, f, area, return_to),
        Mode::Tips { return_to } => render_tips(app, f, area, return_to),
        Mode::ActionMenu { return_to } => render_action_menu(app, f, area, return_to),
        Mode::Filter { buffer } => render_board_input(app, f, area, "Search", buffer),
        Mode::FilterModal => {
            render_board(app, f, area, commandbar::MODE_BOARD);
            if let Some(m) = app.filter_modal.as_ref() {
                m.render_with_bindings(f, area, &app.bindings, InputContext::FilterModal);
                // Record a hit region per criterion row; a click focuses the row and
                // opens its picker (or the calendar), exactly as Enter/l/right would.
                // The offset is the modal's own active-view feedback block (WP05,
                // T024): without it a click would land on the row above the one
                // the widget drew.
                let rect = crate::ui::modal::modal_rect(area);
                for (row, field) in FilterField::ALL.iter().enumerate() {
                    let hit = Rect {
                        x: rect.x + 1,
                        y: rect.y + 1 + m.header_height() + row as u16,
                        width: rect.width.saturating_sub(2),
                        height: 1,
                    };
                    app.record_region(hit, Action::FilterModalFocus(*field));
                }
                if let Some(picker) = app.filter_picker.as_ref() {
                    render_filter_picker(app, f, area, picker);
                }
            }
        }
        Mode::Views => {
            // The board renders underneath, as it does under every other modal,
            // so the user can see the board the view list applies to.
            render_board(app, f, area, commandbar::MODE_BOARD);
            if let Some(m) = app.views.as_ref() {
                let context = if m.is_prompting() {
                    InputContext::ViewsPrompt
                } else {
                    InputContext::Views
                };
                m.render_with_bindings(f, area, &app.bindings, context);
            }
        }
        Mode::Settings => {
            // The Config mode is the mode's content, not a modal over the board
            // (tui-config-mode): the section rail and the active section own the
            // area, as the triage inbox and the cycle listing do. Its planner
            // rows come from the same `planning_rows` the `m` surface uses.
            let (cycles, milestones) = app.planning_rows();
            let viewer = app.viewer_label();
            crate::ui::settings::render_config(
                app,
                f,
                area,
                crate::ui::settings::DashboardView {
                    name: app.active_board_name(),
                    board: app.active_board_config(),
                    editor: app.store.config.editor.as_deref(),
                    viewer: &viewer,
                },
                &cycles,
                &milestones,
            );
        }
        Mode::PlanningManagement => {
            render_board(app, f, area, commandbar::MODE_BOARD);
            if let Some(m) = app.planning.as_ref() {
                let (cycles, milestones) = app.planning_rows();
                m.render_with_bindings(
                    f,
                    area,
                    &cycles,
                    &milestones,
                    &app.bindings,
                    InputContext::PlanningManagement,
                );
            }
        }
        Mode::PlanningForm => {
            render_config_or_board(app, f, area);
            if let Some(fm) = app.planning_form.as_ref() {
                fm.render_with_bindings(f, area, &app.bindings, InputContext::PlanningForm);
            }
        }
        Mode::DatePicker { return_to } => {
            render_config_or_board(app, f, area);
            match return_to.as_ref() {
                Mode::Form => {
                    // The mode's content, so the picker overlays the form where it
                    // was actually drawn rather than a smaller modal rect.
                    if let Some(fr) = app.form.as_ref() {
                        form::render_with_bindings(fr, f, area, &app.bindings, InputContext::Form);
                    }
                }
                Mode::PlanningForm => {
                    if let Some(fm) = app.planning_form.as_ref() {
                        fm.render_with_bindings(f, area, &app.bindings, InputContext::PlanningForm);
                    }
                }
                Mode::FilterModal => {
                    if let Some(m) = app.filter_modal.as_ref() {
                        m.render_with_bindings(f, area, &app.bindings, InputContext::FilterModal);
                    }
                }
                _ => {}
            }
            if let Some(picker) = app.date_picker.as_ref() {
                picker.render_with_bindings(f, area, &app.bindings, InputContext::DatePicker);
                // Record the calendar grid and chrome so pointer clicks route
                // through the same key branches as keyboard input (D6).
                let rect = picker.popup_rect(area);
                let days_y = rect.y + 3;
                let weeks = rect.height.saturating_sub(6);
                for row in 0..weeks {
                    for col in 0..7u16 {
                        let x = rect.x + 1 + col * 3;
                        let y = days_y + row;
                        if let Some(date) = picker.date_at(area, x + 1, y) {
                            let hit = Rect {
                                x,
                                y,
                                width: 3,
                                height: 1,
                            };
                            app.record_region(
                                hit,
                                Action::DatePickerHit(DatePickerHit::Day(
                                    crate::ui::date_picker::format_date(date),
                                )),
                            );
                        }
                    }
                }
                let header_y = rect.y + 1;
                let header_w = rect.width.saturating_sub(2);
                let split = header_w / 2;
                if split > 0 {
                    app.record_region(
                        Rect {
                            x: rect.x + 1,
                            y: header_y,
                            width: split,
                            height: 1,
                        },
                        Action::DatePickerHit(DatePickerHit::PrevMonth),
                    );
                    app.record_region(
                        Rect {
                            x: rect.x + 1 + split,
                            y: header_y,
                            width: header_w - split,
                            height: 1,
                        },
                        Action::DatePickerHit(DatePickerHit::NextMonth),
                    );
                }
                app.record_region(
                    Rect {
                        x: rect.x,
                        y: rect.y + rect.height.saturating_sub(1),
                        width: rect.width,
                        height: 1,
                    },
                    Action::DatePickerHit(DatePickerHit::Submit),
                );
            }
        }
        Mode::Comment { buffer } => render_detail_input(app, f, area, "Comment", buffer),
        Mode::Asset { buffer } => render_detail_input(app, f, area, "Asset", buffer),
        // #1384: the label says the empty case out loud, because "blank clears" is
        // the one thing a user cannot infer from an empty prompt.
        Mode::ParentPrompt { buffer } => {
            render_detail_input(app, f, area, "Parent (blank clears)", buffer)
        }
        Mode::EditRepair {
            filename,
            message,
            key,
            problems,
            temp,
            discard_armed,
            ..
        } => render_edit_repair(
            app,
            f,
            area,
            filename,
            message,
            key.as_deref(),
            problems,
            temp.as_deref(),
            *discard_armed,
        ),
        // #1510. The prompt names both files — the temp copy and the newer
        // on-disk one — so "compare" is something the user can do by hand even
        // outside the editor the key offers.
        Mode::EditConflict {
            filename,
            temp,
            disk_path,
        } => render_edit_conflict(app, f, area, filename, temp, disk_path),
        // #1359. The prompt is labelled by which step it is asking, so "enter
        // something" is never the whole instruction — and the kind step says it is
        // **required**, which is the one thing a user needs to know before typing.
        Mode::LinkCreate { buffer, step, .. } | Mode::LinkEdit { buffer, step, .. } => {
            let label = match (step, matches!(app.mode, Mode::LinkEdit { .. })) {
                (LinkStep::Target, false) => "Link to issue",
                (LinkStep::Target, true) => "Re-target to issue (blank keeps)",
                (LinkStep::Kind, false) => "Kind (required)",
                (LinkStep::Kind, true) => "Kind (required)",
            };
            render_detail_input(app, f, area, label, buffer)
        }
        Mode::ConfirmRemoveRelationship { .. } => {
            if let Some(ref d) = app.detail {
                detail::render(d, f, area, &app.theme);
            }
            render_input_line(
                f,
                Rect {
                    y: area.y + area.height.saturating_sub(1),
                    height: 1,
                    ..area
                },
                "Remove relationship (y to confirm)",
                "",
            );
        }
    }
    render_action_feedback(app, f, area);
}

/// Draw the current action refusal over the bottom of the active mode.
///
/// The board, Schedule and a few forms already own message rows; drawing this
/// shared notice last guarantees newer top-level pages and overlays present the
/// same reason/remedy pair rather than writing a message no renderer reads.
fn render_action_feedback(app: &App, f: &mut ratatui::Frame, area: Rect) {
    let Some(feedback) = app.action_feedback.as_ref() else {
        return;
    };
    if area.height == 0 || area.width == 0 {
        return;
    }
    // A top border plus both text lines. Drawing the border over a two-row rect
    // would clip the remedy entirely.
    let height = area.height.min(3);
    let rect = Rect {
        y: area.y + area.height - height,
        height,
        ..area
    };
    let paragraph = Paragraph::new(vec![
        Line::from(Span::styled(
            feedback.reason_line(),
            Style::default()
                .fg(Color::Yellow)
                .add_modifier(Modifier::BOLD),
        )),
        Line::from(Span::styled(
            feedback.remedy_line(),
            Style::default().fg(Color::White),
        )),
    ])
    .style(Style::default().bg(Color::DarkGray))
    .block(Block::default().borders(Borders::TOP));
    f.render_widget(paragraph, rect);
}

/// Resolve the TUI's color theme (tix #1530): tag colors from the tag store
/// (`tags_dir`), type colors from `[type_colors]`/the shipped defaults, and
/// milestone colors from the milestone records.
///
/// Best-effort: a missing store or an unreadable registry contributes no colors
/// rather than failing startup — losing a color must never stop the TUI opening.
pub(in crate::app) fn theme_for(config: &Config) -> crate::ui::color::Theme {
    let tag_colors = crate::tags::TagStore::new(config.tags_dir())
        .colors()
        .unwrap_or_default();
    let mut type_colors = std::collections::HashMap::new();
    for type_name in config.types() {
        if let Some(color) = config
            .type_color(&type_name)
            .and_then(|name| crate::ui::color::parse(&name))
        {
            type_colors.insert(type_name.to_ascii_lowercase(), color);
        }
    }
    let mut milestone_colors = std::collections::HashMap::new();
    let planner = Planner::from_config(config.clone(), std::path::PathBuf::from("."));
    for milestone in planner.list_milestones().unwrap_or_default() {
        if let Some(color) = milestone.color.as_deref().and_then(crate::ui::color::parse) {
            milestone_colors.insert(milestone.name.to_ascii_lowercase(), color);
        }
    }
    crate::ui::color::Theme::new(tag_colors, type_colors, milestone_colors)
}

/// A template's defaults as `(field, value)` pairs, in the order the create form
/// fills them, skipping the unset ones — a `None`/empty default is not a default,
/// and listing it as one would make every template look alike.
pub(in crate::app) fn template_default_lines(
    defaults: &crate::templates::registry::TemplateDefaults,
) -> Vec<(String, String)> {
    let scalars: [(&str, Option<&String>); 11] = [
        ("title", defaults.title.as_ref()),
        ("status", defaults.status.as_ref()),
        ("priority", defaults.priority.as_ref()),
        ("assignee", defaults.assignee.as_ref()),
        ("estimate", defaults.estimate.as_ref()),
        ("reviewer", defaults.reviewer.as_ref()),
        ("start_date", defaults.start_date.as_ref()),
        ("due_date", defaults.due_date.as_ref()),
        ("parent", defaults.parent.as_ref()),
        ("type", defaults.type_.as_ref()),
        // The body is Markdown and can be long; it is listed last so it never
        // pushes the scalars off the pane.
        ("body", defaults.body.as_ref()),
    ];
    let lists: [(&str, &Vec<String>); 5] = [
        ("labels", &defaults.labels),
        ("files", &defaults.files),
        ("cycles", &defaults.cycles),
        ("milestones", &defaults.milestones),
        ("related_issues", &defaults.related_issues),
    ];
    let mut out: Vec<(String, String)> = scalars
        .into_iter()
        .filter_map(|(key, value)| value.map(|value| (key.to_string(), value.clone())))
        .collect();
    out.extend(lists.into_iter().filter_map(|(key, values)| {
        if values.is_empty() {
            None
        } else {
            Some((key.to_string(), values.join(", ")))
        }
    }));
    out
}

/// A template's one-line tail for a Library row (tix #1593): its scope and what
/// it actually carries, so a row says more than its id.
pub(in crate::app) fn template_subtitle(template: &crate::templates::registry::Template) -> String {
    let defaults = template_default_lines(&template.defaults).len();
    let mut out = template.scope.to_string();
    if let Some(name) = template.name.as_deref()
        && !name.is_empty()
    {
        out.push_str(&format!(" · {name}"));
    }
    out.push_str(&format!(
        " · {defaults} default{} · {} prompt{}",
        if defaults == 1 { "" } else { "s" },
        template.prompts.len(),
        if template.prompts.len() == 1 { "" } else { "s" }
    ));
    out
}

/// A view's stored plan as `key: value` detail lines, in the table's own order.
///
/// The plan is a `toml::Table` (the portable form), so this reads it rather than
/// re-deriving it from the typed filter: what the page shows is what is stored.
pub(in crate::app) fn plan_lines(plan: &toml::Table) -> Vec<(String, String)> {
    plan.iter()
        .map(|(key, value)| (format!("plan {key}"), toml_scalar(value)))
        .collect()
}

/// A `toml::Value` as display text: a string without its TOML quotes, anything
/// else in its TOML spelling (a number, a bool, an inline array).
pub(in crate::app) fn toml_scalar(value: &toml::Value) -> String {
    match value {
        toml::Value::String(text) => text.clone(),
        other => other.to_string(),
    }
}