Skip to main content

codetether_agent/tui/app/input/
char_input.rs

1//! Character input routing for the TUI.
2//!
3//! Dispatches printable characters to symbol search, bus
4//! filter, model filter, file picker filter, or the chat
5//! input buffer depending on the active view.
6//!
7//! # Examples
8//!
9//! ```ignore
10//! handle_char(&mut app, modifiers, 'x').await;
11//! ```
12
13use crossterm::event::KeyModifiers;
14
15use crate::tui::app::state::App;
16use crate::tui::app::symbols::{refresh_symbol_search, symbol_search_active};
17use crate::tui::models::{InputMode, ViewMode};
18
19/// Route a printable character to the correct view handler.
20///
21/// Depending on the active view mode, the character is sent
22/// to symbol search, bus filter, model filter, file picker
23/// filter, or the chat input buffer.
24///
25/// # Examples
26///
27/// ```ignore
28/// handle_char(&mut app, modifiers, 'x').await;
29/// ```
30pub async fn handle_char(app: &mut App, modifiers: KeyModifiers, c: char) {
31    let no_mods =
32        !modifiers.contains(KeyModifiers::CONTROL) && !modifiers.contains(KeyModifiers::ALT);
33
34    if no_mods && symbol_search_active(app) {
35        app.state.symbol_search.handle_char(c);
36        refresh_symbol_search(app).await;
37    } else if app.state.view_mode == ViewMode::Bus && app.state.bus_log.filter_input_mode && no_mods
38    {
39        app.state.bus_log.push_filter_char(c);
40        app.state.status = format!("Protocol filter: {}", app.state.bus_log.filter);
41    } else if app.state.view_mode == ViewMode::Model && no_mods {
42        app.state.model_filter_push(c);
43    } else if app.state.view_mode == ViewMode::FilePicker && no_mods {
44        crate::tui::app::file_picker::file_picker_filter_push(app, c);
45    } else if app.state.view_mode == ViewMode::Chat && no_mods {
46        app.state.input_mode = if app.state.input.is_empty() && c == '/' {
47            InputMode::Command
48        } else if app.state.input.starts_with('/') || c == '/' {
49            InputMode::Command
50        } else {
51            InputMode::Editing
52        };
53        app.state.insert_char(c);
54    }
55}