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
use crate::SettingsUI;
use crate::section::collapsing_section_with_state;
use arboard::Clipboard;
use egui::Color32;
use std::collections::HashSet;
use super::cursor_shader_metadata::show_cursor_shader_metadata_and_settings;
pub fn show_cursor_shader(
ui: &mut egui::Ui,
settings: &mut SettingsUI,
changes_this_frame: &mut bool,
collapsed: &mut HashSet<String>,
) {
collapsing_section_with_state(
ui,
"Cursor Shader",
"cursor_shader",
true,
collapsed,
|ui, collapsed| {
ui.label("Apply shader effects to cursor (trails, glow, etc.)");
ui.add_space(4.0);
// Cursor shader selection dropdown
ui.horizontal(|ui| {
ui.label("Shader:");
let selected_text = if settings.temp_cursor_shader.is_empty() {
"(none)".to_string()
} else {
settings.temp_cursor_shader.clone()
};
let mut shader_changed = false;
egui::ComboBox::from_id_salt("cursor_shader_select")
.selected_text(&selected_text)
.width(200.0)
.show_ui(ui, |ui| {
// Option to select none
if ui
.selectable_label(settings.temp_cursor_shader.is_empty(), "(none)")
.clicked()
{
settings.temp_cursor_shader.clear();
settings.config.shader.cursor_shader = None;
shader_changed = true;
}
// List available cursor shaders (only cursor_* shaders)
for shader in &settings.cursor_shaders() {
let is_selected = settings.temp_cursor_shader == *shader;
if ui.selectable_label(is_selected, shader).clicked() {
settings.temp_cursor_shader = shader.clone();
settings.config.shader.cursor_shader = Some(shader.clone());
shader_changed = true;
}
}
});
if shader_changed {
settings.has_changes = true;
*changes_this_frame = true;
}
// Refresh button
if ui
.button("↻")
.on_hover_text("Refresh shader list")
.clicked()
{
settings.refresh_shaders();
}
});
// Browse button for cursor shader
ui.horizontal(|ui| {
if ui
.button("Browse...")
.on_hover_text("Browse for external shader file")
.clicked()
&& let Some(path) = settings.pick_file_path("Select cursor shader file")
{
settings.temp_cursor_shader = path.clone();
settings.config.shader.cursor_shader = Some(path);
settings.has_changes = true;
*changes_this_frame = true;
}
});
// Show cursor shader compilation error if any
if let Some(error) = &settings.cursor_shader_editor_error {
let shader_path =
par_term_config::Config::shader_path(&settings.temp_cursor_shader);
let full_error = format!("File: {}\n\n{}", shader_path.display(), error);
let error_display = error.clone();
ui.add_space(4.0);
egui::Frame::default()
.fill(Color32::from_rgb(80, 20, 20))
.inner_margin(8.0)
.outer_margin(0.0)
.corner_radius(4.0)
.show(ui, |ui| {
ui.horizontal(|ui| {
ui.colored_label(
Color32::from_rgb(255, 100, 100),
"⚠ Cursor Shader Error",
);
ui.with_layout(
egui::Layout::right_to_left(egui::Align::Center),
|ui| {
if ui.small_button("Copy").clicked()
&& let Ok(mut clipboard) = Clipboard::new()
{
let _ = clipboard.set_text(full_error.clone());
}
},
);
});
// Show shader path on its own line
ui.label(format!("File: {}", shader_path.display()));
ui.separator();
// Show error details with word wrap
ui.add(
egui::TextEdit::multiline(&mut error_display.as_str())
.font(egui::TextStyle::Monospace)
.desired_width(f32::INFINITY)
.desired_rows(3)
.interactive(false),
);
});
ui.add_space(4.0);
}
// Show cursor shader metadata and per-shader settings if a shader is selected
if !settings.temp_cursor_shader.is_empty() {
show_cursor_shader_metadata_and_settings(
ui,
settings,
changes_this_frame,
collapsed,
);
}
if ui
.checkbox(
&mut settings.config.shader.cursor_shader_enabled,
"Enable cursor shader",
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
if ui
.checkbox(
&mut settings.config.shader.cursor_shader_animation,
"Enable cursor shader animation",
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
ui.horizontal(|ui| {
ui.label("Animation speed:");
if ui
.add(egui::Slider::new(
&mut settings.config.shader.cursor_shader_animation_speed,
0.0..=5.0,
))
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
});
if ui
.checkbox(
&mut settings.config.shader.cursor_shader_hides_cursor,
"Hide default cursor (let shader handle it)",
)
.on_hover_text("When enabled, the normal cursor is not drawn, allowing the cursor shader to fully replace cursor rendering")
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
if ui
.checkbox(
&mut settings.config.shader.cursor_shader_disable_in_alt_screen,
"Disable cursor shader in alt screen (vim/less/htop)",
)
.on_hover_text("When enabled, cursor shader effects pause while an application is using the alt screen")
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
ui.horizontal(|ui| {
ui.label("Cursor color:");
let mut color = settings.config.shader.cursor_shader_color;
if ui
.color_edit_button_srgb(&mut color)
.on_hover_text("Color passed to cursor shader via iCursorShaderColor uniform")
.changed()
{
settings.config.shader.cursor_shader_color = color;
settings.has_changes = true;
*changes_this_frame = true;
}
});
ui.add_space(8.0);
// Edit Shader button - only enabled when a shader path is set
let has_shader_path = !settings.temp_cursor_shader.is_empty();
ui.horizontal(|ui| {
let edit_button =
ui.add_enabled(has_shader_path, egui::Button::new("Edit Cursor Shader..."));
if edit_button.clicked() {
// Load shader source from file
let shader_path =
par_term_config::Config::shader_path(&settings.temp_cursor_shader);
match std::fs::read_to_string(&shader_path) {
Ok(source) => {
settings.cursor_shader_editor_source = source.clone();
settings.cursor_shader_editor_original = source;
settings.cursor_shader_editor_error = None;
settings.cursor_shader_editor_visible = true;
}
Err(e) => {
settings.cursor_shader_editor_error = Some(format!(
"Failed to read cursor shader file '{}': {}",
shader_path.display(),
e
));
}
}
}
if !has_shader_path {
ui.label("(set shader path first)");
}
});
},
);
}