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
//! Keyboard and modifier remapping settings sections.
use crate::SettingsUI;
use crate::section::collapsing_section;
use par_term_config::{ModifierTarget, OptionKeyMode};
use std::collections::HashSet;
// ============================================================================
// Keyboard Section
// ============================================================================
pub(super) fn show_keyboard_section(
ui: &mut egui::Ui,
settings: &mut SettingsUI,
changes_this_frame: &mut bool,
collapsed: &mut HashSet<String>,
) {
collapsing_section(ui, "Keyboard", "input_keyboard", true, collapsed, |ui| {
ui.label("Option/Alt key behavior for emacs, vim, and other terminal applications.");
ui.add_space(4.0);
// Left Option/Alt key mode
ui.horizontal(|ui| {
ui.label("Left Option/Alt sends:");
let current = settings.config.left_option_key_mode;
egui::ComboBox::from_id_salt("input_left_option_key_mode")
.selected_text(option_key_mode_label(current))
.show_ui(ui, |ui| {
for mode in [
OptionKeyMode::Esc,
OptionKeyMode::Meta,
OptionKeyMode::Normal,
] {
if ui
.selectable_value(
&mut settings.config.left_option_key_mode,
mode,
option_key_mode_label(mode),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
});
ui.indent("input_left_option_desc", |ui| {
ui.label(
egui::RichText::new(option_key_mode_description(
settings.config.left_option_key_mode,
))
.weak()
.small(),
);
});
ui.add_space(8.0);
// Right Option/Alt key mode
ui.horizontal(|ui| {
ui.label("Right Option/Alt sends:");
let current = settings.config.right_option_key_mode;
egui::ComboBox::from_id_salt("input_right_option_key_mode")
.selected_text(option_key_mode_label(current))
.show_ui(ui, |ui| {
for mode in [
OptionKeyMode::Esc,
OptionKeyMode::Meta,
OptionKeyMode::Normal,
] {
if ui
.selectable_value(
&mut settings.config.right_option_key_mode,
mode,
option_key_mode_label(mode),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
});
ui.indent("input_right_option_desc", |ui| {
ui.label(
egui::RichText::new(option_key_mode_description(
settings.config.right_option_key_mode,
))
.weak()
.small(),
);
});
ui.add_space(8.0);
ui.separator();
// Physical key preference
if ui
.checkbox(
&mut settings.config.use_physical_keys,
"Use physical key positions for keybindings",
)
.on_hover_text(
"Match keybindings by key position (scan code) instead of character produced.\n\
This makes shortcuts like Ctrl+Z work consistently across keyboard layouts\n\
(QWERTY, AZERTY, Dvorak, etc.).",
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
ui.add_space(8.0);
ui.separator();
ui.label(egui::RichText::new("Tips:").strong());
ui.label("• Use \"Esc\" mode for emacs Meta key (M-x, M-f, M-b, etc.)");
ui.label("• Use \"Esc\" mode for vim Alt mappings");
ui.label("• Use \"Normal\" to type special characters (ƒ, ∂, ß, etc.)");
ui.label("• Enable physical keys if shortcuts feel wrong on non-US layouts");
});
}
// ============================================================================
// Modifier Remapping Section
// ============================================================================
pub(super) fn show_modifier_remapping_section(
ui: &mut egui::Ui,
settings: &mut SettingsUI,
changes_this_frame: &mut bool,
collapsed: &mut HashSet<String>,
) {
collapsing_section(
ui,
"Modifier Remapping",
"input_modifier_remapping",
false,
collapsed,
|ui| {
ui.label("Remap modifier keys to different functions.");
ui.label(
egui::RichText::new(
"Note: Changes apply to par-term keybindings only, not system-wide.",
)
.weak()
.small(),
);
ui.add_space(4.0);
// Left Ctrl
ui.horizontal(|ui| {
ui.label("Left Ctrl acts as:");
let current = settings.config.modifier_remapping.left_ctrl;
egui::ComboBox::from_id_salt("input_remap_left_ctrl")
.selected_text(current.display_name())
.show_ui(ui, |ui| {
for target in ModifierTarget::all() {
if ui
.selectable_value(
&mut settings.config.modifier_remapping.left_ctrl,
*target,
target.display_name(),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
});
// Right Ctrl
ui.horizontal(|ui| {
ui.label("Right Ctrl acts as:");
let current = settings.config.modifier_remapping.right_ctrl;
egui::ComboBox::from_id_salt("input_remap_right_ctrl")
.selected_text(current.display_name())
.show_ui(ui, |ui| {
for target in ModifierTarget::all() {
if ui
.selectable_value(
&mut settings.config.modifier_remapping.right_ctrl,
*target,
target.display_name(),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
});
ui.add_space(4.0);
// Left Alt
ui.horizontal(|ui| {
ui.label("Left Alt acts as:");
let current = settings.config.modifier_remapping.left_alt;
egui::ComboBox::from_id_salt("input_remap_left_alt")
.selected_text(current.display_name())
.show_ui(ui, |ui| {
for target in ModifierTarget::all() {
if ui
.selectable_value(
&mut settings.config.modifier_remapping.left_alt,
*target,
target.display_name(),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
});
// Right Alt
ui.horizontal(|ui| {
ui.label("Right Alt acts as:");
let current = settings.config.modifier_remapping.right_alt;
egui::ComboBox::from_id_salt("input_remap_right_alt")
.selected_text(current.display_name())
.show_ui(ui, |ui| {
for target in ModifierTarget::all() {
if ui
.selectable_value(
&mut settings.config.modifier_remapping.right_alt,
*target,
target.display_name(),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
});
ui.add_space(4.0);
#[cfg(target_os = "macos")]
let super_label = "Cmd";
#[cfg(not(target_os = "macos"))]
let super_label = "Super";
// Left Super/Cmd
ui.horizontal(|ui| {
ui.label(format!("Left {} acts as:", super_label));
let current = settings.config.modifier_remapping.left_super;
egui::ComboBox::from_id_salt("input_remap_left_super")
.selected_text(current.display_name())
.show_ui(ui, |ui| {
for target in ModifierTarget::all() {
if ui
.selectable_value(
&mut settings.config.modifier_remapping.left_super,
*target,
target.display_name(),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
});
// Right Super/Cmd
ui.horizontal(|ui| {
ui.label(format!("Right {} acts as:", super_label));
let current = settings.config.modifier_remapping.right_super;
egui::ComboBox::from_id_salt("input_remap_right_super")
.selected_text(current.display_name())
.show_ui(ui, |ui| {
for target in ModifierTarget::all() {
if ui
.selectable_value(
&mut settings.config.modifier_remapping.right_super,
*target,
target.display_name(),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
});
ui.add_space(8.0);
if ui.button("Reset to defaults").clicked() {
settings.config.modifier_remapping = Default::default();
settings.has_changes = true;
*changes_this_frame = true;
}
},
);
}
// ============================================================================
// Helper functions
// ============================================================================
fn option_key_mode_label(mode: OptionKeyMode) -> &'static str {
match mode {
OptionKeyMode::Normal => "Normal",
OptionKeyMode::Meta => "Meta",
OptionKeyMode::Esc => "Esc (Recommended)",
}
}
fn option_key_mode_description(mode: OptionKeyMode) -> &'static str {
match mode {
OptionKeyMode::Normal => {
"Sends special characters (e.g., Option+f → ƒ). Default macOS behavior."
}
OptionKeyMode::Meta => {
"Sets high bit on character (e.g., Option+f → 0xE6). Legacy Meta key mode."
}
OptionKeyMode::Esc => {
"Sends Escape prefix (e.g., Option+f → ESC f). Best for emacs/vim compatibility."
}
}
}