Skip to main content

a2ui_base/
event.rs

1//! Framework-agnostic input event types and interaction results.
2//!
3//! These types define the contract between the UI framework layer (e.g. ratatui)
4//! and the core A2UI runtime, enabling keyboard events to be routed to components
5//! and interaction results (actions, data updates) to flow back to the application.
6
7use std::collections::HashMap;
8
9/// A user input event, framework-agnostic.
10#[derive(Debug, Clone, PartialEq)]
11pub enum InputEvent {
12    /// A key was pressed.
13    KeyPress { key: InputKey },
14}
15
16/// Logical key identifiers, independent of any specific UI framework.
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub enum InputKey {
19    /// A printable character.
20    Char(char),
21    /// Enter / Return key.
22    Enter,
23    /// Tab key.
24    Tab,
25    /// Shift+Tab.
26    BackTab,
27    /// Arrow keys.
28    Up,
29    Down,
30    Left,
31    Right,
32    /// Backspace key.
33    Backspace,
34    /// Delete key.
35    Delete,
36    /// Escape key.
37    Escape,
38    /// Space bar.
39    Space,
40}
41
42/// Result produced by a component handling an input event.
43#[derive(Debug, Clone)]
44pub enum EventResult {
45    /// Dispatch an action to the server.
46    Action {
47        /// The event name.
48        event_name: String,
49        /// Context values to send with the event.
50        context: HashMap<String, serde_json::Value>,
51        /// Whether the action expects a response.
52        want_response: bool,
53        /// Optional data model path to write the response value.
54        response_path: Option<String>,
55    },
56    /// Write a value back to the data model at the given path.
57    DataUpdate {
58        /// JSON Pointer path in the data model.
59        path: String,
60        /// The new value.
61        value: serde_json::Value,
62    },
63    /// Toggle a boolean value in the data model.
64    Toggle {
65        /// JSON Pointer path in the data model.
66        path: String,
67    },
68    /// Component consumed the event; no further processing needed.
69    Consumed,
70}