Upgrade to bitflags 2 (#777)
This commit is contained in:
parent
a2c9350ff2
commit
b2cbd94853
@ -27,16 +27,18 @@ all-features = true
|
|||||||
#
|
#
|
||||||
[features]
|
[features]
|
||||||
default = ["bracketed-paste", "windows", "events"]
|
default = ["bracketed-paste", "windows", "events"]
|
||||||
windows = ["winapi", "crossterm_winapi"]
|
windows = ["dep:winapi", "dep:crossterm_winapi"]
|
||||||
bracketed-paste = []
|
bracketed-paste = []
|
||||||
event-stream = ["futures-core", "events"]
|
event-stream = ["futures-core", "events"]
|
||||||
use-dev-tty = ["filedescriptor"]
|
use-dev-tty = ["filedescriptor"]
|
||||||
events = ["mio", "signal-hook", "signal-hook-mio"]
|
events = ["dep:mio", "dep:signal-hook", "dep:signal-hook-mio"]
|
||||||
|
serde = ["dep:serde", "bitflags/serde"]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Shared dependencies
|
# Shared dependencies
|
||||||
#
|
#
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.3"
|
bitflags = {version = "2.1" }
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
|
|
||||||
# optional deps only added when requested
|
# optional deps only added when requested
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#![allow(clippy::cognitive_complexity)]
|
#![allow(clippy::cognitive_complexity)]
|
||||||
|
|
||||||
use crate::Result;
|
|
||||||
use crossterm::{cursor, queue, style};
|
use crossterm::{cursor, queue, style};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
|
30
src/event.rs
30
src/event.rs
@ -101,9 +101,6 @@ use parking_lot::{MappedMutexGuard, Mutex, MutexGuard};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
@ -250,7 +247,8 @@ bitflags! {
|
|||||||
/// See <https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement> for more information.
|
/// See <https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement> for more information.
|
||||||
///
|
///
|
||||||
/// Alternate keys and Unicode codepoints are not yet supported by crossterm.
|
/// Alternate keys and Unicode codepoints are not yet supported by crossterm.
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(transparent))]
|
||||||
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub struct KeyboardEnhancementFlags: u8 {
|
pub struct KeyboardEnhancementFlags: u8 {
|
||||||
/// Represent Escape and modified keys using CSI-u sequences, so they can be unambiguously
|
/// Represent Escape and modified keys using CSI-u sequences, so they can be unambiguously
|
||||||
/// read.
|
/// read.
|
||||||
@ -504,7 +502,7 @@ impl Command for PopKeyboardEnhancementFlags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents an event.
|
/// Represents an event.
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[cfg_attr(not(feature = "bracketed-paste"), derive(Copy))]
|
#[cfg_attr(not(feature = "bracketed-paste"), derive(Copy))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Hash)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Hash)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
@ -540,7 +538,7 @@ pub enum Event {
|
|||||||
/// Some platforms/terminals does not report all key modifiers
|
/// Some platforms/terminals does not report all key modifiers
|
||||||
/// combinations for all mouse event types. For example - macOS reports
|
/// combinations for all mouse event types. For example - macOS reports
|
||||||
/// `Ctrl` + left mouse button click as a right mouse button click.
|
/// `Ctrl` + left mouse button click as a right mouse button click.
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub struct MouseEvent {
|
pub struct MouseEvent {
|
||||||
/// The kind of mouse event that was caused.
|
/// The kind of mouse event that was caused.
|
||||||
@ -562,7 +560,7 @@ pub struct MouseEvent {
|
|||||||
/// Some platforms/terminals do not report mouse button for the
|
/// Some platforms/terminals do not report mouse button for the
|
||||||
/// `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(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
#[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.
|
||||||
@ -580,7 +578,7 @@ pub enum MouseEventKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a mouse button.
|
/// Represents a mouse button.
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub enum MouseButton {
|
pub enum MouseButton {
|
||||||
/// Left mouse button.
|
/// Left mouse button.
|
||||||
@ -597,7 +595,8 @@ bitflags! {
|
|||||||
/// **Note:** `SUPER`, `HYPER`, and `META` can only be read if
|
/// **Note:** `SUPER`, `HYPER`, and `META` can only be read if
|
||||||
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
|
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
|
||||||
/// [`PushKeyboardEnhancementFlags`].
|
/// [`PushKeyboardEnhancementFlags`].
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(transparent))]
|
||||||
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub struct KeyModifiers: u8 {
|
pub struct KeyModifiers: u8 {
|
||||||
const SHIFT = 0b0000_0001;
|
const SHIFT = 0b0000_0001;
|
||||||
const CONTROL = 0b0000_0010;
|
const CONTROL = 0b0000_0010;
|
||||||
@ -610,7 +609,7 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a keyboard event kind.
|
/// Represents a keyboard event kind.
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
pub enum KeyEventKind {
|
pub enum KeyEventKind {
|
||||||
Press,
|
Press,
|
||||||
@ -624,7 +623,8 @@ bitflags! {
|
|||||||
/// **Note:** This state can only be read if
|
/// **Note:** This state can only be read if
|
||||||
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
|
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
|
||||||
/// [`PushKeyboardEnhancementFlags`].
|
/// [`PushKeyboardEnhancementFlags`].
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(transparent))]
|
||||||
pub struct KeyEventState: u8 {
|
pub struct KeyEventState: u8 {
|
||||||
/// The key event origins from the keypad.
|
/// The key event origins from the keypad.
|
||||||
const KEYPAD = 0b0000_0001;
|
const KEYPAD = 0b0000_0001;
|
||||||
@ -641,7 +641,7 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a key event.
|
/// Represents a key event.
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, PartialOrd, Clone, Copy)]
|
#[derive(Debug, PartialOrd, Clone, Copy)]
|
||||||
pub struct KeyEvent {
|
pub struct KeyEvent {
|
||||||
/// The key itself.
|
/// The key itself.
|
||||||
@ -767,7 +767,7 @@ impl Hash for KeyEvent {
|
|||||||
|
|
||||||
/// Represents a media key (as part of [`KeyCode::Media`]).
|
/// Represents a media key (as part of [`KeyCode::Media`]).
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum MediaKeyCode {
|
pub enum MediaKeyCode {
|
||||||
/// Play media key.
|
/// Play media key.
|
||||||
Play,
|
Play,
|
||||||
@ -799,7 +799,7 @@ pub enum MediaKeyCode {
|
|||||||
|
|
||||||
/// Represents a modifier key (as part of [`KeyCode::Modifier`]).
|
/// Represents a modifier key (as part of [`KeyCode::Modifier`]).
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum ModifierKeyCode {
|
pub enum ModifierKeyCode {
|
||||||
/// Left Shift key.
|
/// Left Shift key.
|
||||||
LeftShift,
|
LeftShift,
|
||||||
@ -833,7 +833,7 @@ pub enum ModifierKeyCode {
|
|||||||
|
|
||||||
/// Represents a key.
|
/// Represents a key.
|
||||||
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum KeyCode {
|
pub enum KeyCode {
|
||||||
/// Backspace key.
|
/// Backspace key.
|
||||||
Backspace,
|
Backspace,
|
||||||
|
Loading…
Reference in New Issue
Block a user