1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//! Key press event for event-driven key dispatch.
//!
//! This event bridges the input driver and the runner's key handling
//! system, enabling loosely-coupled key processing via `EventBus`.
//!
//! # Design Philosophy
//!
//! Following "mechanism, not policy":
//! - `KeyPressEvent` is a pure data carrier (mechanism)
//! - How keys are resolved is decided by handlers (policy in runner)
//! - Session/client routing enables multi-session support
//!
//! # Example
//!
//! ```
//! use reovim_kernel::api::v1::events::{KeyInput, KeyCode, Modifiers};
//! use reovim_kernel::api::v1::events::key::{KeyPressEvent, SessionId, ClientId};
//!
//! let key = KeyInput {
//! key: KeyCode::Char('j'),
//! modifiers: Modifiers::NONE,
//! };
//!
//! let event = KeyPressEvent::new(key, SessionId::new(0), ClientId::new(1));
//! assert_eq!(event.session_id.as_usize(), 0);
//! assert_eq!(event.client_id.as_usize(), 1);
//! ```
use crateEvent;
use KeyInput;
// =============================================================================
// Session and Client Identifiers
// =============================================================================
/// Session identifier for event routing.
///
/// Represents a named editing session (like tmux sessions). Multiple clients
/// can attach to the same session and share state.
///
/// This is a kernel-level mechanism type. The runner maps this to its
/// internal session management.
;
/// Client identifier for event routing.
///
/// Represents a connection to the server (like a tmux client). Each client
/// has a unique ID within the server.
///
/// This is a kernel-level mechanism type. The runner maps this to its
/// internal client/connection management.
;
// =============================================================================
// Key Press Event
// =============================================================================
/// Key press event emitted when a key is received.
///
/// This event is emitted by the runner's event loop and handled by
/// registered key handlers. The handler performs key resolution
/// and returns state changes via the result holder.
///
/// # Synchronous Processing
///
/// Key events are processed synchronously via `bus.emit()` because:
/// - Key handling must complete before the next key is read
/// - State mutations need to happen in order
/// - Latency requirements demand immediate processing
///
/// # Session Routing
///
/// The `session_id` and `client_id` identify which session should
/// process the key. Handlers filter events by session ID.
///
/// # Example
///
/// ```
/// use reovim_kernel::api::v1::{EventBus, EventResult};
/// use reovim_kernel::api::v1::events::{KeyInput, KeyCode, Modifiers, priority};
/// use reovim_kernel::api::v1::events::key::{KeyPressEvent, SessionId, ClientId};
///
/// let bus = EventBus::new();
///
/// // Register handler for session 0
/// let session_id = SessionId::new(0);
/// let _sub = bus.subscribe::<KeyPressEvent, _>(priority::CORE, move |event| {
/// if event.session_id != session_id {
/// return EventResult::NotHandled;
/// }
/// // Process key...
/// EventResult::Handled
/// });
///
/// // Emit key event
/// let key = KeyInput {
/// key: KeyCode::Char('j'),
/// modifiers: Modifiers::NONE,
/// };
/// bus.emit(KeyPressEvent::new(key, SessionId::new(0), ClientId::new(1)));
/// ```
// =============================================================================