From 2f702ad446fcd6a261a3bea0ab2807d70eca43e2 Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Tue, 21 Apr 2026 13:07:27 -0700 Subject: refactor: Replace ad-hoc dispatch with FSM + driver architecture (#3434) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the tangled dispatch handler system (`tui/dispatch.rs`, `tui/state.rs`) with a pure finite state machine + driver architecture. The FSM handles all state transitions as explicit `(State, Event) → (NewState, Effects)` mappings. The driver executes IO effects and bridges the TUI to the FSM. --- crates/atuin-ai/src/tui/components/input_box.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'crates/atuin-ai/src/tui/components/input_box.rs') diff --git a/crates/atuin-ai/src/tui/components/input_box.rs b/crates/atuin-ai/src/tui/components/input_box.rs index 6e041418..6b81322c 100644 --- a/crates/atuin-ai/src/tui/components/input_box.rs +++ b/crates/atuin-ai/src/tui/components/input_box.rs @@ -6,7 +6,7 @@ //! //! On Enter, sends `AiTuiEvent::SubmitInput` via the context-provided channel. -use std::sync::{Arc, Mutex, mpsc}; +use std::sync::{Arc, Mutex}; use crossterm::event::KeyModifiers; use eye_declare::{Canvas, Elements, EventResult, Hooks, component, element, props}; @@ -19,6 +19,7 @@ use ratatui_core::{ }; use tui_textarea::TextArea; +use crate::commands::inline::DriverEventSender; use crate::tui::{events::AiTuiEvent, slash::SlashCommandSearchResult}; /// A bordered text input box backed by tui-textarea. @@ -41,7 +42,7 @@ pub(crate) struct InputBox { pub(crate) struct InputBoxState { textarea: Arc>>, - tx: Option>, + tx: Option, } impl Default for InputBoxState { @@ -97,10 +98,13 @@ fn input_box( state: &InputBoxState, hooks: &mut Hooks, ) -> Elements { - hooks.use_focusable(props.active); + // Always focusable so focus isn't lost when the permission Select is + // removed from the tree. The `active` prop controls visual state and + // whether keystrokes are processed, not focusability. + hooks.use_focusable(true); hooks.use_autofocus(); - hooks.use_context::>(|tx, _, state| { + hooks.use_context::(|tx, _, state| { state.tx = tx.cloned(); }); -- cgit v1.3.1