Skip to content

Commit

Permalink
Upgrade to bitflags 2 (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimonPost committed Apr 8, 2023
1 parent a2c9350 commit b2cbd94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Expand Up @@ -27,16 +27,18 @@ all-features = true
#
[features]
default = ["bracketed-paste", "windows", "events"]
windows = ["winapi", "crossterm_winapi"]
windows = ["dep:winapi", "dep:crossterm_winapi"]
bracketed-paste = []
event-stream = ["futures-core", "events"]
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
#
[dependencies]
bitflags = "1.3"
bitflags = {version = "2.1" }
parking_lot = "0.12"

# optional deps only added when requested
Expand Down
1 change: 0 additions & 1 deletion examples/interactive-demo/src/test/attribute.rs
@@ -1,6 +1,5 @@
#![allow(clippy::cognitive_complexity)]

use crate::Result;
use crossterm::{cursor, queue, style};
use std::io::Write;

Expand Down
30 changes: 15 additions & 15 deletions src/event.rs
Expand Up @@ -101,9 +101,6 @@ use parking_lot::{MappedMutexGuard, Mutex, MutexGuard};
use std::fmt;
use std::time::Duration;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use bitflags::bitflags;
use std::hash::{Hash, Hasher};

Expand Down Expand Up @@ -250,7 +247,8 @@ bitflags! {
/// See <https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement> for more information.
///
/// 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 {
/// Represent Escape and modified keys using CSI-u sequences, so they can be unambiguously
/// read.
Expand Down Expand Up @@ -504,7 +502,7 @@ impl Command for PopKeyboardEnhancementFlags {
}

/// 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))]
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Hash)]
pub enum Event {
Expand Down Expand Up @@ -540,7 +538,7 @@ pub enum Event {
/// Some platforms/terminals does not report all key modifiers
/// combinations for all mouse event types. For example - macOS reports
/// `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)]
pub struct MouseEvent {
/// The kind of mouse event that was caused.
Expand All @@ -562,7 +560,7 @@ pub struct MouseEvent {
/// Some platforms/terminals do not report mouse button for the
/// `MouseEventKind::Up` and `MouseEventKind::Drag` events. `MouseButton::Left`
/// 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)]
pub enum MouseEventKind {
/// Pressed mouse button. Contains the button that was pressed.
Expand All @@ -580,7 +578,7 @@ pub enum MouseEventKind {
}

/// 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)]
pub enum MouseButton {
/// Left mouse button.
Expand All @@ -597,7 +595,8 @@ bitflags! {
/// **Note:** `SUPER`, `HYPER`, and `META` can only be read if
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
/// [`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 {
const SHIFT = 0b0000_0001;
const CONTROL = 0b0000_0010;
Expand All @@ -610,7 +609,7 @@ bitflags! {
}

/// 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)]
pub enum KeyEventKind {
Press,
Expand All @@ -624,7 +623,8 @@ bitflags! {
/// **Note:** This state can only be read if
/// [`KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES`] has been enabled with
/// [`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 {
/// The key event origins from the keypad.
const KEYPAD = 0b0000_0001;
Expand All @@ -641,7 +641,7 @@ bitflags! {
}

/// 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)]
pub struct KeyEvent {
/// The key itself.
Expand Down Expand Up @@ -767,7 +767,7 @@ impl Hash for KeyEvent {

/// Represents a media key (as part of [`KeyCode::Media`]).
#[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 {
/// Play media key.
Play,
Expand Down Expand Up @@ -799,7 +799,7 @@ pub enum MediaKeyCode {

/// Represents a modifier key (as part of [`KeyCode::Modifier`]).
#[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 {
/// Left Shift key.
LeftShift,
Expand Down Expand Up @@ -833,7 +833,7 @@ pub enum ModifierKeyCode {

/// Represents a key.
#[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 {
/// Backspace key.
Backspace,
Expand Down

0 comments on commit b2cbd94

Please sign in to comment.