Skip to main content

wisp/view/
input.rs

1use crate::view::selection::Direction;
2use crossterm::event::KeyEvent;
3
4pub enum UiEvent {
5    Key(KeyEvent),
6    Paste(String),
7    Mouse(MouseAction, (u16, u16)),
8}
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11pub enum MouseAction {
12    ScrollUp,
13    ScrollDown,
14    Click,
15}
16
17/// What a navigation event asked of the pane hosting a list.
18#[derive(Clone, Copy, Debug, Eq, PartialEq)]
19pub(crate) enum Nav {
20    /// The pane should close.
21    Close,
22    /// Enter chose the focused entry.
23    Activate,
24    /// A click moved the selection to an entry, which may also activate it.
25    Clicked,
26    /// The selection or filter query changed.
27    Moved,
28    /// Not a navigation event this list handles.
29    Unhandled,
30}
31
32impl MouseAction {
33    pub fn from_event(kind: crossterm::event::MouseEventKind) -> Option<Self> {
34        use crossterm::event::MouseEventKind;
35        match kind {
36            MouseEventKind::ScrollUp => Some(Self::ScrollUp),
37            MouseEventKind::ScrollDown => Some(Self::ScrollDown),
38            MouseEventKind::Down(_) => Some(Self::Click),
39            _ => None,
40        }
41    }
42
43    pub fn direction(self) -> Option<Direction> {
44        match self {
45            Self::ScrollUp => Some(Direction::Backward),
46            Self::ScrollDown => Some(Direction::Forward),
47            Self::Click => None,
48        }
49    }
50}