Skip to content

Commit 18909aa

Browse files
authored
Update to crossterm-0.25 (#3390)
1 parent d993c63 commit 18909aa

File tree

7 files changed

+34
-6
lines changed

7 files changed

+34
-6
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helix-term/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ which = "4.2"
3838

3939
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] }
4040
tui = { 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"] }
4242
signal-hook = "0.3"
4343
tokio-stream = "0.1"
4444
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }

helix-term/src/ui/editor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ default = ["crossterm"]
1919
bitflags = "1.3"
2020
cassowary = "0.3"
2121
unicode-segmentation = "1.9"
22-
crossterm = { version = "0.24", optional = true }
22+
crossterm = { version = "0.25", optional = true }
2323
serde = { version = "1", "optional" = true, features = ["derive"]}
2424
helix-view = { version = "0.6", path = "../helix-view", features = ["term"] }
2525
helix-core = { version = "0.6", path = "../helix-core" }

helix-view/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ anyhow = "1"
1919
helix-core = { version = "0.6", path = "../helix-core" }
2020
helix-lsp = { version = "0.6", path = "../helix-lsp" }
2121
helix-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
2525
once_cell = "1.13"

helix-view/src/input.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub use crate::keyboard::{KeyCode, KeyModifiers};
88

99
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
1010
pub enum Event {
11+
FocusGained,
12+
FocusLost,
1113
Key(KeyEvent),
1214
Mouse(MouseEvent),
1315
Resize(u16, u16),
@@ -57,6 +59,7 @@ pub enum MouseButton {
5759
pub 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

6265
impl 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")]
323331
impl 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
Original file line numberDiff line numberDiff line change
@@ -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
}

0 commit comments

Comments
 (0)