mirror of
https://github.com/crossterm-rs/crossterm.git
synced 2025-10-01 15:02:47 +00:00
Add a feature flag for derive_more
impls (#970)
This adds a feature flag to allow opting out of the `derive_more` dependency and derivations added in e063091. `derive_more` brings in heavy proc macro dependencies and isn't crucial for the core functioning of crossterm, so it should be possible for a crossterm dependent to opt out of bringing in the transitive dependency.
This commit is contained in:
parent
2c18768d2c
commit
12f36ec316
@ -21,7 +21,7 @@ path = "src/lib.rs"
|
|||||||
all-features = true
|
all-features = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["bracketed-paste", "events", "windows"]
|
default = ["bracketed-paste", "events", "windows", "derive-more"]
|
||||||
|
|
||||||
#! ### Default features
|
#! ### Default features
|
||||||
## Enables triggering [`Event::Paste`](event::Event::Paste) when pasting text into the terminal.
|
## Enables triggering [`Event::Paste`](event::Event::Paste) when pasting text into the terminal.
|
||||||
@ -44,9 +44,12 @@ serde = ["dep:serde", "bitflags/serde"]
|
|||||||
## Enables raw file descriptor polling / selecting instead of mio.
|
## Enables raw file descriptor polling / selecting instead of mio.
|
||||||
use-dev-tty = ["filedescriptor", "rustix/process"]
|
use-dev-tty = ["filedescriptor", "rustix/process"]
|
||||||
|
|
||||||
|
## Enables `is_*` helper functions for event enums.
|
||||||
|
derive-more = ["dep:derive_more"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = { version = "2.3" }
|
bitflags = { version = "2.3" }
|
||||||
derive_more = { version = "1.0.0", features = ["is_variant"] }
|
derive_more = { version = "1.0.0", features = ["is_variant"], optional = true }
|
||||||
document-features = "0.2.10"
|
document-features = "0.2.10"
|
||||||
futures-core = { version = "0.3", optional = true, default-features = false }
|
futures-core = { version = "0.3", optional = true, default-features = false }
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
|
@ -153,6 +153,7 @@ features = ["event-stream"]
|
|||||||
| `serde` | (De)serializing of events. |
|
| `serde` | (De)serializing of events. |
|
||||||
| `events` | Reading input/system events (enabled by default) |
|
| `events` | Reading input/system events (enabled by default) |
|
||||||
| `filedescriptor` | Use raw filedescriptor for all events rather then mio dependency |
|
| `filedescriptor` | Use raw filedescriptor for all events rather then mio dependency |
|
||||||
|
| `derive-more` | Adds `is_*` helper functions for event types |
|
||||||
|
|
||||||
|
|
||||||
To use crossterm as a very thin layer you can disable the `events` feature or use `filedescriptor` feature.
|
To use crossterm as a very thin layer you can disable the `events` feature or use `filedescriptor` feature.
|
||||||
@ -170,6 +171,7 @@ This can disable `mio` / `signal-hook` / `signal-hook-mio` dependencies.
|
|||||||
| `winapi` | Used for low-level windows system calls which ANSI codes can't replace | windows only |
|
| `winapi` | Used for low-level windows system calls which ANSI codes can't replace | windows only |
|
||||||
| `futures-core` | For async stream of events | only with `event-stream` feature flag |
|
| `futures-core` | For async stream of events | only with `event-stream` feature flag |
|
||||||
| `serde` | ***ser***ializing and ***de***serializing of events | only with `serde` feature flag |
|
| `serde` | ***ser***ializing and ***de***serializing of events | only with `serde` feature flag |
|
||||||
|
| `derive_more` | Adds `is_*` helper functions for event types | optional (`derive-more` feature), included by default |
|
||||||
|
|
||||||
### Other Resources
|
### Other Resources
|
||||||
|
|
||||||
|
31
src/event.rs
31
src/event.rs
@ -126,6 +126,7 @@ pub(crate) mod stream;
|
|||||||
pub(crate) mod sys;
|
pub(crate) mod sys;
|
||||||
pub(crate) mod timeout;
|
pub(crate) mod timeout;
|
||||||
|
|
||||||
|
#[cfg(feature = "derive-more")]
|
||||||
use derive_more::derive::IsVariant;
|
use derive_more::derive::IsVariant;
|
||||||
#[cfg(feature = "event-stream")]
|
#[cfg(feature = "event-stream")]
|
||||||
pub use stream::EventStream;
|
pub use stream::EventStream;
|
||||||
@ -543,8 +544,9 @@ impl Command for PopKeyboardEnhancementFlags {
|
|||||||
|
|
||||||
/// Represents an event.
|
/// Represents an event.
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
|
#[cfg_attr(feature = "derive-more", derive(IsVariant))]
|
||||||
#[cfg_attr(not(feature = "bracketed-paste"), derive(Copy))]
|
#[cfg_attr(not(feature = "bracketed-paste"), derive(Copy))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Hash, IsVariant)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Hash)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
/// The terminal gained focus
|
/// The terminal gained focus
|
||||||
FocusGained,
|
FocusGained,
|
||||||
@ -793,7 +795,8 @@ pub struct MouseEvent {
|
|||||||
/// `MouseEventKind::Up` and `MouseEventKind::Drag` events. `MouseButton::Left`
|
/// `MouseEventKind::Up` and `MouseEventKind::Drag` events. `MouseButton::Left`
|
||||||
/// is returned if we don't know which button was used.
|
/// is returned if we don't know which button was used.
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash, IsVariant)]
|
#[cfg_attr(feature = "derive-more", derive(IsVariant))]
|
||||||
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub enum MouseEventKind {
|
pub enum MouseEventKind {
|
||||||
/// Pressed mouse button. Contains the button that was pressed.
|
/// Pressed mouse button. Contains the button that was pressed.
|
||||||
Down(MouseButton),
|
Down(MouseButton),
|
||||||
@ -815,7 +818,8 @@ pub enum MouseEventKind {
|
|||||||
|
|
||||||
/// Represents a mouse button.
|
/// Represents a mouse button.
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash, IsVariant)]
|
#[cfg_attr(feature = "derive-more", derive(IsVariant))]
|
||||||
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub enum MouseButton {
|
pub enum MouseButton {
|
||||||
/// Left mouse button.
|
/// Left mouse button.
|
||||||
Left,
|
Left,
|
||||||
@ -895,7 +899,8 @@ impl Display for KeyModifiers {
|
|||||||
|
|
||||||
/// Represents a keyboard event kind.
|
/// Represents a keyboard event kind.
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash, IsVariant)]
|
#[cfg_attr(feature = "derive-more", derive(IsVariant))]
|
||||||
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub enum KeyEventKind {
|
pub enum KeyEventKind {
|
||||||
Press,
|
Press,
|
||||||
Repeat,
|
Repeat,
|
||||||
@ -1002,17 +1007,17 @@ impl KeyEvent {
|
|||||||
|
|
||||||
/// Returns whether the key event is a press event.
|
/// Returns whether the key event is a press event.
|
||||||
pub fn is_press(&self) -> bool {
|
pub fn is_press(&self) -> bool {
|
||||||
self.kind.is_press()
|
matches!(self.kind, KeyEventKind::Press)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the key event is a release event.
|
/// Returns whether the key event is a release event.
|
||||||
pub fn is_release(&self) -> bool {
|
pub fn is_release(&self) -> bool {
|
||||||
self.kind.is_release()
|
matches!(self.kind, KeyEventKind::Release)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the key event is a repeat event.
|
/// Returns whether the key event is a repeat event.
|
||||||
pub fn is_repeat(&self) -> bool {
|
pub fn is_repeat(&self) -> bool {
|
||||||
self.kind.is_repeat()
|
matches!(self.kind, KeyEventKind::Repeat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1214,7 +1219,8 @@ impl Display for ModifierKeyCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a key.
|
/// Represents a key.
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash, IsVariant)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
|
#[cfg_attr(feature = "derive-more", derive(IsVariant))]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum KeyCode {
|
pub enum KeyCode {
|
||||||
/// Backspace key (Delete on macOS, Backspace on other platforms).
|
/// Backspace key (Delete on macOS, Backspace on other platforms).
|
||||||
@ -1248,12 +1254,12 @@ pub enum KeyCode {
|
|||||||
/// F key.
|
/// F key.
|
||||||
///
|
///
|
||||||
/// `KeyCode::F(1)` represents F1 key, etc.
|
/// `KeyCode::F(1)` represents F1 key, etc.
|
||||||
#[is_variant(ignore)]
|
#[cfg_attr(feature = "derive-more", is_variant(ignore))]
|
||||||
F(u8),
|
F(u8),
|
||||||
/// A character.
|
/// A character.
|
||||||
///
|
///
|
||||||
/// `KeyCode::Char('c')` represents `c` character, etc.
|
/// `KeyCode::Char('c')` represents `c` character, etc.
|
||||||
#[is_variant(ignore)]
|
#[cfg_attr(feature = "derive-more", is_variant(ignore))]
|
||||||
Char(char),
|
Char(char),
|
||||||
/// Null.
|
/// Null.
|
||||||
Null,
|
Null,
|
||||||
@ -1306,7 +1312,7 @@ pub enum KeyCode {
|
|||||||
/// **Note:** these keys can only be read if
|
/// **Note:** these keys can only be read if
|
||||||
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
|
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
|
||||||
/// [`PushKeyboardEnhancementFlags`].
|
/// [`PushKeyboardEnhancementFlags`].
|
||||||
#[is_variant(ignore)]
|
#[cfg_attr(feature = "derive-more", is_variant(ignore))]
|
||||||
Media(MediaKeyCode),
|
Media(MediaKeyCode),
|
||||||
/// A modifier key.
|
/// A modifier key.
|
||||||
///
|
///
|
||||||
@ -1314,7 +1320,7 @@ pub enum KeyCode {
|
|||||||
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] and
|
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] and
|
||||||
/// [`KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES`] have been enabled with
|
/// [`KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES`] have been enabled with
|
||||||
/// [`PushKeyboardEnhancementFlags`].
|
/// [`PushKeyboardEnhancementFlags`].
|
||||||
#[is_variant(ignore)]
|
#[cfg_attr(feature = "derive-more", is_variant(ignore))]
|
||||||
Modifier(ModifierKeyCode),
|
Modifier(ModifierKeyCode),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1632,6 +1638,7 @@ mod tests {
|
|||||||
modifiers: KeyModifiers::empty(),
|
modifiers: KeyModifiers::empty(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "derive-more")]
|
||||||
#[test]
|
#[test]
|
||||||
fn event_is() {
|
fn event_is() {
|
||||||
let event = Event::FocusGained;
|
let event = Event::FocusGained;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user