wrkflw-ui 0.8.0

Terminal user interface for wrkflw workflow execution engine
Documentation
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
687
688
689
690
691
692
693
694
695
696
697
698
// App module for UI state and main TUI entry point
mod state;

use crate::handlers::workflow::start_next_workflow_execution;
use crate::models::{ExecutionResultMsg, QueuedExecution, Workflow, WorkflowStatus};
use crate::utils::load_workflows;
use crate::views::{
    render_ui, TAB_COUNT, TAB_DAG, TAB_EXECUTION, TAB_HELP, TAB_LOGS, TAB_SECRETS, TAB_TRIGGER,
    TAB_WORKFLOWS,
};
use chrono::Local;
use crossterm::{
    event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyModifiers},
    execute,
    terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use ratatui::{backend::CrosstermBackend, Terminal};
use std::io::{self, stdout};
use std::path::PathBuf;
use std::sync::mpsc;
use std::time::{Duration, Instant};
use wrkflw_executor::RuntimeType;

pub use state::{Accent, App, TriggerPlatform};

// Main entry point for the TUI interface
#[allow(clippy::ptr_arg)]
pub async fn run_wrkflw_tui(
    path: Option<&PathBuf>,
    runtime_type: RuntimeType,
    verbose: bool,
    preserve_containers_on_failure: bool,
    show_action_messages: bool,
) -> io::Result<()> {
    // Terminal setup
    enable_raw_mode()?;
    let mut stdout = stdout();
    execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
    let backend = CrosstermBackend::new(stdout);
    let mut terminal = Terminal::new(backend)?;

    // Suppress logging to stdout/stderr while TUI owns the terminal
    wrkflw_logging::set_quiet_mode(true);

    // Set up channel for async communication
    let (tx, rx): (
        mpsc::Sender<ExecutionResultMsg>,
        mpsc::Receiver<ExecutionResultMsg>,
    ) = mpsc::channel();

    // Initialize app state
    let mut app = App::new(
        runtime_type.clone(),
        tx.clone(),
        preserve_containers_on_failure,
        show_action_messages,
    );

    if app.validation_mode {
        app.logs.push("Starting in validation mode".to_string());
        wrkflw_logging::info("Starting in validation mode");
    }

    // Load workflows
    let dir_path = match path {
        Some(path) if path.is_dir() => path.clone(),
        Some(path) if path.is_file() => {
            // Single workflow file
            let name = path
                .file_name()
                .unwrap_or_default()
                .to_string_lossy()
                .into_owned();

            let (definition, job_names) = {
                use std::sync::Arc;
                use wrkflw_parser::workflow::parse_workflow;
                match parse_workflow(path) {
                    Ok(def) => {
                        let mut names: Vec<String> = def.jobs.keys().cloned().collect();
                        names.sort();
                        (Some(Arc::new(def)), names)
                    }
                    Err(_) => (None, crate::utils::extract_job_names(path)),
                }
            };

            app.workflows = vec![Workflow {
                name: name.clone(),
                path: path.clone(),
                selected: true,
                status: WorkflowStatus::NotStarted,
                execution_details: None,
                job_names,
                trigger_match: None,
                definition,
            }];

            // Queue the single workflow for execution
            app.execution_queue = vec![QueuedExecution {
                workflow_idx: 0,
                target_job: None,
            }];
            app.start_execution();

            // Return parent dir or current dir if no parent
            path.parent()
                .map(|p| p.to_path_buf())
                .unwrap_or_else(|| PathBuf::from("."))
        }
        _ => PathBuf::from(".github/workflows"),
    };

    // Only load directory if we haven't already loaded a single file
    if app.workflows.is_empty() {
        app.workflows = load_workflows(&dir_path);
    }

    // Run the main event loop
    let tx_clone = tx.clone();

    // Run the event loop
    let result = run_tui_event_loop(&mut terminal, &mut app, &tx_clone, &rx, verbose);

    // Clean up terminal
    wrkflw_logging::set_quiet_mode(false);
    disable_raw_mode()?;
    execute!(
        terminal.backend_mut(),
        LeaveAlternateScreen,
        DisableMouseCapture
    )?;
    terminal.show_cursor()?;

    match result {
        Ok(_) => Ok(()),
        Err(e) => {
            // If the TUI fails to initialize or crashes, fall back to CLI mode
            wrkflw_logging::error(&format!("Failed to start UI: {}", e));

            // Only for 'tui' command should we fall back to CLI mode for files
            // For other commands, return the error
            if let Some(path) = path {
                if path.is_file() {
                    wrkflw_logging::error("Falling back to CLI mode...");
                    crate::handlers::workflow::execute_workflow_cli(
                        path,
                        runtime_type,
                        verbose,
                        show_action_messages,
                    )
                    .await
                } else if path.is_dir() {
                    crate::handlers::workflow::validate_workflow(path, verbose)
                } else {
                    Err(e)
                }
            } else {
                Err(e)
            }
        }
    }
}

// Helper function to run the main event loop
#[allow(clippy::collapsible_match)]
fn run_tui_event_loop(
    terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
    app: &mut App,
    tx_clone: &mpsc::Sender<ExecutionResultMsg>,
    rx: &mpsc::Receiver<ExecutionResultMsg>,
    verbose: bool,
) -> io::Result<()> {
    // Max time to wait for events - keep this short to ensure UI responsiveness
    let event_poll_timeout = Duration::from_millis(50);

    // Set up a dedicated tick timer
    let tick_rate = app.tick_rate;
    let mut last_tick = Instant::now();

    loop {
        // Always redraw the UI on each loop iteration to keep it responsive
        terminal.draw(|f| {
            render_ui(f, app);
        })?;

        // Update the UI on every tick
        if last_tick.elapsed() >= tick_rate {
            app.tick();
            app.update_running_workflow_progress();

            // Check for log processing updates (includes system log change detection)
            app.check_log_processing_updates();

            // Request log processing if needed
            if app.logs_need_update {
                app.request_log_processing_update();
            }

            // Check for completed diff filter results
            app.check_diff_filter_results();

            last_tick = Instant::now();
        }

        // Non-blocking check for execution results
        if let Ok((workflow_idx, result)) = rx.try_recv() {
            app.process_execution_result(workflow_idx, result);
            app.current_execution = None;

            // Get next workflow to execute using our helper function
            start_next_workflow_execution(app, tx_clone, verbose);
        }

        // Surface any completed Trigger-tab dispatches on the status bar
        // so the user sees the outcome where they fired it, rather than
        // having to switch tabs to Logs.
        app.drain_trigger_outcomes();

        // Start execution if we have a queued workflow and nothing is currently running
        if app.running && app.current_execution.is_none() && !app.execution_queue.is_empty() {
            start_next_workflow_execution(app, tx_clone, verbose);
        }

        // Handle key events with a short timeout
        if event::poll(event_poll_timeout)? {
            if let Event::Key(key) = event::read()? {
                // Handle search input first if we're in search mode and logs tab
                if app.selected_tab == TAB_LOGS && app.log_search_active {
                    app.handle_log_search_input(key.code);
                    continue;
                }

                // When the Tweaks overlay is open it is modal: only
                // its own shortcuts are honoured, everything else is
                // swallowed so keys like `d` or a tab number can't
                // silently fire the global handler while the user is
                // in edit-mode. `q` is the one exception — quit is
                // universally modal-safe in this TUI and swallowing
                // it silently was a discoverability trap.
                if app.tweaks_open {
                    match key.code {
                        KeyCode::Char('q') => {
                            break Ok(());
                        }
                        KeyCode::Esc | KeyCode::Char(',') => {
                            app.tweaks_open = false;
                        }
                        KeyCode::Char('a') | KeyCode::Char('A') => {
                            app.tweaks_accent = app.tweaks_accent.next();
                        }
                        _ => {}
                    }
                    continue;
                }

                // Trigger tab: if a text field (branch or an input
                // row) is focused, route printable characters and
                // edit keys straight to that field before the global
                // key-map fires. Otherwise editing a value like
                // "notify=slack" would trip the `s` logs shortcut
                // below and jump tabs.
                if app.selected_tab == TAB_TRIGGER
                    && app.trigger_editing()
                    && app.trigger_handle_input_key(key.code)
                {
                    continue;
                }

                // Handle help overlay scrolling
                if app.show_help {
                    match key.code {
                        KeyCode::Up | KeyCode::Char('k') => {
                            app.scroll_help_up();
                            continue;
                        }
                        KeyCode::Down | KeyCode::Char('j') => {
                            app.scroll_help_down();
                            continue;
                        }
                        KeyCode::Esc | KeyCode::Char('?') => {
                            app.show_help = false;
                            continue;
                        }
                        _ => {}
                    }
                }

                match key.code {
                    KeyCode::Char('q') => {
                        // Exit and clean up
                        break Ok(());
                    }
                    KeyCode::Esc => {
                        if app.job_selection_mode {
                            app.exit_job_selection_mode();
                        } else if app.detailed_view {
                            app.detailed_view = false;
                        } else if app.show_help {
                            app.show_help = false;
                        } else {
                            // Exit and clean up
                            break Ok(());
                        }
                    }
                    KeyCode::Tab => {
                        // Inside the Step Inspector, Tab cycles inspector
                        // sub-tabs (Output / Env / Files / Matrix / Timeline);
                        // elsewhere it cycles top-level tabs.
                        if app.selected_tab == TAB_EXECUTION && app.detailed_view {
                            app.step_inspector_tab = (app.step_inspector_tab + 1) % 5;
                        } else if app.selected_tab == TAB_TRIGGER {
                            // In the Trigger tab Tab cycles inputs/fields.
                            app.trigger_tab_next_field();
                        } else {
                            app.switch_tab((app.selected_tab + 1) % TAB_COUNT);
                        }
                    }
                    KeyCode::BackTab => {
                        if app.selected_tab == TAB_EXECUTION && app.detailed_view {
                            app.step_inspector_tab = (app.step_inspector_tab + 4) % 5;
                        } else if app.selected_tab == TAB_TRIGGER {
                            app.trigger_tab_prev_field();
                        } else {
                            app.switch_tab((app.selected_tab + TAB_COUNT - 1) % TAB_COUNT);
                        }
                    }
                    KeyCode::Char('1') | KeyCode::Char('w') => app.switch_tab(TAB_WORKFLOWS),
                    KeyCode::Char('2') | KeyCode::Char('x') => app.switch_tab(TAB_EXECUTION),
                    KeyCode::Char('3') => app.switch_tab(TAB_DAG),
                    KeyCode::Char('4') | KeyCode::Char('l') => app.switch_tab(TAB_LOGS),
                    KeyCode::Char('5') => app.switch_tab(TAB_TRIGGER),
                    KeyCode::Char('6') => app.switch_tab(TAB_SECRETS),
                    KeyCode::Char('7') | KeyCode::Char('h') => app.switch_tab(TAB_HELP),
                    KeyCode::Char(',') => {
                        // `,` toggles the Tweaks overlay anywhere (global).
                        // Chosen because it never conflicts with our single-
                        // letter tab shortcuts or with the log-search input
                        // mode (which only consumes printable chars when
                        // `log_search_active` is true, which we already
                        // handled above with a `continue`).
                        app.tweaks_open = !app.tweaks_open;
                    }
                    KeyCode::Up | KeyCode::Char('k') => match app.selected_tab {
                        TAB_WORKFLOWS => {
                            if app.job_selection_mode {
                                app.previous_available_job();
                            } else {
                                app.previous_workflow();
                            }
                        }
                        TAB_EXECUTION => {
                            if app.detailed_view {
                                app.previous_step();
                            } else {
                                app.previous_job();
                            }
                        }
                        TAB_LOGS => {
                            if !app.log_search_matches.is_empty() {
                                app.previous_search_match();
                            } else {
                                app.scroll_logs_up();
                            }
                        }
                        TAB_TRIGGER => app.trigger_tab_prev_workflow(),
                        TAB_SECRETS => app.secrets_tab_prev(),
                        TAB_HELP => app.scroll_help_up(),
                        _ => {}
                    },
                    KeyCode::Down | KeyCode::Char('j') => match app.selected_tab {
                        TAB_WORKFLOWS => {
                            if app.job_selection_mode {
                                app.next_available_job();
                            } else {
                                app.next_workflow();
                            }
                        }
                        TAB_EXECUTION => {
                            if app.detailed_view {
                                app.next_step();
                            } else {
                                app.next_job();
                            }
                        }
                        TAB_LOGS => {
                            if !app.log_search_matches.is_empty() {
                                app.next_search_match();
                            } else {
                                app.scroll_logs_down();
                            }
                        }
                        TAB_TRIGGER => app.trigger_tab_next_workflow(),
                        TAB_SECRETS => app.secrets_tab_next(),
                        TAB_HELP => app.scroll_help_down(),
                        _ => {}
                    },
                    KeyCode::Char(' ') => {
                        if app.selected_tab == TAB_WORKFLOWS
                            && !app.running
                            && !app.job_selection_mode
                        {
                            app.toggle_selected();
                        }
                    }
                    KeyCode::Enter => {
                        match app.selected_tab {
                            TAB_WORKFLOWS => {
                                if !app.running {
                                    if app.job_selection_mode {
                                        // In job selection mode, run the selected job
                                        if app.selected_job_index < app.available_jobs.len() {
                                            let job_name =
                                                app.available_jobs[app.selected_job_index].clone();
                                            app.run_from_job_selection(Some(job_name));
                                        }
                                    } else {
                                        // Run the selected workflow directly
                                        if let Some(idx) = app.workflow_list_state.selected() {
                                            if idx < app.workflows.len() {
                                                app.workflows[idx].selected = true;
                                                app.queue_selected_for_execution();
                                                app.start_execution();
                                            }
                                        }
                                    }
                                }
                            }
                            TAB_EXECUTION => {
                                // In execution tab, Enter shows job details
                                app.toggle_detailed_view();
                            }
                            TAB_TRIGGER => {
                                // Trigger tab: Enter on a non-editing row
                                // begins editing it (value first, then Tab
                                // to swap); when already editing, Enter
                                // commits the edit back to the row.
                                app.trigger_tab_enter();
                            }
                            _ => {}
                        }
                    }
                    KeyCode::Char('r') => {
                        // Some terminals deliver Shift+r as lowercase
                        // `r` plus a SHIFT modifier instead of
                        // uppercase `R` (see the `R` arm below).
                        // Route both encodings to the reset path so
                        // users don't have to reason about what their
                        // terminal emits.
                        if key.modifiers.contains(KeyModifiers::SHIFT) {
                            if !app.running {
                                app.reset_workflow_status();
                                terminal.draw(|f| {
                                    render_ui(f, app);
                                })?;
                            }
                        } else if !app.running
                            && !app.job_selection_mode
                            && app.selected_tab == TAB_WORKFLOWS
                        {
                            // Plain `r` queues the selected workflow
                            // for execution — a Workflows-tab action.
                            // Gate on the active tab so `r` typed on
                            // the DAG/Trigger/Secrets tabs doesn't
                            // silently mutate queue state behind the
                            // user's back.
                            app.queue_selected_for_execution();
                            app.start_execution();
                        }
                    }
                    KeyCode::Char('a') => {
                        if !app.running {
                            if app.job_selection_mode {
                                // In job selection mode, run all jobs
                                app.run_from_job_selection(None);
                            } else if app.selected_tab == TAB_WORKFLOWS {
                                // Select-all is a Workflows-tab action.
                                // Without this tab gate, pressing `a`
                                // on DAG/Trigger/Secrets (outside edit
                                // mode) would silently flip every
                                // workflow to `selected` behind the
                                // user's back.
                                for workflow in &mut app.workflows {
                                    workflow.selected = true;
                                }
                            }
                        }
                    }
                    KeyCode::Char('J') => {
                        // Enter job selection mode for selected workflow
                        if !app.running
                            && app.selected_tab == TAB_WORKFLOWS
                            && !app.job_selection_mode
                        {
                            app.enter_job_selection_mode();
                        }
                    }
                    KeyCode::Char('e') => {
                        if !app.running {
                            app.toggle_emulation_mode();
                        }
                    }
                    KeyCode::Char('v') => {
                        if !app.running {
                            app.toggle_validation_mode();
                        }
                    }
                    KeyCode::Char('d') => {
                        if !app.running && app.selected_tab == TAB_WORKFLOWS {
                            app.toggle_diff_filter();
                        }
                    }
                    KeyCode::Char('D') => {
                        // Shift+D cycles through the diff-filter event
                        // name (push → pull_request → workflow_dispatch →
                        // schedule → release → push). Previously the
                        // event name was a hardcoded "push" and the TUI
                        // silently reported "0 triggered" for any
                        // workflow gated on a non-push event — exactly
                        // the "stop lying about which workflows would
                        // run" failure mode the commit history fought.
                        if !app.running && app.selected_tab == TAB_WORKFLOWS {
                            app.cycle_diff_filter_event();
                        }
                    }
                    KeyCode::Char('n') => {
                        if app.selected_tab == TAB_LOGS && !app.log_search_query.is_empty() {
                            app.next_search_match();
                        } else if app.selected_tab == TAB_WORKFLOWS && !app.running {
                            // Deselect all workflows
                            for workflow in &mut app.workflows {
                                workflow.selected = false;
                            }
                        }
                    }
                    KeyCode::Char('R') => {
                        if !app.running {
                            app.reset_workflow_status();
                            terminal.draw(|f| {
                                render_ui(f, app);
                            })?;
                        } else {
                            app.add_timestamped_log(
                                "Cannot reset workflow while another operation is running",
                            );
                        }
                    }
                    KeyCode::Char('?') => {
                        // Toggle help overlay
                        app.show_help = !app.show_help;
                    }
                    KeyCode::Char('t') => {
                        // Only trigger workflow if not already running and we're in the workflows tab
                        if !app.running && app.selected_tab == TAB_WORKFLOWS {
                            if let Some(selected_idx) = app.workflow_list_state.selected() {
                                if selected_idx < app.workflows.len() {
                                    let workflow = &app.workflows[selected_idx];
                                    if workflow.status == WorkflowStatus::NotStarted {
                                        app.trigger_selected_workflow();
                                    } else if workflow.status == WorkflowStatus::Running {
                                        app.logs.push(format!(
                                            "Workflow '{}' is already running",
                                            workflow.name
                                        ));
                                        wrkflw_logging::warning(&format!(
                                            "Workflow '{}' is already running",
                                            workflow.name
                                        ));
                                    } else {
                                        // First, get all the data we need from the workflow
                                        let workflow_name = workflow.name.clone();
                                        let status_text = match workflow.status {
                                            WorkflowStatus::Success => "Success",
                                            WorkflowStatus::Failed => "Failed",
                                            WorkflowStatus::Skipped => "Skipped",
                                            _ => "current",
                                        };
                                        let needs_reset_hint = workflow.status
                                            == WorkflowStatus::Success
                                            || workflow.status == WorkflowStatus::Failed
                                            || workflow.status == WorkflowStatus::Skipped;

                                        // Now set the status message (mutable borrow)
                                        app.set_error_message(format!(
                                            "Cannot trigger workflow '{}' in {} state. Press Shift+R to reset.",
                                            workflow_name,
                                            status_text
                                        ));

                                        // Add log entries
                                        app.logs.push(format!(
                                            "Cannot trigger workflow '{}' in {} state",
                                            workflow_name, status_text
                                        ));

                                        // Add hint about using reset
                                        if needs_reset_hint {
                                            let timestamp =
                                                Local::now().format("%H:%M:%S").to_string();
                                            app.logs.push(format!(
                                                "[{}] Hint: Press 'Shift+R' to reset the workflow status and allow triggering",
                                                timestamp
                                            ));
                                        }

                                        wrkflw_logging::warning(&format!(
                                            "Cannot trigger workflow in {} state",
                                            status_text
                                        ));
                                    }
                                }
                            } else {
                                app.logs.push("No workflow selected to trigger".to_string());
                                wrkflw_logging::warning("No workflow selected to trigger");
                            }
                        } else if app.running {
                            app.logs.push(
                                "Cannot trigger workflow while another operation is in progress"
                                    .to_string(),
                            );
                            wrkflw_logging::warning(
                                "Cannot trigger workflow while another operation is in progress",
                            );
                        } else if app.selected_tab != TAB_WORKFLOWS {
                            app.logs
                                .push("Switch to Workflows tab to trigger a workflow".to_string());
                            wrkflw_logging::warning(
                                "Switch to Workflows tab to trigger a workflow",
                            );
                            // For better UX, we could also automatically switch to the Workflows tab here
                            app.switch_tab(TAB_WORKFLOWS);
                        }
                    }
                    KeyCode::Char('s') => {
                        if app.selected_tab == TAB_LOGS {
                            app.toggle_log_search();
                        }
                    }
                    KeyCode::Char('f') => {
                        if app.selected_tab == TAB_LOGS {
                            app.toggle_log_filter();
                        }
                    }
                    KeyCode::Char('c') => {
                        if app.selected_tab == TAB_LOGS {
                            app.clear_log_search_and_filter();
                        } else if app.selected_tab == TAB_TRIGGER {
                            // Trigger tab: copy curl preview into the
                            // status bar so the user can scrape it from
                            // their scrollback without shelling out of
                            // the TUI. No clipboard integration yet —
                            // terminals vary too widely; a log line is
                            // honest.
                            app.trigger_tab_copy_curl();
                        }
                    }
                    KeyCode::Char('g') => {
                        if app.selected_tab == TAB_DAG {
                            // Toggle DAG tab between graph and list view —
                            // matches the design's `g` shortcut on
                            // screen 4.
                            app.dag_list_view = !app.dag_list_view;
                        }
                    }
                    KeyCode::Char('p') => {
                        if app.selected_tab == TAB_TRIGGER {
                            // Trigger tab: flip github ↔ gitlab. Also
                            // rebinds the branch default because each
                            // platform has its own `get_repo_info`.
                            app.trigger_tab_toggle_platform();
                        }
                    }
                    KeyCode::Char('+') | KeyCode::Char('=') => {
                        if app.selected_tab == TAB_TRIGGER {
                            app.trigger_tab_add_input();
                        }
                    }
                    KeyCode::Char('b') => {
                        // Trigger tab: focus the Branch / ref row so
                        // the user can type a non-default branch. The
                        // previous revision rendered the field as
                        // editable but provided no keystroke that
                        // reached it.
                        if app.selected_tab == TAB_TRIGGER {
                            app.trigger_tab_edit_branch();
                        }
                    }
                    KeyCode::Char(c) => {
                        if app.selected_tab == TAB_LOGS && app.log_search_active {
                            app.handle_log_search_input(KeyCode::Char(c));
                        }
                    }
                    _ => {}
                }
            }
        }
    }
}