From 0478a05320ff7bc4257633bc945bd750864d68d4 Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Mon, 30 Mar 2026 15:20:31 -0700 Subject: chore: Update to eye-declare 0.3.0 (#3365) --- crates/atuin-ai/src/tui/components/atuin_ai.rs | 73 ++++++++------------------ 1 file changed, 23 insertions(+), 50 deletions(-) (limited to 'crates/atuin-ai/src/tui/components/atuin_ai.rs') diff --git a/crates/atuin-ai/src/tui/components/atuin_ai.rs b/crates/atuin-ai/src/tui/components/atuin_ai.rs index b2239a70..fab29502 100644 --- a/crates/atuin-ai/src/tui/components/atuin_ai.rs +++ b/crates/atuin-ai/src/tui/components/atuin_ai.rs @@ -7,7 +7,7 @@ use std::sync::mpsc; use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; -use eye_declare::{Component, EventResult, Hooks, Tracked, impl_slot_children}; +use eye_declare::{Elements, EventResult, Hooks, component, props}; use crate::tui::events::AiTuiEvent; use crate::tui::state::AppMode; @@ -16,60 +16,31 @@ use crate::tui::state::AppMode; /// /// Props carry the current mode so `handle_event` can translate keys /// into the right `AiTuiEvent`. Children are rendered via slot children. -pub struct AtuinAi { +#[props] +pub(crate) struct AtuinAi { pub mode: AppMode, pub has_command: bool, pub is_input_blank: bool, pub pending_confirmation: bool, } -impl Default for AtuinAi { - fn default() -> Self { - Self { - mode: AppMode::Input, - has_command: false, - is_input_blank: false, - pending_confirmation: false, - } - } -} - -impl_slot_children!(AtuinAi); - #[derive(Default)] pub struct AtuinAiState { tx: Option>, } -impl Component for AtuinAi { - type State = AtuinAiState; - - fn initial_state(&self) -> Option { - Some(AtuinAiState::default()) - } - - fn lifecycle(&self, hooks: &mut Hooks, _state: &Self::State) { - hooks.use_context::>(|tx, state| { - state.tx = tx.cloned(); - }); - } - - fn render( - &self, - _area: ratatui::layout::Rect, - _buf: &mut ratatui::buffer::Buffer, - _state: &Self::State, - ) { - // Rendering is handled by slot children - } - - fn desired_height(&self, _width: u16, _state: &Self::State) -> u16 { - 0 - } - - fn handle_event_capture(&self, event: &Event, state: &mut Tracked) -> EventResult { - let state = state.read(); - +#[component(props = AtuinAi, state = AtuinAiState, children = Elements)] +fn atuin_ai( + _props: &AtuinAi, + _state: &AtuinAiState, + hooks: &mut Hooks, + children: Elements, +) -> Elements { + hooks.use_context::>(|tx, _, state| { + state.tx = tx.cloned(); + }); + + hooks.use_event_capture(move |event, props, state| { let Event::Key(KeyEvent { code, kind: KeyEventKind::Press, @@ -80,7 +51,7 @@ impl Component for AtuinAi { return EventResult::Ignored; }; - let Some(ref tx) = state.tx else { + let Some(ref tx) = state.read().tx else { return EventResult::Ignored; }; @@ -90,10 +61,10 @@ impl Component for AtuinAi { return EventResult::Consumed; } - match self.mode { + match props.mode { AppMode::Input => match code { KeyCode::Esc => { - if self.pending_confirmation { + if props.pending_confirmation { let _ = tx.send(AiTuiEvent::CancelConfirmation); return EventResult::Consumed; } @@ -102,7 +73,7 @@ impl Component for AtuinAi { EventResult::Consumed } KeyCode::Tab => { - if self.has_command && self.is_input_blank { + if props.has_command && props.is_input_blank { let _ = tx.send(AiTuiEvent::InsertCommand); return EventResult::Consumed; } @@ -110,7 +81,7 @@ impl Component for AtuinAi { EventResult::Ignored } KeyCode::Enter => { - if self.has_command && self.is_input_blank { + if props.has_command && props.is_input_blank { let _ = tx.send(AiTuiEvent::ExecuteCommand); return EventResult::Consumed; } @@ -138,5 +109,7 @@ impl Component for AtuinAi { _ => EventResult::Ignored, }, } - } + }); + + children } -- cgit v1.3.1