Skip to main content

codetether_agent/tui/app/input/
bus.rs

1//! Bus-view input handlers for the TUI.
2//!
3//! Provides key handlers for scrolling, filtering, and
4//! clearing the protocol bus log while in
5//! [`ViewMode::Bus`].
6//!
7//! # Examples
8//!
9//! ```ignore
10//! handle_bus_g(&mut app);
11//! handle_bus_c(&mut app);
12//! handle_bus_slash(&mut app);
13//! ```
14
15use crate::tui::app::state::App;
16
17/// Jump to the bottom of the bus log and enable auto-scroll.
18///
19/// Triggered by pressing `g` while in Bus view mode.
20///
21/// # Examples
22///
23/// ```ignore
24/// handle_bus_g(&mut app);
25/// ```
26pub fn handle_bus_g(app: &mut App) {
27    let len = app.state.bus_log.visible_count();
28    if len > 0 {
29        app.state.bus_log.selected_index = len - 1;
30        app.state.bus_log.auto_scroll = true;
31    }
32}
33
34/// Clear the bus log protocol filter.
35///
36/// Triggered by pressing `c` while in Bus view mode.
37///
38/// # Examples
39///
40/// ```ignore
41/// handle_bus_c(&mut app);
42/// ```
43pub fn handle_bus_c(app: &mut App) {
44    app.state.bus_log.clear_filter();
45    app.state.status = "Protocol filter cleared".to_string();
46}
47
48/// Enter bus filter input mode.
49///
50/// Triggered by pressing `/` while in Bus view mode.
51///
52/// # Examples
53///
54/// ```ignore
55/// handle_bus_slash(&mut app);
56/// ```
57pub fn handle_bus_slash(app: &mut App) {
58    app.state.bus_log.enter_filter_mode();
59    app.state.status = "Protocol filter mode".to_string();
60}
61
62/// Confirm the bus filter and exit filter input mode.
63///
64/// Called when Enter is pressed while the bus filter input
65/// is active.
66///
67/// # Examples
68///
69/// ```ignore
70/// handle_enter_bus_filter(&mut app);
71/// ```
72pub(super) fn handle_enter_bus_filter(app: &mut App) {
73    app.state.bus_log.exit_filter_mode();
74    app.state.status = if app.state.bus_log.filter.is_empty() {
75        "Protocol filter cleared".to_string()
76    } else {
77        format!("Protocol filter applied: {}", app.state.bus_log.filter)
78    };
79}