Skip to main content

KeyPressEvent

Struct KeyPressEvent 

Source
pub struct KeyPressEvent {
    pub key: KeyInput,
    pub session_id: SessionId,
    pub client_id: ClientId,
}
Expand description

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)));

Fields§

§key: KeyInput

The key input from the input driver.

§session_id: SessionId

Session ID for routing.

§client_id: ClientId

Client ID that originated this key.

Implementations§

Source§

impl KeyPressEvent

Source

pub const fn new( key: KeyInput, session_id: SessionId, client_id: ClientId, ) -> Self

Create a new key press event.

Source

pub const fn event_type(&self) -> &'static str

Get the event type name for logging.

Trait Implementations§

Source§

impl Clone for KeyPressEvent

Source§

fn clone(&self) -> KeyPressEvent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyPressEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Event for KeyPressEvent

Source§

fn priority(&self) -> u32

Priority for handler dispatch ordering. Read more
Source§

fn batchable(&self) -> bool

Whether this event can be batched with similar events. Read more
Source§

impl PartialEq for KeyPressEvent

Source§

fn eq(&self, other: &KeyPressEvent) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for KeyPressEvent

Source§

impl StructuralPartialEq for KeyPressEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.