aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-ai/src/tui/components/atuin_ai.rs
diff options
context:
space:
mode:
authorMichelle Tilley <michelle@michelletilley.net>2026-03-30 15:20:31 -0700
committerGitHub <noreply@github.com>2026-03-30 15:20:31 -0700
commit0478a05320ff7bc4257633bc945bd750864d68d4 (patch)
tree2e1abf5b0a49fe0270b70bd6385062ea81fb0ba1 /crates/atuin-ai/src/tui/components/atuin_ai.rs
parentfix: replace `e>|` with `|` in nushell integration to restore history recordi... (diff)
downloadatuin-0478a05320ff7bc4257633bc945bd750864d68d4.zip
chore: Update to eye-declare 0.3.0 (#3365)
Diffstat (limited to 'crates/atuin-ai/src/tui/components/atuin_ai.rs')
-rw-r--r--crates/atuin-ai/src/tui/components/atuin_ai.rs71
1 files changed, 22 insertions, 49 deletions
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<mpsc::Sender<AiTuiEvent>>,
}
-impl Component for AtuinAi {
- type State = AtuinAiState;
-
- fn initial_state(&self) -> Option<Self::State> {
- Some(AtuinAiState::default())
- }
-
- fn lifecycle(&self, hooks: &mut Hooks<Self::State>, _state: &Self::State) {
- hooks.use_context::<mpsc::Sender<AiTuiEvent>>(|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<Self::State>) -> EventResult {
- let state = state.read();
+#[component(props = AtuinAi, state = AtuinAiState, children = Elements)]
+fn atuin_ai(
+ _props: &AtuinAi,
+ _state: &AtuinAiState,
+ hooks: &mut Hooks<AtuinAi, AtuinAiState>,
+ children: Elements,
+) -> Elements {
+ hooks.use_context::<mpsc::Sender<AiTuiEvent>>(|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
}