term39 1.5.1

A modern, retro-styled terminal multiplexer with a classic MS-DOS aesthetic
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
//! Keyboard handlers for vim-like Window Mode
//!
//! This module handles keyboard input when the application is in Window Mode,
//! allowing full keyboard-only control of windows.

use super::manager::{FocusState, WindowManager};
use crate::app::app_state::AppState;
use crate::app::config_manager::AppConfig;
use crate::input::keybinding_profile::{KeybindingProfile, matches_any};
use crate::input::keyboard_mode::{KeyboardMode, ResizeDirection, SnapPosition, WindowSubMode};
use crate::rendering::RenderBackend;
use crate::ui::info_window::InfoWindow;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use std::time::{Duration, Instant};

/// Double-backtick threshold in milliseconds
const DOUBLE_BACKTICK_THRESHOLD_MS: u64 = 300;

/// Direction constants for spatial navigation
pub const DIR_LEFT: u8 = 0;
pub const DIR_DOWN: u8 = 1;
pub const DIR_UP: u8 = 2;
pub const DIR_RIGHT: u8 = 3;

/// Helper to check if focused window is locked (auto-tiled first 4)
fn is_focused_window_locked(window_manager: &WindowManager, auto_tiling_enabled: bool) -> bool {
    if let Some(focused_id) = window_manager.get_focused_window_id() {
        window_manager.is_window_tiled_locked(focused_id, auto_tiling_enabled)
    } else {
        false
    }
}

/// Handle keyboard input when in Window Mode
/// Returns true if event was consumed
#[allow(clippy::too_many_arguments)]
pub fn handle_window_mode_keyboard(
    app_state: &mut AppState,
    app_config: &mut AppConfig,
    key_event: KeyEvent,
    window_manager: &mut WindowManager,
    backend: &dyn RenderBackend,
    profile: &KeybindingProfile,
) -> bool {
    // Only handle if in Window Mode
    let sub_mode = match app_state.keyboard_mode {
        KeyboardMode::Normal => return false,
        KeyboardMode::WindowMode(sub) => sub,
    };

    let (cols, rows) = backend.dimensions();
    let top_y: u16 = 1; // Top bar is row 0

    match sub_mode {
        WindowSubMode::Navigation => handle_navigation_mode(
            app_state,
            app_config,
            key_event,
            window_manager,
            backend,
            cols,
            rows,
            top_y,
            profile,
        ),
        WindowSubMode::Move => {
            handle_move_mode(app_state, key_event, window_manager, cols, rows, top_y)
        }
        WindowSubMode::Resize(direction) => {
            handle_resize_mode(app_state, key_event, window_manager, direction)
        }
    }
}

/// Handle keyboard in Navigation sub-mode (default Window Mode)
#[allow(clippy::too_many_arguments)]
fn handle_navigation_mode(
    app_state: &mut AppState,
    app_config: &mut AppConfig,
    key_event: KeyEvent,
    window_manager: &mut WindowManager,
    backend: &dyn RenderBackend,
    cols: u16,
    rows: u16,
    top_y: u16,
    profile: &KeybindingProfile,
) -> bool {
    let code = key_event.code;
    let modifiers = key_event.modifiers;
    let has_shift = modifiers.contains(KeyModifiers::SHIFT);

    match code {
        // Exit Window Mode (F8 or Esc)
        KeyCode::F(8) | KeyCode::Esc => {
            app_state.keyboard_mode.exit_to_normal();
            app_state.move_state.reset();
            app_state.resize_state.reset();
            true
        }

        // Backtick with double-press detection
        // Single backtick: exit Window Mode
        // Double backtick (within 300ms): send literal '`' to terminal and exit
        KeyCode::Char('`') => {
            let now = Instant::now();
            let is_double_press = app_state
                .last_backtick_time
                .map(|t| {
                    now.duration_since(t) < Duration::from_millis(DOUBLE_BACKTICK_THRESHOLD_MS)
                })
                .unwrap_or(false);

            if is_double_press {
                // Double backtick: send literal '`' to focused terminal
                app_state.last_backtick_time = None;
                app_state.keyboard_mode.exit_to_normal();
                app_state.move_state.reset();
                app_state.resize_state.reset();
                let _ = window_manager.send_to_focused("`");
            } else {
                // Single backtick: just exit Window Mode and record time
                app_state.last_backtick_time = Some(now);
                app_state.keyboard_mode.exit_to_normal();
                app_state.move_state.reset();
                app_state.resize_state.reset();
            }
            true
        }

        // Spatial navigation - focus window in direction (profile-based)
        _ if !has_shift && matches_any(&profile.wm_focus_left, code, modifiers) => {
            window_manager.focus_window_in_direction(DIR_LEFT);
            true
        }
        _ if !has_shift && matches_any(&profile.wm_focus_down, code, modifiers) => {
            window_manager.focus_window_in_direction(DIR_DOWN);
            true
        }
        _ if !has_shift && matches_any(&profile.wm_focus_up, code, modifiers) => {
            window_manager.focus_window_in_direction(DIR_UP);
            true
        }
        _ if !has_shift && matches_any(&profile.wm_focus_right, code, modifiers) => {
            window_manager.focus_window_in_direction(DIR_RIGHT);
            true
        }

        // Snap to full halves (profile-based)
        // Don't snap locked windows (auto-tiled first 4)
        _ if matches_any(&profile.wm_snap_left, code, modifiers) => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::FullLeft.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        _ if matches_any(&profile.wm_snap_down, code, modifiers) => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::FullBottom.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        _ if matches_any(&profile.wm_snap_up, code, modifiers) => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::FullTop.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        _ if matches_any(&profile.wm_snap_right, code, modifiers) => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::FullRight.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }

        // Tab cycling
        KeyCode::Tab if !has_shift => {
            window_manager.cycle_to_next_window();
            true
        }
        KeyCode::BackTab | KeyCode::Tab if has_shift => {
            window_manager.cycle_to_previous_window();
            true
        }

        // Enter Move sub-mode (profile-based)
        _ if matches_any(&profile.wm_enter_move, code, modifiers) => {
            app_state.keyboard_mode.enter_sub_mode(WindowSubMode::Move);
            app_state.move_state.reset();
            true
        }

        // Enter Resize sub-mode (profile-based)
        _ if matches_any(&profile.wm_enter_resize, code, modifiers) => {
            app_state
                .keyboard_mode
                .enter_sub_mode(WindowSubMode::Resize(ResizeDirection::Default));
            app_state.resize_state.reset();
            true
        }

        // Close focused window (profile-based)
        _ if matches_any(&profile.wm_close, code, modifiers) => {
            // 'q' on desktop/topbar: let the main handler show exit prompt
            if code == KeyCode::Char('q') {
                let focus = window_manager.get_focus();
                if matches!(focus, FocusState::Desktop | FocusState::Topbar) {
                    return false;
                }
            }
            let closed = window_manager.request_close_focused_window();
            if closed && window_manager.window_count() == 0 {
                app_state.keyboard_mode.exit_to_normal();
            }
            true
        }

        // Toggle maximize (profile-based)
        _ if matches_any(&profile.wm_maximize, code, modifiers) => {
            window_manager.toggle_focused_window_maximize(cols, rows, app_config.tiling_gaps);
            true
        }

        // Minimize
        _ if matches_any(&profile.wm_minimize, code, modifiers) => {
            window_manager.toggle_focused_window_minimize();
            true
        }

        // New terminal window (normal size)
        KeyCode::Char('t') => {
            crate::input::keyboard_handlers::create_terminal_window(
                app_state,
                window_manager,
                backend,
                false,
                app_config.tiling_gaps,
            );
            true
        }

        // New maximized terminal window
        KeyCode::Char('T') => {
            crate::input::keyboard_handlers::create_terminal_window(
                app_state,
                window_manager,
                backend,
                true,
                app_config.tiling_gaps,
            );
            true
        }

        // Toggle auto-tiling (profile-based)
        _ if matches_any(&profile.wm_toggle_auto_tiling, code, modifiers) => {
            // Toggle config and persist
            app_config.toggle_auto_tiling_on_startup();
            app_state.auto_tiling_enabled = app_config.auto_tiling_on_startup;
            let auto_tiling_text = if app_state.auto_tiling_enabled {
                "â–ˆ on] Auto Tiling"
            } else {
                "off â–‘] Auto Tiling"
            };
            let bar_y = rows - 1;
            app_state.auto_tiling_button =
                crate::ui::button::Button::new(1, bar_y, auto_tiling_text.to_string());
            if app_state.auto_tiling_enabled {
                window_manager.auto_position_windows(cols, rows, app_config.tiling_gaps);
            }
            true
        }

        // Numpad-style snap positions (1-9)
        // Don't snap locked windows (auto-tiled first 4)
        KeyCode::Char('1') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::BottomLeft.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        KeyCode::Char('2') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::BottomCenter.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        KeyCode::Char('3') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::BottomRight.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        KeyCode::Char('4') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::MiddleLeft.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        KeyCode::Char('5') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::Center.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        KeyCode::Char('6') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::MiddleRight.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        KeyCode::Char('7') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::TopLeft.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        KeyCode::Char('8') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::TopCenter.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }
        KeyCode::Char('9') => {
            if !is_focused_window_locked(window_manager, app_state.auto_tiling_enabled) {
                let (x, y, w, h) = SnapPosition::TopRight.calculate_rect(cols, rows, top_y);
                window_manager.snap_focused_window(x, y, w, h);
            }
            true
        }

        // Help overlay
        KeyCode::Char('?') => {
            show_winmode_help_window(app_state, cols, rows);
            true
        }

        // Consume all other keys - don't let them pass to terminal while in Window Mode
        _ => true,
    }
}

/// Handle keyboard in Move sub-mode
fn handle_move_mode(
    app_state: &mut AppState,
    key_event: KeyEvent,
    window_manager: &mut WindowManager,
    cols: u16,
    rows: u16,
    top_y: u16,
) -> bool {
    // Check if focused window is locked (auto-tiled first 4)
    // Locked windows cannot be moved, but allow exiting move mode
    if let Some(focused_id) = window_manager.get_focused_window_id() {
        if window_manager.is_window_tiled_locked(focused_id, app_state.auto_tiling_enabled) {
            // Allow exiting move mode but block actual movement
            match key_event.code {
                KeyCode::Enter
                | KeyCode::Esc
                | KeyCode::F(8)
                | KeyCode::Char('m')
                | KeyCode::Char('`') => {
                    app_state.keyboard_mode.return_to_navigation();
                    app_state.move_state.reset();
                }
                _ => {}
            }
            return true;
        }
    }

    let has_shift = key_event.modifiers.contains(KeyModifiers::SHIFT);

    match key_event.code {
        // Exit Move mode (Enter, Esc, F8, m)
        KeyCode::Enter | KeyCode::Esc | KeyCode::F(8) | KeyCode::Char('m') => {
            app_state.keyboard_mode.return_to_navigation();
            app_state.move_state.reset();
            true
        }

        // Backtick with double-press detection in Move mode
        KeyCode::Char('`') => {
            let now = Instant::now();
            let is_double_press = app_state
                .last_backtick_time
                .map(|t| {
                    now.duration_since(t) < Duration::from_millis(DOUBLE_BACKTICK_THRESHOLD_MS)
                })
                .unwrap_or(false);

            if is_double_press {
                // Double backtick: send literal '`' to focused terminal and exit
                app_state.last_backtick_time = None;
                app_state.keyboard_mode.exit_to_normal();
                app_state.move_state.reset();
                app_state.resize_state.reset();
                let _ = window_manager.send_to_focused("`");
            } else {
                // Single backtick: exit to navigation and record time
                app_state.last_backtick_time = Some(now);
                app_state.keyboard_mode.return_to_navigation();
                app_state.move_state.reset();
            }
            true
        }

        // Incremental movement (with adaptive step)
        KeyCode::Char('h') | KeyCode::Left if !has_shift => {
            let step = app_state.move_state.get_step() as i16;
            window_manager.move_focused_window_by(-step, 0, cols, rows, top_y);
            true
        }
        KeyCode::Char('j') | KeyCode::Down if !has_shift => {
            let step = app_state.move_state.get_step() as i16;
            window_manager.move_focused_window_by(0, step, cols, rows, top_y);
            true
        }
        KeyCode::Char('k') | KeyCode::Up if !has_shift => {
            let step = app_state.move_state.get_step() as i16;
            window_manager.move_focused_window_by(0, -step, cols, rows, top_y);
            true
        }
        KeyCode::Char('l') | KeyCode::Right if !has_shift => {
            let step = app_state.move_state.get_step() as i16;
            window_manager.move_focused_window_by(step, 0, cols, rows, top_y);
            true
        }

        // Snap to edges (Shift + h/j/k/l)
        KeyCode::Char('H') | KeyCode::Left if has_shift => {
            // Snap to left edge (x = 0)
            if let Some(win) = window_manager.get_focused_window() {
                let new_x = 0;
                window_manager.snap_focused_window(
                    new_x,
                    win.window.y,
                    win.window.width,
                    win.window.height,
                );
            }
            true
        }
        KeyCode::Char('J') | KeyCode::Down if has_shift => {
            // Snap to bottom edge
            if let Some(win) = window_manager.get_focused_window() {
                let new_y = rows.saturating_sub(win.window.height);
                window_manager.snap_focused_window(
                    win.window.x,
                    new_y,
                    win.window.width,
                    win.window.height,
                );
            }
            true
        }
        KeyCode::Char('K') | KeyCode::Up if has_shift => {
            // Snap to top edge
            if let Some(win) = window_manager.get_focused_window() {
                window_manager.snap_focused_window(
                    win.window.x,
                    top_y,
                    win.window.width,
                    win.window.height,
                );
            }
            true
        }
        KeyCode::Char('L') | KeyCode::Right if has_shift => {
            // Snap to right edge
            if let Some(win) = window_manager.get_focused_window() {
                let new_x = cols.saturating_sub(win.window.width);
                window_manager.snap_focused_window(
                    new_x,
                    win.window.y,
                    win.window.width,
                    win.window.height,
                );
            }
            true
        }

        // Consume all other keys - don't let them pass to terminal while in Move mode
        _ => true,
    }
}

/// Handle keyboard in Resize sub-mode
/// Shift modifier controls which edge is resized (left/top vs right/bottom)
fn handle_resize_mode(
    app_state: &mut AppState,
    key_event: KeyEvent,
    window_manager: &mut WindowManager,
    _resize_direction: ResizeDirection, // Kept for API compatibility
) -> bool {
    // Check if focused window is locked (auto-tiled first 4)
    // Locked windows cannot be resized, but allow exiting resize mode
    if let Some(focused_id) = window_manager.get_focused_window_id() {
        if window_manager.is_window_tiled_locked(focused_id, app_state.auto_tiling_enabled) {
            // Allow exiting resize mode but block actual resizing
            match key_event.code {
                KeyCode::Enter
                | KeyCode::Esc
                | KeyCode::F(8)
                | KeyCode::Char('r')
                | KeyCode::Char('`') => {
                    app_state.keyboard_mode.return_to_navigation();
                    app_state.resize_state.reset();
                }
                _ => {}
            }
            return true;
        }
    }

    let has_shift = key_event.modifiers.contains(KeyModifiers::SHIFT);

    match key_event.code {
        // Exit Resize mode (Enter, Esc, F8, r)
        KeyCode::Enter | KeyCode::Esc | KeyCode::F(8) | KeyCode::Char('r') => {
            app_state.keyboard_mode.return_to_navigation();
            app_state.resize_state.reset();
            true
        }

        // Backtick with double-press detection in Resize mode
        KeyCode::Char('`') => {
            let now = Instant::now();
            let is_double_press = app_state
                .last_backtick_time
                .map(|t| {
                    now.duration_since(t) < Duration::from_millis(DOUBLE_BACKTICK_THRESHOLD_MS)
                })
                .unwrap_or(false);

            if is_double_press {
                // Double backtick: send literal '`' to focused terminal and exit
                app_state.last_backtick_time = None;
                app_state.keyboard_mode.exit_to_normal();
                app_state.move_state.reset();
                app_state.resize_state.reset();
                let _ = window_manager.send_to_focused("`");
            } else {
                // Single backtick: exit to navigation and record time
                app_state.last_backtick_time = Some(now);
                app_state.keyboard_mode.return_to_navigation();
                app_state.resize_state.reset();
            }
            true
        }

        // Incremental resize (with adaptive step)
        // Without Shift: normal resize behavior (right/bottom edge)
        // With Shift: resize from left/top edge

        // h/Left = shrink width from right edge
        KeyCode::Char('h') | KeyCode::Left if !has_shift => {
            let step = app_state.resize_state.get_step() as i16;
            window_manager.resize_focused_window_by(-step, 0);
            true
        }
        // Shift+H = grow width from left edge
        KeyCode::Char('H') | KeyCode::Left if has_shift => {
            let step = app_state.resize_state.get_step() as i16;
            window_manager.resize_focused_window_from_left(step);
            true
        }

        // l/Right = grow width from right edge
        KeyCode::Char('l') | KeyCode::Right if !has_shift => {
            let step = app_state.resize_state.get_step() as i16;
            window_manager.resize_focused_window_by(step, 0);
            true
        }
        // Shift+L = shrink width from left edge
        KeyCode::Char('L') | KeyCode::Right if has_shift => {
            let step = app_state.resize_state.get_step() as i16;
            window_manager.resize_focused_window_from_left(-step);
            true
        }

        // k/Up = shrink height from bottom edge
        KeyCode::Char('k') | KeyCode::Up if !has_shift => {
            let step = app_state.resize_state.get_step() as i16;
            window_manager.resize_focused_window_by(0, -step);
            true
        }
        // Shift+K = grow height from top edge
        KeyCode::Char('K') | KeyCode::Up if has_shift => {
            let step = app_state.resize_state.get_step() as i16;
            window_manager.resize_focused_window_from_top(step);
            true
        }

        // j/Down = grow height from bottom edge
        KeyCode::Char('j') | KeyCode::Down if !has_shift => {
            let step = app_state.resize_state.get_step() as i16;
            window_manager.resize_focused_window_by(0, step);
            true
        }
        // Shift+J = shrink height from top edge
        KeyCode::Char('J') | KeyCode::Down if has_shift => {
            let step = app_state.resize_state.get_step() as i16;
            window_manager.resize_focused_window_from_top(-step);
            true
        }

        // Consume all other keys - don't let them pass to terminal while in Resize mode
        _ => true,
    }
}

/// Show Window Mode help overlay with all keybindings
pub fn show_winmode_help_window(app_state: &mut AppState, cols: u16, rows: u16) {
    let help_message = "\
{C}WINDOW MODE HELP{W}

Press {Y}`{W} or {Y}F8{W} to toggle Window Mode

{C}NAVIGATION (default){W}

{Y}h{W}/{Y}\u{2190}{W}         Focus window to left
{Y}j{W}/{Y}\u{2193}{W}         Focus window below
{Y}k{W}/{Y}\u{2191}{W}         Focus window above
{Y}l{W}/{Y}\u{2192}{W}         Focus window to right
{Y}Tab{W}         Cycle to next window
{Y}Shift+Tab{W}   Cycle to previous window

{C}SNAP (Shift + h/j/k/l){W}

{Y}H{W}           Snap to left half
{Y}J{W}           Snap to bottom half
{Y}K{W}           Snap to top half
{Y}L{W}           Snap to right half

{C}NUMPAD POSITIONS (1-9){W}

{Y}7{W} {Y}8{W} {Y}9{W}       Top-left, Top-center, Top-right
{Y}4{W} {Y}5{W} {Y}6{W}       Middle-left, Center, Middle-right
{Y}1{W} {Y}2{W} {Y}3{W}       Bottom-left, Bottom-center, Bottom-right

{C}WINDOW ACTIONS{W}

{Y}t{W}           New terminal window
{Y}T{W}           New maximized terminal window
{Y}m{W}           Enter Move mode
{Y}r{W}           Enter Resize mode
{Y}z{W}/{Y}+{W}/{Y}Space{W}   Toggle maximize
{Y}-{W}/{Y}_{W}         Toggle minimize
{Y}x{W}/{Y}q{W}         Close focused window
{Y}a{W}           Toggle auto-tiling

{C}MOVE MODE (after 'm'){W}

{Y}h/j/k/l{W}     Move window (adaptive speed)
{Y}Shift+H/J/K/L{W} Snap to edge
{Y}Enter{W}/{Y}Esc{W}/{Y}m{W} Exit Move mode

{C}RESIZE MODE (after 'r'){W}

{Y}h{W}/{Y}l{W}         Shrink/Grow width
{Y}k{W}/{Y}j{W}         Shrink/Grow height
{Y}Shift{W}       Invert direction
{Y}Enter{W}/{Y}Esc{W}/{Y}r{W} Exit Resize mode

{C}EXIT WINDOW MODE{W}

{Y}`{W}/{Y}F8{W}/{Y}Esc{W}    Return to Normal mode";

    app_state.active_winmode_help_window = Some(InfoWindow::new(
        "Window Mode Help".to_string(),
        help_message,
        cols,
        rows,
    ));
}