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
use crate::charset::Charset;
use crate::config_manager::AppConfig;
use crate::theme::Theme;
use crate::video_buffer::{self, Cell, VideoBuffer};
/// Action to take based on config window interaction
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ConfigAction {
None,
#[allow(dead_code)]
Close,
ToggleAutoTiling,
ToggleShowDate,
CycleTheme,
CycleBackgroundChar,
ToggleTintTerminal,
}
/// Configuration modal window (centered, with border and title)
pub struct ConfigWindow {
pub width: u16,
pub height: u16,
pub x: u16,
pub y: u16,
auto_arrange_row: u16, // Row where auto arrange toggle is rendered
show_date_row: u16, // Row where show date toggle is rendered
theme_row: u16, // Row where theme selector is rendered
background_char_row: u16, // Row where background character selector is rendered
tint_terminal_row: u16, // Row where tint terminal toggle is rendered
}
impl ConfigWindow {
/// Create a new configuration window (centered on screen)
pub fn new(buffer_width: u16, buffer_height: u16) -> Self {
// Fixed dimensions for config window
let width = 60;
let height = 16; // Increased to fit all options including tint terminal
// Center on screen
let x = (buffer_width.saturating_sub(width)) / 2;
let y = (buffer_height.saturating_sub(height)) / 2;
// Calculate row positions for options
let auto_arrange_row = y + 3; // Title at y+1, blank at y+2, first option at y+3
let show_date_row = y + 5; // Blank at y+4, second option at y+5
let theme_row = y + 7; // Blank at y+6, third option at y+7
let background_char_row = y + 9; // Blank at y+8, fourth option at y+9
let tint_terminal_row = y + 11; // Blank at y+10, fifth option at y+11
Self {
width,
height,
x,
y,
auto_arrange_row,
show_date_row,
theme_row,
background_char_row,
tint_terminal_row,
}
}
/// Render the configuration window to the video buffer
pub fn render(
&self,
buffer: &mut VideoBuffer,
charset: &Charset,
theme: &Theme,
config: &AppConfig,
tint_terminal: bool,
) {
let title_bg = theme.config_title_bg;
let title_fg = theme.config_title_fg;
let border_color = theme.config_border;
let content_bg = theme.config_content_bg;
// Get border characters
let top_left = charset.border_top_left();
let top_right = charset.border_top_right();
let bottom_left = charset.border_bottom_left();
let bottom_right = charset.border_bottom_right();
let horizontal = charset.border_horizontal();
let vertical = charset.border_vertical();
// Draw top border with title
buffer.set(
self.x,
self.y,
Cell::new(top_left, border_color, content_bg),
);
let title = " Settings ";
let title_start = self.x + (self.width - title.len() as u16) / 2;
// Fill top border before title
for x in 1..title_start - self.x {
buffer.set(
self.x + x,
self.y,
Cell::new(horizontal, border_color, content_bg),
);
}
// Render title with special background
for (i, ch) in title.chars().enumerate() {
buffer.set(
title_start + i as u16,
self.y,
Cell::new(ch, title_fg, title_bg),
);
}
// Fill top border after title
for x in (title_start + title.len() as u16 - self.x)..(self.width - 1) {
buffer.set(
self.x + x,
self.y,
Cell::new(horizontal, border_color, content_bg),
);
}
buffer.set(
self.x + self.width - 1,
self.y,
Cell::new(top_right, border_color, content_bg),
);
// Draw content area with side borders
for y in 1..(self.height - 1) {
// Left border
buffer.set(
self.x,
self.y + y,
Cell::new(vertical, border_color, content_bg),
);
// Content area
for x in 1..(self.width - 1) {
buffer.set(
self.x + x,
self.y + y,
Cell::new(' ', theme.config_content_fg, content_bg),
);
}
// Right border
buffer.set(
self.x + self.width - 1,
self.y + y,
Cell::new(vertical, border_color, content_bg),
);
}
// Draw bottom border
buffer.set(
self.x,
self.y + self.height - 1,
Cell::new(bottom_left, border_color, content_bg),
);
for x in 1..(self.width - 1) {
buffer.set(
self.x + x,
self.y + self.height - 1,
Cell::new(horizontal, border_color, content_bg),
);
}
buffer.set(
self.x + self.width - 1,
self.y + self.height - 1,
Cell::new(bottom_right, border_color, content_bg),
);
// Render configuration options
self.render_option(
buffer,
self.auto_arrange_row,
"On startup Auto Tiling:",
config.auto_tiling_on_startup,
charset,
theme,
);
self.render_option(
buffer,
self.show_date_row,
"Show Date in clock:",
config.show_date_in_clock,
charset,
theme,
);
// Render theme selector
self.render_theme_selector(buffer, self.theme_row, &config.theme, theme);
// Render background character selector
self.render_background_char_selector(buffer, self.background_char_row, config, theme);
// Render tint terminal toggle
self.render_option(
buffer,
self.tint_terminal_row,
"Tint terminal content:",
tint_terminal,
charset,
theme,
);
// Render instruction at bottom
let instruction = "Press ESC to close";
let instruction_x = self.x + (self.width - instruction.len() as u16) / 2;
let instruction_y = self.y + self.height - 2;
for (i, ch) in instruction.chars().enumerate() {
buffer.set(
instruction_x + i as u16,
instruction_y,
Cell::new(ch, theme.config_instructions_fg, content_bg),
);
}
// Render shadow
video_buffer::render_shadow(
buffer,
self.x,
self.y,
self.width,
self.height,
charset,
theme,
);
}
/// Render a single configuration option with toggle
fn render_option(
&self,
buffer: &mut VideoBuffer,
row: u16,
label: &str,
enabled: bool,
charset: &Charset,
theme: &Theme,
) {
let fg = theme.config_content_fg;
let bg = theme.config_content_bg;
let option_x = self.x + 3; // 3 spaces from left border
// Render label
for (i, ch) in label.chars().enumerate() {
buffer.set(option_x + i as u16, row, Cell::new(ch, fg, bg));
}
// Render toggle indicator
let toggle_x = option_x + label.len() as u16 + 1;
if enabled {
// [█ on]
let toggle_on = format!("[{} on]", charset.block());
for (i, ch) in toggle_on.chars().enumerate() {
let color = if i == 1 {
theme.config_toggle_on_color
} else {
fg
}; // Block character in theme color
buffer.set(toggle_x + i as u16, row, Cell::new(ch, color, bg));
}
} else {
// [off ░]
let toggle_off = format!("[off {}]", charset.shade());
for (i, ch) in toggle_off.chars().enumerate() {
let color = if i == 4 {
theme.config_toggle_off_color
} else {
fg
}; // Shade character in theme color
buffer.set(toggle_x + i as u16, row, Cell::new(ch, color, bg));
}
}
}
/// Render theme selector showing current theme with arrows to cycle
fn render_theme_selector(
&self,
buffer: &mut VideoBuffer,
row: u16,
current_theme: &str,
theme: &Theme,
) {
let fg = theme.config_content_fg;
let bg = theme.config_content_bg;
let option_x = self.x + 3; // 3 spaces from left border
// Render label
let label = "Theme:";
for (i, ch) in label.chars().enumerate() {
buffer.set(option_x + i as u16, row, Cell::new(ch, fg, bg));
}
// Render theme selector: < classic >
let theme_display = match current_theme {
"classic" => "Classic",
"monochrome" => "Monochrome",
"dark" => "Dark",
"green_phosphor" => "Green Phosphor",
"amber" => "Amber",
_ => "Classic",
};
let selector_x = option_x + label.len() as u16 + 2;
let selector_text = format!("< {} >", theme_display);
for (i, ch) in selector_text.chars().enumerate() {
buffer.set(selector_x + i as u16, row, Cell::new(ch, fg, bg));
}
}
/// Render background character selector showing current character with arrows to cycle
fn render_background_char_selector(
&self,
buffer: &mut VideoBuffer,
row: u16,
config: &AppConfig,
theme: &Theme,
) {
let fg = theme.config_content_fg;
let bg = theme.config_content_bg;
let option_x = self.x + 3; // 3 spaces from left border
// Render label
let label = "Background character:";
for (i, ch) in label.chars().enumerate() {
buffer.set(option_x + i as u16, row, Cell::new(ch, fg, bg));
}
// Render character selector: < Light Shade [░] >
let char_name = config.get_background_char_name();
let char_sample = config.get_background_char();
let selector_x = option_x + label.len() as u16 + 2;
let selector_text = format!("< {} [{}] >", char_name, char_sample);
for (i, ch) in selector_text.chars().enumerate() {
buffer.set(selector_x + i as u16, row, Cell::new(ch, fg, bg));
}
}
/// Handle mouse click and return appropriate action
pub fn handle_click(&self, x: u16, y: u16) -> ConfigAction {
// Check if click is on auto tiling row
if y == self.auto_arrange_row {
// Click anywhere on the row toggles the option
if x >= self.x && x < self.x + self.width {
return ConfigAction::ToggleAutoTiling;
}
}
// Check if click is on show date row
if y == self.show_date_row {
// Click anywhere on the row toggles the option
if x >= self.x && x < self.x + self.width {
return ConfigAction::ToggleShowDate;
}
}
// Check if click is on theme row
if y == self.theme_row {
// Click anywhere on the row cycles the theme
if x >= self.x && x < self.x + self.width {
return ConfigAction::CycleTheme;
}
}
// Check if click is on background character row
if y == self.background_char_row {
// Click anywhere on the row cycles the background character
if x >= self.x && x < self.x + self.width {
return ConfigAction::CycleBackgroundChar;
}
}
// Check if click is on tint terminal row
if y == self.tint_terminal_row {
// Click anywhere on the row toggles the option
if x >= self.x && x < self.x + self.width {
return ConfigAction::ToggleTintTerminal;
}
}
ConfigAction::None
}
/// Check if point is within config window bounds
pub fn contains_point(&self, x: u16, y: u16) -> bool {
x >= self.x && x < self.x + self.width && y >= self.y && y < self.y + self.height
}
}