par-term 0.30.11

Cross-platform GPU-accelerated terminal emulator with inline graphics support (Sixel, iTerm2, Kitty)
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
//! Integration tests for general Config settings.
//!
//! Covers: basic defaults, serialization/deserialization, power saving, initial text,
//! tab bar colors, inactive tab dimming, cursor enhancements, answerback string,
//! and advanced mouse features.

#![allow(clippy::field_reassign_with_default)]

use par_term::config::{Config, UnfocusedCursorStyle};

#[test]
fn test_config_defaults() {
    let config = Config::default();
    assert_eq!(config.cols, 80);
    assert_eq!(config.rows, 24);
    assert_eq!(config.font_size, 13.0);
    assert_eq!(config.font_family, "JetBrains Mono");
    assert_eq!(config.line_spacing, 1.0);
    assert_eq!(config.char_spacing, 1.0);
    assert_eq!(config.scrollback.scrollback_lines, 10000);
    assert_eq!(config.window_title, "par-term");
    assert_eq!(config.theme, "dark-background");
    assert!(config.auto_copy_selection);
    assert!(config.middle_click_paste);
    assert!(!config.copy_trailing_newline); // Inverted logic: false means strip trailing newline
    assert_eq!(config.screenshot_format, "png");
    // Session undo defaults
    assert_eq!(config.session_undo_timeout_secs, 5);
    assert_eq!(config.session_undo_max_entries, 10);
    assert!(!config.session_undo_preserve_shell);
}

#[test]
fn test_config_with_title() {
    let config = Config::default().with_title("My Terminal");
    assert_eq!(config.window_title, "My Terminal");
}

#[test]
fn test_config_yaml_serialization() {
    let config = Config::default();
    let yaml = serde_yaml_ng::to_string(&config).unwrap();
    assert!(yaml.contains("cols: 80"));
    assert!(yaml.contains("rows: 24"));
    assert!(yaml.contains("font_size: 13.0"));
}

#[test]
fn test_config_yaml_deserialization() {
    let yaml = r#"
cols: 100
rows: 30
font_size: 16.0
font_family: "Consolas"
scrollback_size: 5000
window_title: "Test Terminal"
theme: "light-background"
auto_copy_selection: true
middle_click_paste: false
screenshot_format: "svg"
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.cols, 100);
    assert_eq!(config.rows, 30);
    assert_eq!(config.font_size, 16.0);
    assert_eq!(config.font_family, "Consolas");
    assert_eq!(config.scrollback.scrollback_lines, 5000); // Tests backward compatibility via alias
    assert_eq!(config.window_title, "Test Terminal");
    assert_eq!(config.theme, "light-background");
    assert!(config.auto_copy_selection);
    assert!(!config.middle_click_paste);
    assert_eq!(config.screenshot_format, "svg");
}

#[test]
fn test_config_partial_yaml() {
    // Test that default values are used for missing fields
    let yaml = r#"
cols: 100
font_size: 16.0
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.cols, 100);
    assert_eq!(config.rows, 24); // default
    assert_eq!(config.font_size, 16.0);
    assert_eq!(config.font_family, "JetBrains Mono"); // default
}

#[test]
fn test_config_builder_chain() {
    let config = Config::default().with_title("Custom Terminal");
    assert_eq!(config.window_title, "Custom Terminal");
    // Defaults should still be intact
    assert_eq!(config.cols, 80);
    assert_eq!(config.rows, 24);
}

#[test]
fn test_config_power_saving_defaults() {
    let config = Config::default();
    // Default: pause shaders on blur is enabled for power savings
    assert!(config.pause_shaders_on_blur);
    // Default: pause refresh on blur is enabled for power savings (changed from false)
    assert!(config.pause_refresh_on_blur);
    // Default unfocused FPS is 30
    assert_eq!(config.unfocused_fps, 30);

    // Initial text defaults
    assert!(config.initial_text.is_empty());
    assert_eq!(config.initial_text_delay_ms, 100);
    assert!(config.initial_text_send_newline);
}

#[test]
fn test_config_power_saving_yaml_deserialization() {
    let yaml = r#"
pause_shaders_on_blur: false
pause_refresh_on_blur: true
unfocused_fps: 5
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!(!config.pause_shaders_on_blur);
    assert!(config.pause_refresh_on_blur);
    assert_eq!(config.unfocused_fps, 5);
}

#[test]
fn test_config_initial_text_yaml_deserialization() {
    let yaml = r#"
initial_text: "ssh server"
initial_text_delay_ms: 250
initial_text_send_newline: false
"#;

    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.initial_text, "ssh server");
    assert_eq!(config.initial_text_delay_ms, 250);
    assert!(!config.initial_text_send_newline);
}

#[test]
fn test_config_initial_text_yaml_serialization() {
    let mut config = Config::default();
    config.initial_text = "echo ready".to_string();
    config.initial_text_delay_ms = 10;
    config.initial_text_send_newline = false;

    let yaml = serde_yaml_ng::to_string(&config).unwrap();
    assert!(yaml.contains("initial_text: echo ready"));
    assert!(yaml.contains("initial_text_delay_ms: 10"));
    assert!(yaml.contains("initial_text_send_newline: false"));
}

#[test]
fn test_config_power_saving_yaml_serialization() {
    let mut config = Config::default();
    config.pause_shaders_on_blur = false;
    config.pause_refresh_on_blur = true;
    config.unfocused_fps = 15;

    let yaml = serde_yaml_ng::to_string(&config).unwrap();
    assert!(yaml.contains("pause_shaders_on_blur: false"));
    assert!(yaml.contains("pause_refresh_on_blur: true"));
    assert!(yaml.contains("unfocused_fps: 15"));
}

#[test]
fn test_config_tab_bar_color_defaults() {
    let config = Config::default();
    // Tab bar background colors
    assert_eq!(config.tab_bar_background, [40, 40, 40]);
    assert_eq!(config.tab_active_background, [60, 60, 60]);
    assert_eq!(config.tab_inactive_background, [40, 40, 40]);
    assert_eq!(config.tab_hover_background, [50, 50, 50]);
    // Tab text colors
    assert_eq!(config.tab_active_text, [255, 255, 255]);
    assert_eq!(config.tab_inactive_text, [180, 180, 180]);
    // Tab indicator colors
    assert_eq!(config.tab_active_indicator, [100, 150, 255]);
    assert_eq!(config.tab_activity_indicator, [100, 180, 255]);
    assert_eq!(config.tab_bell_indicator, [255, 200, 100]);
    // Close button colors
    assert_eq!(config.tab_close_button, [150, 150, 150]);
    assert_eq!(config.tab_close_button_hover, [255, 100, 100]);
}

#[test]
fn test_config_tab_bar_color_yaml_deserialization() {
    let yaml = r#"
tab_bar_background: [30, 30, 30]
tab_active_background: [80, 80, 80]
tab_inactive_background: [35, 35, 35]
tab_hover_background: [55, 55, 55]
tab_active_text: [240, 240, 240]
tab_inactive_text: [160, 160, 160]
tab_active_indicator: [120, 170, 255]
tab_activity_indicator: [80, 200, 255]
tab_bell_indicator: [255, 180, 80]
tab_close_button: [130, 130, 130]
tab_close_button_hover: [255, 80, 80]
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.tab_bar_background, [30, 30, 30]);
    assert_eq!(config.tab_active_background, [80, 80, 80]);
    assert_eq!(config.tab_inactive_background, [35, 35, 35]);
    assert_eq!(config.tab_hover_background, [55, 55, 55]);
    assert_eq!(config.tab_active_text, [240, 240, 240]);
    assert_eq!(config.tab_inactive_text, [160, 160, 160]);
    assert_eq!(config.tab_active_indicator, [120, 170, 255]);
    assert_eq!(config.tab_activity_indicator, [80, 200, 255]);
    assert_eq!(config.tab_bell_indicator, [255, 180, 80]);
    assert_eq!(config.tab_close_button, [130, 130, 130]);
    assert_eq!(config.tab_close_button_hover, [255, 80, 80]);
}

#[test]
fn test_config_tab_bar_color_yaml_serialization() {
    let mut config = Config::default();
    config.tab_bar_background = [50, 50, 50];
    config.tab_active_indicator = [200, 100, 50];

    let yaml = serde_yaml_ng::to_string(&config).unwrap();
    assert!(yaml.contains("tab_bar_background:"));
    assert!(yaml.contains("- 50"));
    assert!(yaml.contains("tab_active_indicator:"));
    assert!(yaml.contains("- 200"));
    assert!(yaml.contains("- 100"));
}

#[test]
fn test_config_tab_bar_color_partial_yaml() {
    // Test that default values are used for missing tab bar color fields
    let yaml = r#"
tab_bar_background: [25, 25, 25]
tab_active_text: [200, 200, 200]
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.tab_bar_background, [25, 25, 25]);
    assert_eq!(config.tab_active_text, [200, 200, 200]);
    // Other fields should have defaults
    assert_eq!(config.tab_active_background, [60, 60, 60]);
    assert_eq!(config.tab_inactive_background, [40, 40, 40]);
    assert_eq!(config.tab_close_button, [150, 150, 150]);
}

#[test]
fn test_config_inactive_tab_dimming_defaults() {
    let config = Config::default();
    // Default: dimming is enabled
    assert!(config.dim_inactive_tabs);
    // Default: 60% opacity for inactive tabs
    assert!((config.inactive_tab_opacity - 0.6).abs() < f32::EPSILON);
}

#[test]
fn test_config_inactive_tab_dimming_yaml_deserialization() {
    let yaml = r#"
dim_inactive_tabs: false
inactive_tab_opacity: 0.8
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!(!config.dim_inactive_tabs);
    assert!((config.inactive_tab_opacity - 0.8).abs() < f32::EPSILON);
}

#[test]
fn test_config_inactive_tab_dimming_yaml_serialization() {
    let mut config = Config::default();
    config.dim_inactive_tabs = false;
    config.inactive_tab_opacity = 0.5;

    let yaml = serde_yaml_ng::to_string(&config).unwrap();
    assert!(yaml.contains("dim_inactive_tabs: false"));
    assert!(yaml.contains("inactive_tab_opacity: 0.5"));
}

#[test]
fn test_config_inactive_tab_dimming_partial_yaml() {
    // Test that default values are used for missing fields
    let yaml = r#"
dim_inactive_tabs: true
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!(config.dim_inactive_tabs);
    // Default opacity should be used
    assert!((config.inactive_tab_opacity - 0.6).abs() < f32::EPSILON);
}

#[test]
fn test_config_inactive_tab_opacity_bounds() {
    // Test various opacity values that might be configured
    let yaml = r#"
inactive_tab_opacity: 0.0
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!((config.inactive_tab_opacity).abs() < f32::EPSILON);

    let yaml = r#"
inactive_tab_opacity: 1.0
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!((config.inactive_tab_opacity - 1.0).abs() < f32::EPSILON);

    let yaml = r#"
inactive_tab_opacity: 0.3
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!((config.inactive_tab_opacity - 0.3).abs() < f32::EPSILON);
}

#[test]
fn test_config_cursor_enhancement_defaults() {
    let config = Config::default();
    // Unfocused cursor style defaults to Hollow
    assert_eq!(config.unfocused_cursor_style, UnfocusedCursorStyle::Hollow);
    // Cursor guide disabled by default
    assert!(!config.cursor_guide_enabled);
    // Default guide color: white with low alpha
    assert_eq!(config.cursor_guide_color, [255, 255, 255, 20]);
    // Cursor shadow disabled by default
    assert!(!config.cursor_shadow_enabled);
    // Default shadow color: black with 50% alpha
    assert_eq!(config.cursor_shadow_color, [0, 0, 0, 128]);
    // Default shadow offset
    assert!((config.cursor_shadow_offset[0] - 2.0).abs() < f32::EPSILON);
    assert!((config.cursor_shadow_offset[1] - 2.0).abs() < f32::EPSILON);
    // Default shadow blur
    assert!((config.cursor_shadow_blur - 3.0).abs() < f32::EPSILON);
    // Cursor boost (glow) disabled by default (0.0)
    assert!((config.cursor_boost).abs() < f32::EPSILON);
    // Default boost color: white
    assert_eq!(config.cursor_boost_color, [255, 255, 255]);
}

#[test]
fn test_config_cursor_enhancement_yaml_deserialization() {
    let yaml = r#"
unfocused_cursor_style: hidden
cursor_guide_enabled: true
cursor_guide_color: [200, 200, 255, 40]
cursor_shadow_enabled: true
cursor_shadow_color: [0, 0, 0, 200]
cursor_shadow_offset: [3.0, 3.0]
cursor_shadow_blur: 5.0
cursor_boost: 0.5
cursor_boost_color: [255, 200, 100]
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.unfocused_cursor_style, UnfocusedCursorStyle::Hidden);
    assert!(config.cursor_guide_enabled);
    assert_eq!(config.cursor_guide_color, [200, 200, 255, 40]);
    assert!(config.cursor_shadow_enabled);
    assert_eq!(config.cursor_shadow_color, [0, 0, 0, 200]);
    assert!((config.cursor_shadow_offset[0] - 3.0).abs() < f32::EPSILON);
    assert!((config.cursor_shadow_offset[1] - 3.0).abs() < f32::EPSILON);
    assert!((config.cursor_shadow_blur - 5.0).abs() < f32::EPSILON);
    assert!((config.cursor_boost - 0.5).abs() < f32::EPSILON);
    assert_eq!(config.cursor_boost_color, [255, 200, 100]);
}

#[test]
fn test_config_unfocused_cursor_style_variants() {
    // Test hollow variant
    let yaml = r#"unfocused_cursor_style: hollow"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.unfocused_cursor_style, UnfocusedCursorStyle::Hollow);

    // Test same variant
    let yaml = r#"unfocused_cursor_style: same"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.unfocused_cursor_style, UnfocusedCursorStyle::Same);

    // Test hidden variant
    let yaml = r#"unfocused_cursor_style: hidden"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.unfocused_cursor_style, UnfocusedCursorStyle::Hidden);
}

#[test]
fn test_config_cursor_enhancement_yaml_serialization() {
    let mut config = Config::default();
    config.unfocused_cursor_style = UnfocusedCursorStyle::Same;
    config.cursor_guide_enabled = true;
    config.cursor_guide_color = [100, 150, 200, 50];
    config.cursor_shadow_enabled = true;
    config.cursor_boost = 0.7;

    let yaml = serde_yaml_ng::to_string(&config).unwrap();
    assert!(yaml.contains("unfocused_cursor_style: same"));
    assert!(yaml.contains("cursor_guide_enabled: true"));
    assert!(yaml.contains("cursor_shadow_enabled: true"));
    assert!(yaml.contains("cursor_boost: 0.7"));
}

#[test]
fn test_config_cursor_enhancement_partial_yaml() {
    // Test that default values are used for missing cursor enhancement fields
    let yaml = r#"
cursor_guide_enabled: true
cursor_boost: 0.3
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!(config.cursor_guide_enabled);
    assert!((config.cursor_boost - 0.3).abs() < f32::EPSILON);
    // Other fields should have defaults
    assert_eq!(config.unfocused_cursor_style, UnfocusedCursorStyle::Hollow);
    assert!(!config.cursor_shadow_enabled);
    assert_eq!(config.cursor_guide_color, [255, 255, 255, 20]);
}

// ============================================================================
// Answerback String Tests
// ============================================================================

#[test]
fn test_config_answerback_string_default() {
    let config = Config::default();
    // Answerback should be empty by default for security
    assert!(config.answerback_string.is_empty());
}

#[test]
fn test_config_answerback_string_yaml_deserialization() {
    let yaml = r#"
answerback_string: "par-term"
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert_eq!(config.answerback_string, "par-term");
}

#[test]
fn test_config_answerback_string_yaml_serialization() {
    let mut config = Config::default();
    config.answerback_string = "vt100".to_string();

    let yaml = serde_yaml_ng::to_string(&config).unwrap();
    assert!(yaml.contains("answerback_string: vt100"));
}

#[test]
fn test_config_answerback_string_empty_by_default_yaml() {
    // Empty string should deserialize correctly
    let yaml = r#"
answerback_string: ""
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!(config.answerback_string.is_empty());
}

#[test]
fn test_config_answerback_string_partial_yaml() {
    // Test that default value is used when field is missing
    let yaml = r#"
cols: 120
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    // Answerback should use default (empty)
    assert!(config.answerback_string.is_empty());
    assert_eq!(config.cols, 120);
}

// ============================================================================
// Advanced Mouse Features Tests
// ============================================================================

#[test]
fn test_config_advanced_mouse_defaults() {
    let config = Config::default();
    // Option+Click moves cursor should be enabled by default
    assert!(config.option_click_moves_cursor);
    // Focus follows mouse should be disabled by default (opt-in)
    assert!(!config.focus_follows_mouse);
    // Horizontal scroll reporting should be enabled by default
    assert!(config.report_horizontal_scroll);
}

#[test]
fn test_config_advanced_mouse_yaml_deserialization() {
    let yaml = r#"
option_click_moves_cursor: false
focus_follows_mouse: true
report_horizontal_scroll: false
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!(!config.option_click_moves_cursor);
    assert!(config.focus_follows_mouse);
    assert!(!config.report_horizontal_scroll);
}

#[test]
fn test_config_advanced_mouse_yaml_serialization() {
    let mut config = Config::default();
    config.option_click_moves_cursor = false;
    config.focus_follows_mouse = true;
    config.report_horizontal_scroll = false;

    let yaml = serde_yaml_ng::to_string(&config).unwrap();
    assert!(yaml.contains("option_click_moves_cursor: false"));
    assert!(yaml.contains("focus_follows_mouse: true"));
    assert!(yaml.contains("report_horizontal_scroll: false"));
}

#[test]
fn test_config_advanced_mouse_partial_yaml() {
    // Test that default values are used for missing fields
    let yaml = r#"
focus_follows_mouse: true
"#;
    let config: Config = serde_yaml_ng::from_str(yaml).unwrap();
    assert!(config.focus_follows_mouse);
    // Other fields should have defaults
    assert!(config.option_click_moves_cursor);
    assert!(config.report_horizontal_scroll);
}