bear_lib_terminal/terminal/input.rs
1/// All pressable keys.
2#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
3pub enum KeyCode {
4 A,
5 B,
6 C,
7 D,
8 E,
9 F,
10 G,
11 H,
12 I,
13 J,
14 K,
15 L,
16 M,
17 N,
18 O,
19 P,
20 Q,
21 R,
22 S,
23 T,
24 U,
25 V,
26 W,
27 X,
28 Y,
29 Z,
30 /// Top-row `1/!` key.
31 Row1,
32 /// Top-row `2/@` key.
33 Row2,
34 /// Top-row `3/#` key.
35 Row3,
36 /// Top-row `4/$` key.
37 Row4,
38 /// Top-row `5/%` key.
39 Row5,
40 /// Top-row `6/^` key.
41 Row6,
42 /// Top-row `7/&` key.
43 Row7,
44 /// Top-row `8/*` key.
45 Row8,
46 /// Top-row `9/(` key.
47 Row9,
48 /// Top-row `0/)` key.
49 Row0,
50 /// Top-row `/~ key.
51 Grave,
52 /// Top-row `-/_` key.
53 Minus,
54 /// Top-row `=/+` key.
55 Equals,
56 /// Second-row `[/{` key.
57 LeftBracket,
58 /// Second-row `]/}` key.
59 RightBracket,
60 /// Second-row `\/|` key.
61 Backslash,
62 /// Third-row `;/:` key.
63 Semicolon,
64 /// Third-row `'/"` key.
65 Apostrophe,
66 /// Fourth-row `,/<` key.
67 Comma,
68 /// Fourth-row `./>` key.
69 Period,
70 /// Fourth-row `//?` key.
71 Slash,
72 F1,
73 F2,
74 F3,
75 F4,
76 F5,
77 F6,
78 F7,
79 F8,
80 F9,
81 F10,
82 F11,
83 F12,
84 Enter,
85 Escape,
86 Backspace,
87 Tab,
88 Space,
89 Pause,
90 Insert,
91 Home,
92 PageUp,
93 Delete,
94 End,
95 PageDown,
96 /// Right arrow key.
97 Right,
98 /// Left arrow key.
99 Left,
100 /// Down arrow key.
101 Down,
102 /// Up arrow key.
103 Up,
104 /// Numpad `/` key.
105 NumDivide,
106 /// Numpad `*` key.
107 NumMultiply,
108 /// Numpad `-` key.
109 NumMinus,
110 /// Numpad `+` key.
111 NumPlus,
112 /// Numpad ⏎ key.
113 NumEnter,
114 /// Numpad `Del/.` key (output locale-dependent).
115 NumPeriod,
116 /// Numpad `1/End` key.
117 Num1,
118 /// Numpad 2/↓ key.
119 Num2,
120 /// Numpad `3/PageDown` key.
121 Num3,
122 /// Numpad 4/← key.
123 Num4,
124 /// Numpad `5` key.
125 Num5,
126 /// Numpad 6/→ key.
127 Num6,
128 /// Numpad `7/Home` key.
129 Num7,
130 /// Numpad 8/↑ key.
131 Num8,
132 /// Numpad `9/PageUp` key.
133 Num9,
134 /// Numpad `0/Insert` key.
135 Num0,
136 /// Left mouse button.
137 MouseLeft,
138 /// Right mouse button.
139 MouseRight,
140 /// Middle mouse button a.k.a. pressed scroll wheel.
141 MouseMiddle,
142 MouseFourth,
143 MouseFifth,
144}
145
146/// A single input event.
147#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
148pub enum Event {
149 /// Terminal window closed.
150 Close,
151 /// Terminal window resized. Needs to have `window.resizeable = true` to occur.
152 ///
153 /// Note, that, as of [`40e6253`](https://bitbucket.org/cfyzium/bearlibterminal/commits/40e625311f0cccc43b94633add4dec0d6b77c2b7),
154 /// the terminal window is cleared when resized.
155 Resize{
156 /// Width the terminal was resized to.
157 width: i32,
158 /// Heigth the terminal was resized to.
159 height: i32,
160 },
161 /// Mouse moved.
162 ///
163 /// If [`precise-mouse`](config/struct.Input.html#structfield.precise_mouse) is off, generated each time mouse moves from cell to cell, otherwise,
164 /// when it moves from pixel to pixel.
165 MouseMove{
166 /// `0`-based cell index from the left to which the mouse cursor moved.
167 x: i32,
168 /// `0`-based cell index from the top to which the mouse cursor moved.
169 y: i32
170 },
171 /// Mouse wheel moved.
172 MouseScroll{
173 /// Amount of steps the wheel rotated.
174 ///
175 /// Positive when scrolled "down"/"backwards".
176 ///
177 /// Negative when scrolled "up"/"forwards"/"away".
178 delta: i32
179 },
180 /// A keyboard or mouse button pressed (might repeat, if set in OS).
181 KeyPressed{
182 /// The key pressed.
183 key: KeyCode,
184 /// Whether the Control key is pressed.
185 ctrl: bool,
186 /// Whether the Shift key is pressed.
187 shift: bool
188 },
189 /// A keyboard or mouse button released.
190 KeyReleased{
191 /// The key released.
192 key: KeyCode,
193 /// Whether the Control key is pressed.
194 ctrl: bool,
195 /// Whether the Shift key is pressed.
196 shift: bool
197 },
198 /// The Shift key pressed (might repeat, if set in OS).
199 ShiftPressed,
200 /// The Shift key released.
201 ShiftReleased,
202 /// The Shift key pressed (might repeat, if set in OS).
203 ControlPressed,
204 /// The Control key released.
205 ControlReleased,
206 /// The Alt key pressed (might repeat, if set in OS).
207 AltPressed,
208 /// The Alt key released.
209 AltReleased,
210}