Skip to main content

codetether_agent/tui/app/input/
sessions.rs

1//! Session-view character input handler.
2//!
3//! Appends printable characters to the session filter
4//! string and loads the selected session on Enter.
5//!
6//! # Examples
7//!
8//! ```ignore
9//! handle_sessions_char(&mut app, modifiers, 'a');
10//! ```
11
12use std::path::Path;
13
14use crossterm::event::KeyModifiers;
15
16use crate::session::Session;
17use crate::tui::app::state::App;
18
19/// Append a character to the session filter string.
20///
21/// Ignores Ctrl/Alt modified keys so they can be handled
22/// by other keybind logic.
23///
24/// # Examples
25///
26/// ```ignore
27/// handle_sessions_char(&mut app, modifiers, 'a');
28/// ```
29pub fn handle_sessions_char(app: &mut App, modifiers: KeyModifiers, c: char) {
30    if !modifiers.contains(KeyModifiers::CONTROL) && !modifiers.contains(KeyModifiers::ALT) {
31        app.state.session_filter_push(c);
32    }
33}
34
35/// Load the currently selected session on Enter.
36///
37/// Reads the filtered session list, finds the original
38/// index, and loads the session by ID.
39///
40/// # Examples
41///
42/// ```ignore
43/// handle_enter_sessions(&mut app, cwd, &mut session).await;
44/// ```
45pub(super) async fn handle_enter_sessions(app: &mut App, cwd: &Path, session: &mut Session) {
46    let session_id = app
47        .state
48        .filtered_sessions()
49        .get(app.state.selected_session)
50        .map(|(orig_idx, _)| app.state.sessions[*orig_idx].id.clone());
51    if let Some(session_id) = session_id {
52        crate::tui::app::codex_sessions::load_selected_session(app, cwd, session, &session_id)
53            .await;
54    }
55}