6 Commits

Author SHA1 Message Date
Josh McKinney
41bcd3b783
fix: clippy lints (#1000) 2025-07-13 18:18:47 -07:00
Josh McKinney
e063091312
Add is_* and as_* methods to the event enums (#949)
* Add is_ and as_ methods to the event enums

Often application code only cares about a small subset of possible
events. These methods make it simpler to write code which checks whether
an event is a particular event type or converts events into the specific
type (returning an Option).

This can help simplify some nested match blocks. E.g.:

```rust
match event {
    Event::Key(key) if key.kind == KeyEventKind::Press => { ... }
}
```

becomes:

```rust
if let Some(key) = event.as_key_press() { ... }
```

Similar flexible methods are aded across all the event enums:

- `Event::is_focus_gained()`
- `Event::is_focus_lost()`
- `Event::is_key()`
- `Event::is_mouse()`
- `Event::is_paste()`
- `Event::is_resize()`
- `Event::is_key_press()`
- `Event::as_key_press() -> Option<&KeyEvent>`
- `MouseEventKind::is_*()`
- `MouseButton::is_*()`
- `KeyEventKind::is_*()`
- `KeyEvent::is_press()`
- `KeyEvent::is_release()`
- `KeyEvent::is_repeat()`
- `KeyCode::is_*()`
- `KeyCode::is_function_key(n)`
- `KeyCode::is_char(c)`
- `KeyCode::as_char() -> Option<char>`
- `KeyCode::is_media_key(media)`
- `KeyCode::is_modifier(modifier)`
- add is_key_release() and is_key_repeat() checks
- add as_key_event()
- rename as_key_press() to as_key_press_event()
- add as_key_repeat_event()
- add as_key_release_event()
- add as_mouse_event()
- add as_paste_event()
- more tests
- update event-match and key-display examples
2025-02-02 11:31:10 +01:00
Charlie Groves
1fee5ff30c
Add bracketed paste parsing (#693) 2022-08-10 09:16:56 +02:00
Jesse Weaver
551659dee3
Add support for functional key codes from kitty keyboard protocol (#691) 2022-07-30 10:33:59 +02:00
Jesse Weaver
60e51be726
Increase support for kitty enhanced keyboard protocol (#688) 2022-07-24 14:06:46 +02:00
Timon
47e8366f2b
Moved examples back into crossterm (#332) 2019-12-10 21:07:15 +01:00