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
//! `tga tui` — an interactive terminal view over collection and correlation.
//!
//! Why: `tga collect` and `tga classify` are minutes-long batch commands whose
//! only progress surface is an `indicatif` bar that is hidden off-TTY, and the
//! commit ↔ board-item correlation stored in `commit_work_items` had no view at
//! all. #5197 adds one screen that picks repositories from the existing config,
//! shows the pipelines running live off the [`tga::core::progress`] bus, and
//! reports which commits reached the board and which did not.
//!
//! What: a subcommand of the existing `tga` binary (not a new crate), built on
//! ratatui 0.29 / crossterm 0.28 — the versions already in the workspace
//! dependency table and the ones `trusty_common`'s `monitor-tui` feature uses,
//! so there is exactly one ratatui major in the build graph. The file split
//! follows the house pattern in `trusty_common::monitor::search_tui`:
//! [`state`] holds everything drawn, [`render`] draws it, [`event_loop`] maps
//! keys, and [`work`] owns the database and the background runs.
//!
//! **Zero inference is the default.** Every view, every pull, and the whole
//! correlation pass are deterministic: no model is consulted and no API key is
//! read anywhere in this module or in [`tga::collect::correlate`]. `[c]` runs
//! the correlation pass with no network at all. Inference stays where it
//! already is — the classify cascade's opt-in tier 4 — and switching it off
//! changes nothing here.
//!
//! Terminal hygiene is a correctness requirement, in two directions. Raw mode
//! and the alternate screen are restored on normal exit, on error, and on
//! panic (see [`install_panic_hook`]) — and while the screen IS ours, nothing
//! in the process may write to it behind ratatui's back. Three things used to:
//! the revwalk's `indicatif` spinner (now suppressed whenever a progress bus is
//! attached), the collect pipeline's `println!` / `eprintln!` lines (now routed
//! to the bus by `tga::collect`'s `notify`), and the `tracing` subscriber
//! itself (now diverted into [`capture`] and rendered in the ACTIVITY pane).
//! A stray write is not cosmetic: ratatui's diff renderer never repaints a cell
//! it believes unchanged, so it survives every later redraw (#5197).
//!
//! Test: `tests` in this module covers the picker, the key map, the state
//! transitions, and the zero-credential path.
use ;
use Config;
use Database;
use ;
use crateTuiArgs;
use TuiState;
use WorkerHandle;
pub use LogCapture;
/// Restore the terminal from raw mode and the alternate screen.
///
/// Why: `leave_tui` needs a live `Terminal`, which a panicking thread has
/// already given up. This talks to stdout directly so the same restoration
/// works from a panic hook.
/// What: disables raw mode, releases mouse capture, leaves the alternate
/// screen, and shows the cursor. Every step is best-effort — a terminal that
/// is already restored must not turn this into a second failure.
/// Test: side-effect-only terminal glue.
/// Wrap the current panic hook so a panic never leaves the terminal wedged.
///
/// Why: a panic inside the draw loop unwinds past every `leave_tui` call, and
/// an operator left in raw mode on the alternate screen has a shell that does
/// not echo and does not scroll. That is a defect, not a rough edge.
/// What: installs a hook that restores the terminal and stops diverting
/// `tracing` (#5197 — a swallowed log line after a panic is a lost diagnosis),
/// then delegates to whatever hook was installed before so the backtrace still
/// prints.
/// Test: side-effect-only; verified by panicking inside the loop by hand.
/// Run `tga tui`.
///
/// Why: the single entry point `main.rs` dispatches to.
/// What: builds the state from `config`, opens a read connection at
/// `db_path`, then hands the terminal to a blocking task so the draw loop
/// never occupies an async worker while the pipelines run on the same runtime.
/// The terminal is restored on every exit path — normal, error, and panic.
///
/// # Errors
///
/// Returns an error when the database cannot be opened, when terminal setup
/// fails, or when the loop itself fails. The terminal is restored first in
/// every one of those cases.
///
/// `logs` is the [`LogCapture`] `main.rs` installed as the tracing writer; the
/// TUI arms it for exactly as long as it owns the screen (#5197).
pub async
/// The blocking half of [`run`]: terminal setup, loop, teardown.
///
/// Why: split out so the `spawn_blocking` closure stays a one-liner and the
/// teardown ordering is readable.
/// What: installs the panic hook, opens the database, enters the alternate
/// screen, runs the loop, and restores the terminal before returning either
/// result.
/// Test: side-effect-only glue.