mod health;
mod key;
mod mouse;
mod session;
mod terminal;
pub use {
health::{PingEvent, PongEvent},
key::{KeyCode, KeyEvent, KeyEventKind, Modifiers},
mouse::{ClickEvent, ClickKind, MouseButton, ScrollDirection, ScrollEvent},
session::{AttachEvent, DetachEvent, DetachReason},
terminal::{FocusEvent, FocusKind, PasteEvent, ResizeEvent},
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Input {
Key(KeyEvent),
Click(ClickEvent),
Scroll(ScrollEvent),
Resize(ResizeEvent),
Focus(FocusEvent),
Paste(PasteEvent),
Attach(AttachEvent),
Detach(DetachEvent),
Ping(PingEvent),
Pong(PongEvent),
}
impl Input {
#[must_use]
pub const fn key(event: KeyEvent) -> Self {
Self::Key(event)
}
#[must_use]
pub const fn click(event: ClickEvent) -> Self {
Self::Click(event)
}
#[must_use]
pub const fn scroll(event: ScrollEvent) -> Self {
Self::Scroll(event)
}
#[must_use]
pub const fn resize(event: ResizeEvent) -> Self {
Self::Resize(event)
}
#[must_use]
pub const fn focus(event: FocusEvent) -> Self {
Self::Focus(event)
}
#[must_use]
pub const fn paste(event: PasteEvent) -> Self {
Self::Paste(event)
}
#[must_use]
pub const fn attach(event: AttachEvent) -> Self {
Self::Attach(event)
}
#[must_use]
pub const fn detach(event: DetachEvent) -> Self {
Self::Detach(event)
}
#[must_use]
pub const fn ping(event: PingEvent) -> Self {
Self::Ping(event)
}
#[must_use]
pub const fn pong(event: PongEvent) -> Self {
Self::Pong(event)
}
#[must_use]
pub const fn is_key(&self) -> bool {
matches!(self, Self::Key(_))
}
#[must_use]
pub const fn is_click(&self) -> bool {
matches!(self, Self::Click(_))
}
#[must_use]
pub const fn is_scroll(&self) -> bool {
matches!(self, Self::Scroll(_))
}
#[must_use]
pub const fn is_resize(&self) -> bool {
matches!(self, Self::Resize(_))
}
#[must_use]
pub const fn is_focus(&self) -> bool {
matches!(self, Self::Focus(_))
}
#[must_use]
pub const fn is_paste(&self) -> bool {
matches!(self, Self::Paste(_))
}
#[must_use]
pub const fn is_attach(&self) -> bool {
matches!(self, Self::Attach(_))
}
#[must_use]
pub const fn is_detach(&self) -> bool {
matches!(self, Self::Detach(_))
}
#[must_use]
pub const fn is_ping(&self) -> bool {
matches!(self, Self::Ping(_))
}
#[must_use]
pub const fn is_pong(&self) -> bool {
matches!(self, Self::Pong(_))
}
}
#[cfg(test)]
#[path = "mod_tests.rs"]
mod tests;