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
use crate::geometry::*;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GrinInput {
    Resize(Point),
    Key(KeyEvent),
    Mouse(MouseEvent),
    Raw(Vec<u8>),
}

/// A mouse related event.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct MouseEvent {
    pub position: Point,
    pub action: MouseAction,
}

/// A mouse button.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MouseAction {
    /// A mouse left button was pressed.
    PressLeft,
    /// A mouse right button was pressed.
    PressRight,
    /// A mouse right button was pressed.
    PressMiddle,
    /// A mouse button was released.
    Release,
    /// A mouse button is held over the given coordinates.
    Drag,
    /// Mouse wheel is going up.
    WheelUp,
    /// Mouse wheel is going down.
    WheelDown,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct KeyEvent {
    pub key: Key,
    pub ctrl: bool,
    pub alt: bool,
}

/// A key.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Key {
    /// Backspace.
    Backspace,
    /// Left arrow.
    Left,
    /// Right arrow.
    Right,
    /// Up arrow.
    Up,
    /// Down arrow.
    Down,
    /// Home key.
    Home,
    /// End key.
    End,
    /// Page Up key.
    PageUp,
    /// Page Down key.
    PageDown,
    /// Delete key.
    Delete,
    /// Insert key.
    Insert,
    /// Function keys.
    ///
    /// Only function keys 1 through 12 are supported.
    F(u8),
    /// Normal character.
    Char(char),
    /// Null byte.
    Null,
    /// Esc key.
    Esc,
    /// Unknown key
    Other(u8),
}