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
//! Shared trait definitions for par-term components.
//!
//! These traits document the contracts between major components and enable
//! mock implementations for unit testing the `app/` module without needing
//! a live PTY session or GPU context.
//!
//! # Status
//!
//! [`TerminalAccess`] is **fully implemented** on [`crate::terminal::TerminalManager`].
//! See [`crate::traits_impl`] for the concrete `impl` and a `MockTerminal` test helper.
//!
//! [`UIElement`] is **fully implemented** on [`crate::tab_bar_ui::TabBarUI`] and
//! [`crate::status_bar::StatusBarUI`].
//! See [`crate::traits_impl`] for the concrete impls and a compile-time test.
//!
//! `EventHandler` is still deferred — see the comment block at the end of this file.
//!
//! # Migration Path for `EventHandler`
//!
//! When the `WindowState` decomposition is further advanced:
//! 1. Define `EventHandler<E>` where `E = winit::event::WindowEvent` and implement it
//! on each sub-handler struct extracted from `WindowState`.
//! 2. Add mock implementations in `#[cfg(test)]` blocks.
// ── AUD-040: TerminalAccess ──────────────────────────────────────────────────
/// Provides read-only access to terminal mode and state for input/mouse handlers.
///
/// Implemented by `TerminalManager` (and mock types in tests). Decouples
/// `app/mouse_events/` and `app/input_events/` from the concrete terminal type,
/// enabling unit tests without a live PTY session.
///
/// # Notes
///
/// All methods take `&self` — this trait is intentionally read-only. State
/// mutation goes through `TerminalManager` directly (write, resize, etc.).
// ── AUD-041: UIElement ────────────────────────────────────────────────────────
/// Common interface for UI bar/panel components whose height and visibility
/// depend on per-frame context (configuration, window state).
///
/// # Design rationale
///
/// The previous stub used zero-argument methods for `height_logical`,
/// `width_logical`, and `is_visible`. This was incompatible with the concrete
/// types (`TabBarUI`, `StatusBarUI`) which all require `&Config` and additional
/// per-frame parameters to compute these values. Forcing them to cache a config
/// snapshot would introduce a new class of stale-config bugs.
///
/// The solution is a GAT (`type Ctx<'a>`) that lets each implementor declare
/// exactly what context it needs. The caller provides context at the call site;
/// no component stores a redundant snapshot.
///
/// # GAT note
///
/// GATs (`type X<'a>`) require Rust 1.65+. They have been stable since late
/// 2022 and are available in all supported rustc versions for this project.
///
/// # Concrete context types
///
/// - `TabBarUI::Ctx<'a> = TabBarCtx<'a>` — needs `(&Config, tab_count: usize)`
/// - `StatusBarUI::Ctx<'a> = StatusBarCtx<'a>` — needs `(&Config, is_fullscreen: bool)`
///
/// # Components that are excluded
///
/// `TmuxStatusBarUI::height` is a static method, not `&self`, so it cannot
/// implement this trait without a wrapper. It is documented as out-of-scope.
// ── R-10: OverlayComponent ────────────────────────────────────────────────────
/// Common interface for egui overlay UI components that follow the
/// `show(&mut self, ctx: &egui::Context) -> Self::Action` pattern.
///
/// # Design notes
///
/// Twelve or more UI dialogs in par-term share the same shape:
/// - they maintain a `visible: bool` field (or equivalent),
/// - they expose a `show` method that renders the dialog and returns an action,
/// - they can be hidden without producing an action.
///
/// This trait formalises that contract so callers can be written generically
/// and components become easier to test in isolation.
///
/// # Components that are excluded
///
/// The following components have additional required parameters on `show` and
/// cannot implement this trait without a wrapper:
/// - `HelpUI::show` — returns `()` (no action type)
/// - `TmuxSessionPickerUI::show` — requires `tmux_path: &str`
/// - `InspectorPanel::show` — requires `available_agents: &[AgentConfig]`
///
/// These are documented as out-of-scope in `docs/TRAITS.md` (future work).
// ── AUD-042: EventHandler — REMOVED ──────────────────────────────────────────
//
// The `EventHandler` trait was removed because wiring it up to the concrete
// `WindowState` dispatch chain is a larger structural refactor than can be done
// in this file alone. The trait will be reintroduced as part of that effort.
//
// Proposed future definition (kept here as a design record):
//
// pub trait EventHandler {
// fn handle_event(&mut self, event: winit::event::WindowEvent) -> bool;
// }
//
// To use this trait, each handler extracted from `WindowState` would implement it
// and `WindowState::on_window_event` would iterate a `Vec<Box<dyn EventHandler>>`.
// That decomposition is tracked in the `WindowState` refactor issue.