use crate::{
escape::{csi::Csi, dcs::Dcs, osc::Osc},
WindowSize,
};
pub(crate) mod reader;
pub(crate) mod source;
#[cfg(feature = "event-stream")]
pub(crate) mod stream;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
Key(KeyEvent),
Mouse(MouseEvent),
WindowResized(WindowSize),
FocusIn,
FocusOut,
Paste(String),
Csi(Csi),
Osc(Osc<'static>),
Dcs(Dcs),
}
impl Event {
#[inline]
pub fn is_escape(&self) -> bool {
matches!(self, Self::Csi(_) | Self::Dcs(_) | Self::Osc(_))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct KeyEvent {
pub code: KeyCode,
pub kind: KeyEventKind,
pub modifiers: Modifiers,
pub state: KeyEventState,
}
impl KeyEvent {
pub const fn new(code: KeyCode, modifiers: Modifiers) -> Self {
Self {
code,
modifiers,
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
}
}
}
impl From<KeyCode> for KeyEvent {
fn from(code: KeyCode) -> Self {
Self {
code,
kind: KeyEventKind::Press,
modifiers: Modifiers::NONE,
state: KeyEventState::NONE,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyEventKind {
Press,
Release,
Repeat,
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Modifiers: u8 {
const NONE = 0;
const SHIFT = 1 << 1;
const ALT = 1 << 2;
const CONTROL = 1 << 3;
const SUPER = 1 << 4;
const HYPER = 1 << 5;
const META = 1 << 5;
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct KeyEventState: u8 {
const NONE = 0;
const KEYPAD = 1 << 1;
const CAPS_LOCK = 1 << 2;
const NUM_LOCK = 1 << 3;
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyCode {
Char(char),
Enter,
Backspace,
Tab,
Escape,
Left,
Right,
Up,
Down,
Home,
End,
BackTab,
PageUp,
PageDown,
Insert,
Delete,
KeypadBegin,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
Menu,
Null,
Function(u8),
Modifier(ModifierKeyCode),
Media(MediaKeyCode),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ModifierKeyCode {
LeftShift,
LeftControl,
LeftAlt,
LeftSuper,
LeftHyper,
LeftMeta,
RightShift,
RightControl,
RightAlt,
RightSuper,
RightHyper,
RightMeta,
IsoLevel3Shift,
IsoLevel5Shift,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MediaKeyCode {
Play,
Pause,
PlayPause,
Reverse,
Stop,
FastForward,
Rewind,
TrackNext,
TrackPrevious,
Record,
LowerVolume,
RaiseVolume,
MuteVolume,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MouseEvent {
pub kind: MouseEventKind,
pub column: u16,
pub row: u16,
pub modifiers: Modifiers,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MouseEventKind {
Down(MouseButton),
Up(MouseButton),
Drag(MouseButton),
Moved,
ScrollDown,
ScrollUp,
ScrollLeft,
ScrollRight,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MouseButton {
Left,
Right,
Middle,
}