Skip to main content

codetether_agent/tui/app/input/
enter.rs

1//! Enter-key dispatch across all TUI view modes.
2//!
3//! Examines the active view mode and routes the Enter
4//! press to the appropriate handler — sessions, chat,
5//! bus filter, model, settings, etc.
6//!
7//! # Examples
8//!
9//! ```ignore
10//! dispatch_enter(&mut app, cwd, &mut session, &reg,
11//!     &bridge, &tx, &rtx).await;
12//! ```
13
14use std::{path::Path, sync::Arc};
15use tokio::sync::mpsc;
16
17use crate::provider::ProviderRegistry;
18use crate::session::{Session, SessionEvent};
19use crate::tui::app::{settings::toggle_selected_setting, state::App};
20use crate::tui::{models::ViewMode, worker_bridge::TuiWorkerBridge};
21
22/// Dispatch Enter to the handler matching the active view.
23///
24/// # Examples
25///
26/// ```ignore
27/// dispatch_enter(&mut app, cwd, &mut session, &reg,
28///     &bridge, &tx, &rtx).await;
29/// ```
30pub async fn dispatch_enter(
31    app: &mut App,
32    cwd: &Path,
33    session: &mut Session,
34    registry: &Option<Arc<ProviderRegistry>>,
35    worker_bridge: &Option<TuiWorkerBridge>,
36    event_tx: &mpsc::Sender<SessionEvent>,
37    result_tx: &mpsc::Sender<anyhow::Result<Session>>,
38) {
39    match app.state.view_mode {
40        ViewMode::Sessions => super::sessions::handle_enter_sessions(app, cwd, session).await,
41        ViewMode::FilePicker => crate::tui::app::file_picker::file_picker_enter(app, cwd),
42        ViewMode::Swarm => app.state.swarm.enter_detail(),
43        ViewMode::Ralph => app.state.ralph.enter_detail(),
44        ViewMode::Bus if app.state.bus_log.filter_input_mode => {
45            super::bus::handle_enter_bus_filter(app)
46        }
47        ViewMode::Bus => app.state.bus_log.enter_detail(),
48        ViewMode::Chat => {
49            super::chat_submit::handle_enter_chat(
50                app,
51                cwd,
52                session,
53                registry,
54                worker_bridge,
55                event_tx,
56                result_tx,
57            )
58            .await
59        }
60        ViewMode::Model => crate::tui::app::model_picker::apply_selected_model(app, session),
61        ViewMode::Settings => toggle_selected_setting(app, session).await,
62        ViewMode::Lsp
63        | ViewMode::Rlm
64        | ViewMode::Latency
65        | ViewMode::Protocol
66        | ViewMode::Inspector => {}
67    }
68}