on master help sign in
Update to crossterm-0.25 (#3390)
commit18909aafe21ed32f11dcdf646423b43b1a951010 authorCharlie Groves <c@sevorg.org> dateMon 22 Aug 2022, 01:29 (4 years ago) parentd993c63
7 files changed+34−6
Cargo.lock+2−2 helix-term/Cargo.toml+1−1 helix-term/src/ui/editor.rs+1 helix-tui/Cargo.toml+1−1 helix-view/Cargo.toml+1−1 helix-view/src/input.rs+17−1 helix-view/src/keyboard.rs+11
Cargo.lock+2−2
@@ -152,9 +152,9 @@ dependencies = [
152152
153153[[package]]
154154name = "crossterm"
155−version = "0.24.0"
155+version = "0.25.0"
156156source = "registry+https://github.com/rust-lang/crates.io-index"
157−checksum = "ab9f7409c70a38a56216480fba371ee460207dd8926ccf5b4160591759559170"
157+checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67"
158158dependencies = [
159159 "bitflags",
160160 "crossterm_winapi",
helix-term/Cargo.toml+1−1
@@ -38,7 +38,7 @@ which = "4.2"
3838
3939tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] }
4040tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] }
41−crossterm = { version = "0.24", features = ["event-stream"] }
41+crossterm = { version = "0.25", features = ["event-stream"] }
4242signal-hook = "0.3"
4343tokio-stream = "0.1"
4444futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
helix-term/src/ui/editor.rs+1
@@ -1253,6 +1253,7 @@ impl Component for EditorView {
12531253 }
12541254
12551255 Event::Mouse(event) => self.handle_mouse_event(event, &mut cx),
1256+ Event::FocusGained | Event::FocusLost => EventResult::Ignored(None),
12561257 }
12571258 }
12581259
helix-tui/Cargo.toml+1−1
@@ -19,7 +19,7 @@ default = ["crossterm"]
1919bitflags = "1.3"
2020cassowary = "0.3"
2121unicode-segmentation = "1.9"
22−crossterm = { version = "0.24", optional = true }
22+crossterm = { version = "0.25", optional = true }
2323serde = { version = "1", "optional" = true, features = ["derive"]}
2424helix-view = { version = "0.6", path = "../helix-view", features = ["term"] }
2525helix-core = { version = "0.6", path = "../helix-core" }
helix-view/Cargo.toml+1−1
@@ -19,7 +19,7 @@ anyhow = "1"
1919helix-core = { version = "0.6", path = "../helix-core" }
2020helix-lsp = { version = "0.6", path = "../helix-lsp" }
2121helix-dap = { version = "0.6", path = "../helix-dap" }
22−crossterm = { version = "0.24", optional = true }
22+crossterm = { version = "0.25", optional = true }
2323
2424# Conversion traits
2525once_cell = "1.13"
helix-view/src/input.rs+17−1
@@ -8,6 +8,8 @@ pub use crate::keyboard::{KeyCode, KeyModifiers};
88
99#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
1010pub enum Event {
11+ FocusGained,
12+ FocusLost,
1113 Key(KeyEvent),
1214 Mouse(MouseEvent),
1315 Resize(u16, u16),
@@ -57,6 +59,7 @@ pub enum MouseButton {
5759pub struct KeyEvent {
5860 pub code: KeyCode,
5961 pub modifiers: KeyModifiers,
62+ // TODO: crossterm now supports kind & state if terminal supports kitty's extended protocol
6063}
6164
6265impl KeyEvent {
@@ -271,6 +274,11 @@ impl From<crossterm::event::Event> for Event {
271274 crossterm::event::Event::Key(key) => Self::Key(key.into()),
272275 crossterm::event::Event::Mouse(mouse) => Self::Mouse(mouse.into()),
273276 crossterm::event::Event::Resize(w, h) => Self::Resize(w, h),
277+ crossterm::event::Event::FocusGained => Self::FocusGained,
278+ crossterm::event::Event::FocusLost => Self::FocusLost,
279+ crossterm::event::Event::Paste(_) => {
280+ unreachable!("crossterm shouldn't emit Paste events without them being enabled")
281+ }
274282 }
275283 }
276284}
@@ -321,7 +329,11 @@ impl From<crossterm::event::MouseButton> for MouseButton {
321329
322330#[cfg(feature = "term")]
323331impl From<crossterm::event::KeyEvent> for KeyEvent {
324− fn from(crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent) -> Self {
332+ fn from(
333+ crossterm::event::KeyEvent {
334+ code, modifiers, ..
335+ }: crossterm::event::KeyEvent,
336+ ) -> Self {
325337 if code == crossterm::event::KeyCode::BackTab {
326338 // special case for BackTab -> Shift-Tab
327339 let mut modifiers: KeyModifiers = modifiers.into();
@@ -349,11 +361,15 @@ impl From<KeyEvent> for crossterm::event::KeyEvent {
349361 crossterm::event::KeyEvent {
350362 code: crossterm::event::KeyCode::BackTab,
351363 modifiers: modifiers.into(),
364+ kind: crossterm::event::KeyEventKind::Press,
365+ state: crossterm::event::KeyEventState::NONE,
352366 }
353367 } else {
354368 crossterm::event::KeyEvent {
355369 code: code.into(),
356370 modifiers: modifiers.into(),
371+ kind: crossterm::event::KeyEventKind::Press,
372+ state: crossterm::event::KeyEventState::NONE,
357373 }
358374 }
359375 }
helix-view/src/keyboard.rs+11
@@ -147,6 +147,17 @@ impl From<crossterm::event::KeyCode> for KeyCode {
147147 CKeyCode::Char(character) => KeyCode::Char(character),
148148 CKeyCode::Null => KeyCode::Null,
149149 CKeyCode::Esc => KeyCode::Esc,
150+ CKeyCode::CapsLock
151+ | CKeyCode::ScrollLock
152+ | CKeyCode::NumLock
153+ | CKeyCode::PrintScreen
154+ | CKeyCode::Pause
155+ | CKeyCode::Menu
156+ | CKeyCode::KeypadBegin
157+ | CKeyCode::Media(_)
158+ | CKeyCode::Modifier(_) => unreachable!(
159+ "Shouldn't get this key without enabling DISAMBIGUATE_ESCAPE_CODES in crossterm"
160+ ),
150161 }
151162 }
152163}