par-term-settings-ui 0.12.2

Settings UI for par-term terminal emulator
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
//! Profile badge appearance section for the edit view.

use super::ProfileModalUI;
use crate::section::collapsing_section;
use std::collections::HashSet;

impl ProfileModalUI {
    /// Render the badge appearance collapsing section (profile-level overrides).
    pub(super) fn render_badge_section(
        &mut self,
        ui: &mut egui::Ui,
        collapsed: &mut HashSet<String>,
    ) {
        collapsing_section(
            ui,
            "Badge Appearance",
            "profile_badge_appearance",
            false,
            collapsed,
            |ui| {
                egui::Grid::new("profile_form_badge_appearance")
                    .num_columns(2)
                    .spacing([10.0, 8.0])
                    .show(ui, |ui| {
                        // Badge color
                        ui.label("Color:");
                        ui.horizontal(|ui| {
                            let mut use_custom = self.temp_badge_color.is_some();
                            if ui.checkbox(&mut use_custom, "").changed() {
                                if use_custom {
                                    self.temp_badge_color = Some([255, 0, 0]); // Default red
                                } else {
                                    self.temp_badge_color = None;
                                }
                            }
                            if let Some(ref mut color) = self.temp_badge_color {
                                let mut egui_color =
                                    egui::Color32::from_rgb(color[0], color[1], color[2]);
                                if egui::color_picker::color_edit_button_srgba(
                                    ui,
                                    &mut egui_color,
                                    egui::color_picker::Alpha::Opaque,
                                )
                                .changed()
                                {
                                    *color = [egui_color.r(), egui_color.g(), egui_color.b()];
                                }
                            } else {
                                ui.label(
                                    egui::RichText::new("(use global)")
                                        .small()
                                        .color(egui::Color32::GRAY),
                                );
                            }
                        });
                        ui.end_row();

                        // Badge alpha/opacity
                        ui.label("Opacity:");
                        ui.horizontal(|ui| {
                            let mut use_custom = self.temp_badge_color_alpha.is_some();
                            if ui.checkbox(&mut use_custom, "").changed() {
                                if use_custom {
                                    self.temp_badge_color_alpha = Some(0.5);
                                } else {
                                    self.temp_badge_color_alpha = None;
                                }
                            }
                            if let Some(ref mut alpha) = self.temp_badge_color_alpha {
                                ui.add(egui::Slider::new(alpha, 0.0..=1.0).step_by(0.05));
                            } else {
                                ui.label(
                                    egui::RichText::new("(use global)")
                                        .small()
                                        .color(egui::Color32::GRAY),
                                );
                            }
                        });
                        ui.end_row();

                        // Badge font
                        ui.label("Font:");
                        ui.horizontal(|ui| {
                            ui.text_edit_singleline(&mut self.temp_badge_font);
                            ui.label(
                                egui::RichText::new("(blank = global)")
                                    .small()
                                    .color(egui::Color32::GRAY),
                            );
                        });
                        ui.end_row();

                        // Badge font bold
                        ui.label("Bold:");
                        ui.horizontal(|ui| {
                            let mut use_custom = self.temp_badge_font_bold.is_some();
                            if ui.checkbox(&mut use_custom, "").changed() {
                                if use_custom {
                                    self.temp_badge_font_bold = Some(true);
                                } else {
                                    self.temp_badge_font_bold = None;
                                }
                            }
                            if let Some(ref mut bold) = self.temp_badge_font_bold {
                                ui.checkbox(bold, "Bold text");
                            } else {
                                ui.label(
                                    egui::RichText::new("(use global)")
                                        .small()
                                        .color(egui::Color32::GRAY),
                                );
                            }
                        });
                        ui.end_row();

                        // Badge top margin
                        ui.label("Top Margin:");
                        ui.horizontal(|ui| {
                            let mut use_custom = self.temp_badge_top_margin.is_some();
                            if ui.checkbox(&mut use_custom, "").changed() {
                                if use_custom {
                                    self.temp_badge_top_margin = Some(0.0);
                                } else {
                                    self.temp_badge_top_margin = None;
                                }
                            }
                            if let Some(ref mut margin) = self.temp_badge_top_margin {
                                ui.add(
                                    egui::DragValue::new(margin)
                                        .range(0.0..=100.0)
                                        .suffix(" px"),
                                );
                            } else {
                                ui.label(
                                    egui::RichText::new("(use global)")
                                        .small()
                                        .color(egui::Color32::GRAY),
                                );
                            }
                        });
                        ui.end_row();

                        // Badge right margin
                        ui.label("Right Margin:");
                        ui.horizontal(|ui| {
                            let mut use_custom = self.temp_badge_right_margin.is_some();
                            if ui.checkbox(&mut use_custom, "").changed() {
                                if use_custom {
                                    self.temp_badge_right_margin = Some(16.0);
                                } else {
                                    self.temp_badge_right_margin = None;
                                }
                            }
                            if let Some(ref mut margin) = self.temp_badge_right_margin {
                                ui.add(
                                    egui::DragValue::new(margin)
                                        .range(0.0..=100.0)
                                        .suffix(" px"),
                                );
                            } else {
                                ui.label(
                                    egui::RichText::new("(use global)")
                                        .small()
                                        .color(egui::Color32::GRAY),
                                );
                            }
                        });
                        ui.end_row();

                        // Badge max width
                        ui.label("Max Width:");
                        ui.horizontal(|ui| {
                            let mut use_custom = self.temp_badge_max_width.is_some();
                            if ui.checkbox(&mut use_custom, "").changed() {
                                if use_custom {
                                    self.temp_badge_max_width = Some(0.5);
                                } else {
                                    self.temp_badge_max_width = None;
                                }
                            }
                            if let Some(ref mut width) = self.temp_badge_max_width {
                                ui.add(
                                    egui::Slider::new(width, 0.1..=1.0)
                                        .step_by(0.05)
                                        .custom_formatter(|v, _| format!("{:.0}%", v * 100.0)),
                                );
                            } else {
                                ui.label(
                                    egui::RichText::new("(use global)")
                                        .small()
                                        .color(egui::Color32::GRAY),
                                );
                            }
                        });
                        ui.end_row();

                        // Badge max height
                        ui.label("Max Height:");
                        ui.horizontal(|ui| {
                            let mut use_custom = self.temp_badge_max_height.is_some();
                            if ui.checkbox(&mut use_custom, "").changed() {
                                if use_custom {
                                    self.temp_badge_max_height = Some(0.2);
                                } else {
                                    self.temp_badge_max_height = None;
                                }
                            }
                            if let Some(ref mut height) = self.temp_badge_max_height {
                                ui.add(
                                    egui::Slider::new(height, 0.05..=0.5)
                                        .step_by(0.05)
                                        .custom_formatter(|v, _| format!("{:.0}%", v * 100.0)),
                                );
                            } else {
                                ui.label(
                                    egui::RichText::new("(use global)")
                                        .small()
                                        .color(egui::Color32::GRAY),
                                );
                            }
                        });
                        ui.end_row();
                    });

                ui.add_space(4.0);
                ui.label(
                    egui::RichText::new(
                        "Check boxes to override global badge settings for this profile.",
                    )
                    .small()
                    .color(egui::Color32::GRAY),
                );
            },
        );
    }

    /// Render per-profile shader override settings.
    pub(super) fn render_shader_section(
        &mut self,
        ui: &mut egui::Ui,
        collapsed: &mut HashSet<String>,
    ) {
        collapsing_section(
            ui,
            "Shader Overrides",
            "profile_shader_overrides",
            false,
            collapsed,
            |ui| {
                ui.label(
                    egui::RichText::new(
                        "Optional background shader settings applied when this profile opens.",
                    )
                    .small()
                    .color(egui::Color32::GRAY),
                );
                ui.add_space(6.0);

                egui::Grid::new("profile_shader_form")
                    .num_columns(2)
                    .spacing([10.0, 8.0])
                    .show(ui, |ui| {
                        ui.label("Shader:");
                        ui.horizontal(|ui| {
                            ui.text_edit_singleline(&mut self.temp_shader);
                            ui.label(egui::RichText::new("(blank = global)").small().weak());
                        });
                        ui.end_row();

                        optional_slider_row(
                            ui,
                            "Brightness:",
                            &mut self.temp_shader_brightness,
                            0.05..=1.0,
                            0.35,
                        );
                        optional_slider_row(
                            ui,
                            "Text opacity:",
                            &mut self.temp_shader_text_opacity,
                            0.0..=1.0,
                            1.0,
                        );
                        optional_slider_row(
                            ui,
                            "Animation speed:",
                            &mut self.temp_shader_animation_speed,
                            0.0..=5.0,
                            1.0,
                        );

                        for index in 0..4 {
                            ui.label(format!("iChannel{}:", index));
                            ui.horizontal(|ui| {
                                ui.text_edit_singleline(&mut self.temp_shader_channels[index]);
                                ui.label(egui::RichText::new("(blank = inherit)").small().weak());
                            });
                            ui.end_row();
                        }
                    });
            },
        );
    }

    /// Render the tmux auto-connect collapsing section.
    pub(super) fn render_tmux_section(
        &mut self,
        ui: &mut egui::Ui,
        collapsed: &mut HashSet<String>,
    ) {
        collapsing_section(
            ui,
            "Tmux Auto-Connect",
            "profile_tmux",
            false,
            collapsed,
            |ui| {
                ui.label(
                    egui::RichText::new(
                        "Automatically connect to a tmux session when this profile opens.",
                    )
                    .small()
                    .color(egui::Color32::GRAY),
                );
                ui.add_space(6.0);

                egui::Grid::new("profile_tmux_form")
                    .num_columns(2)
                    .spacing([10.0, 8.0])
                    .show(ui, |ui| {
                        ui.label("Session Name:");
                        ui.horizontal(|ui| {
                            ui.text_edit_singleline(&mut self.temp_tmux_session_name);
                            ui.label(
                                egui::RichText::new("(empty = disabled)")
                                    .small()
                                    .color(egui::Color32::GRAY),
                            );
                        });
                        ui.end_row();

                        ui.label("Connection Mode:");
                        ui.horizontal(|ui| {
                            ui.radio_value(
                                &mut self.temp_tmux_connection_mode,
                                par_term_config::TmuxConnectionMode::ControlMode,
                                "Control Mode",
                            )
                            .on_hover_text(
                                "Full par-term integration via tmux -CC. Enables pane sync, layout, and input routing.",
                            );
                            ui.add_space(8.0);
                            ui.radio_value(
                                &mut self.temp_tmux_connection_mode,
                                par_term_config::TmuxConnectionMode::Normal,
                                "Normal",
                            )
                            .on_hover_text(
                                "Plain tmux running in the terminal. No par-term integration.",
                            );
                        });
                        ui.end_row();
                    });
            },
        );
    }

    /// Render the SSH connection collapsing section.
    pub(super) fn render_ssh_section(
        &mut self,
        ui: &mut egui::Ui,
        collapsed: &mut HashSet<String>,
    ) {
        collapsing_section(
            ui,
            "SSH Connection",
            "profile_ssh_connection",
            false,
            collapsed,
            |ui| {
                ui.horizontal(|ui| {
                    ui.label("Host:");
                    ui.text_edit_singleline(&mut self.temp_ssh_host);
                });
                ui.horizontal(|ui| {
                    ui.label("User:");
                    ui.text_edit_singleline(&mut self.temp_ssh_user);
                });
                ui.horizontal(|ui| {
                    ui.label("Port:");
                    ui.add(egui::TextEdit::singleline(&mut self.temp_ssh_port).desired_width(60.0));
                });
                ui.horizontal(|ui| {
                    ui.label("Identity File:");
                    ui.text_edit_singleline(&mut self.temp_ssh_identity_file);
                });
                ui.horizontal(|ui| {
                    ui.label("Extra Args:");
                    ui.text_edit_singleline(&mut self.temp_ssh_extra_args);
                });
                ui.add_space(4.0);
                ui.label(
                    egui::RichText::new(
                        "When SSH Host is set, opening this profile connects via SSH instead of launching a shell.",
                    )
                    .weak()
                    .size(11.0),
                );
            },
        );
    }
}

fn optional_slider_row(
    ui: &mut egui::Ui,
    label: &str,
    value: &mut Option<f32>,
    range: std::ops::RangeInclusive<f32>,
    default_value: f32,
) {
    ui.label(label);
    ui.horizontal(|ui| {
        let mut use_custom = value.is_some();
        if ui.checkbox(&mut use_custom, "").changed() {
            *value = if use_custom {
                Some(default_value)
            } else {
                None
            };
        }
        if let Some(current) = value {
            ui.add(egui::Slider::new(current, range));
        } else {
            ui.label(egui::RichText::new("(use global)").small().weak());
        }
    });
    ui.end_row();
}