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
use crate::command_palette::catalog::chord_display;
use crate::config::Config;
use crate::help_content::{MODAL_SECTIONS, shortcut_sections};
use crate::ui_constants::{HELP_WINDOW_DEFAULT_HEIGHT, HELP_WINDOW_DEFAULT_WIDTH};
use egui::{Color32, Context, Frame, RichText, Window, epaint::Shadow};
use par_term_keybindings::KeybindingRegistry;
use std::cell::Cell;
/// The chord the registry currently binds to `action`, formatted the way the
/// palette formats it, or `"unbound"`.
fn live_chord(registry: &KeybindingRegistry, action: &str) -> String {
registry
.chord_for_action(action)
.map(|combo| chord_display(&combo))
.unwrap_or_else(|| "unbound".to_string())
}
/// Help UI manager using egui
pub struct HelpUI {
/// Whether the help window is currently visible
pub visible: bool,
}
impl HelpUI {
/// Create a new help UI
pub fn new() -> Self {
Self { visible: false }
}
/// Toggle help window visibility
pub fn toggle(&mut self) {
self.visible = !self.visible;
}
/// Show the help window. Every chord comes from `registry`, the live
/// bindings, and `keybindings`, the list it was built from (UX.md V12).
pub fn show(
&mut self,
ctx: &Context,
registry: &KeybindingRegistry,
keybindings: &[par_term_config::KeyBinding],
) {
if !self.visible {
return;
}
// Fully opaque regardless of terminal opacity — scoped to this
// panel (OV1: no global style writes).
let mut open = true;
let close_requested = Cell::new(false);
let viewport = ctx.input(|i| i.viewport_rect());
Window::new("Help")
.resizable(true)
.default_width(HELP_WINDOW_DEFAULT_WIDTH)
.default_height(HELP_WINDOW_DEFAULT_HEIGHT)
.default_pos(viewport.center())
.pivot(egui::Align2::CENTER_CENTER)
.open(&mut open)
.frame(
Frame::window(&ctx.global_style())
.fill(crate::app::overlay::theme::PANEL_FILL)
.stroke(egui::Stroke::NONE)
.shadow(Shadow {
offset: [0, 0],
blur: 0,
spread: 0,
color: Color32::TRANSPARENT,
}),
)
.show(ctx, |ui| {
crate::app::overlay::theme::solid_panel(ui);
egui::ScrollArea::vertical().show(ui, |ui| {
// About Section
ui.heading("About par-term");
ui.separator();
ui.horizontal(|ui| {
ui.label("Version:");
ui.label(RichText::new(env!("CARGO_PKG_VERSION")).strong());
});
ui.add_space(4.0);
ui.label(env!("CARGO_PKG_DESCRIPTION"));
ui.add_space(4.0);
ui.horizontal(|ui| {
ui.label("Author:");
ui.label(env!("CARGO_PKG_AUTHORS"));
});
ui.horizontal(|ui| {
ui.label("License:");
ui.label(env!("CARGO_PKG_LICENSE"));
});
ui.horizontal(|ui| {
ui.label("Repository:");
ui.hyperlink_to(env!("CARGO_PKG_REPOSITORY"), env!("CARGO_PKG_REPOSITORY"));
});
ui.add_space(12.0);
// Configuration Paths Section
ui.heading("Configuration Paths");
ui.separator();
let config_path = Config::config_path();
let shaders_dir = Config::shaders_dir();
ui.horizontal(|ui| {
ui.label("Config file:");
ui.label(RichText::new(config_path.display().to_string()).monospace());
});
ui.horizontal(|ui| {
ui.label("Shaders folder:");
ui.label(RichText::new(shaders_dir.display().to_string()).monospace());
});
ui.add_space(12.0);
// One-sentence model (UX.md 2.3)
ui.heading("Windows, Tabs, Panes, Sessions");
ui.separator();
ui.label(
"A window holds tabs; a tab holds panes. A window can be attached \
to one par-mux session, in which case its tabs live in the daemon \
and survive quitting par-term. Detach leaves them running; End \
session ends them.",
);
ui.add_space(12.0);
// Keyboard Shortcuts Section: generated (UX.md V12)
ui.heading("Keyboard Shortcuts");
ui.separator();
ui.label(
RichText::new(
"Generated from your current bindings; change them in \
Settings ▸ Input ▸ Keybindings. Unbound actions are not \
listed; the command palette reaches every action.",
)
.weak(),
);
ui.add_space(4.0);
egui::Grid::new("shortcuts_grid")
.num_columns(2)
.spacing([20.0, 4.0])
.striped(true)
.show(ui, |ui| {
for section in shortcut_sections(registry, keybindings) {
ui.label(RichText::new(section.title).strong().underline());
ui.end_row();
for row in §ion.rows {
shortcut_row(ui, &row.chord, &row.label);
}
ui.end_row();
}
for (title, rows) in MODAL_SECTIONS {
ui.label(RichText::new(*title).strong().underline());
ui.end_row();
for (keys, description) in *rows {
shortcut_row(ui, keys, description);
}
ui.end_row();
}
});
ui.add_space(12.0);
// Mouse Actions Section
ui.heading("Mouse Actions");
ui.separator();
egui::Grid::new("mouse_grid")
.num_columns(2)
.spacing([20.0, 4.0])
.striped(true)
.show(ui, |ui| {
shortcut_row(ui, "Click + drag", "Select text");
shortcut_row(ui, "Double / triple-click", "Select word / line");
shortcut_row(ui, "Middle-click", "Paste (if enabled)");
shortcut_row(ui, "Cmd/Ctrl+Click URL", "Open URL in browser");
shortcut_row(ui, "Scrollbar drag / click", "Scroll / jump");
shortcut_row(ui, "Middle-click a tab", "Close the tab");
shortcut_row(ui, "Double-click empty tab bar", "New tab");
});
ui.add_space(12.0);
// Tips Section
ui.heading("Tips");
ui.separator();
ui.label(
"• Configuration changes made in Settings are saved to the config file.",
);
ui.label(format!(
"• Press {} to reload config without restarting the terminal.",
live_chord(registry, "reload_config")
));
ui.label("• Custom shaders can be placed in the shaders folder.");
ui.label(format!(
"• {} opens the command palette: every action, searchable by name.",
live_chord(registry, "toggle_command_palette")
));
ui.add_space(12.0);
// Close button
ui.separator();
ui.horizontal(|ui| {
if ui.button("Close").clicked() {
close_requested.set(true);
}
ui.label(
RichText::new(format!(
"Press {} or Escape to close",
live_chord(registry, "toggle_help")
))
.weak(),
);
});
});
});
// Update visibility based on window state
if !open || close_requested.get() {
self.visible = false;
}
}
}
impl Default for HelpUI {
fn default() -> Self {
Self::new()
}
}
/// Helper function to add a shortcut row to the grid
fn shortcut_row(ui: &mut egui::Ui, shortcut: &str, description: &str) {
ui.label(RichText::new(shortcut).monospace().strong());
ui.label(description);
ui.end_row();
}
#[cfg(test)]
mod tests {
use super::*;
/// A rebind shows the new chord; an unbound action says so.
#[test]
fn live_chord_reads_the_registry() {
let rebound = KeybindingRegistry::from_config(&[par_term_config::KeyBinding {
key: "F9".to_string(),
action: "split_right".to_string(),
}]);
assert_eq!(live_chord(&rebound, "split_right"), "F9");
assert_eq!(live_chord(&rebound, "split_down"), "unbound");
}
/// V12: the panel holds no hand-maintained chord table. Its shortcut
/// rows come from `help_content`, whose tests prove they match the
/// shipped defaults.
#[test]
fn the_panel_renders_generated_sections() {
let source = include_str!("help_ui.rs");
let body = &source[..source.find("#[cfg(test)]").unwrap()];
assert!(body.contains("shortcut_sections(registry, keybindings)"));
assert!(!body.contains("REGISTRY_SHORTCUTS"));
assert!(!body.contains("\"Cmd+C"));
}
}