mirror of
https://github.com/crossterm-rs/crossterm.git
synced 2025-09-30 06:21:48 +00:00
x
This commit is contained in:
parent
0852a9bc6e
commit
a90acdbfb7
66
src/event.rs
66
src/event.rs
@ -80,10 +80,6 @@
|
||||
//! Check the [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples) folder for more of
|
||||
//! them (`event-*`).
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::{csi, Command};
|
||||
|
||||
pub(crate) mod filter;
|
||||
pub(crate) mod read;
|
||||
pub(crate) mod source;
|
||||
@ -100,7 +96,9 @@ use crate::event::{
|
||||
read::InternalEventReader,
|
||||
timeout::PollTimeout,
|
||||
};
|
||||
use crate::{csi, Command};
|
||||
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard};
|
||||
use std::fmt;
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
@ -113,7 +111,7 @@ use std::hash::{Hash, Hasher};
|
||||
/// This needs to be static because there can be one event reader.
|
||||
static INTERNAL_EVENT_READER: Mutex<Option<InternalEventReader>> = parking_lot::const_mutex(None);
|
||||
|
||||
pub(super) fn lock_internal_event_reader() -> MappedMutexGuard<'static, InternalEventReader> {
|
||||
pub(crate) fn lock_internal_event_reader() -> MappedMutexGuard<'static, InternalEventReader> {
|
||||
MutexGuard::map(INTERNAL_EVENT_READER.lock(), |reader| {
|
||||
reader.get_or_insert_with(InternalEventReader::default)
|
||||
})
|
||||
@ -245,6 +243,34 @@ where
|
||||
reader.read(filter)
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// Represents special flags that tell compatible terminals to add extra information to keyboard events.
|
||||
///
|
||||
/// 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))]
|
||||
pub struct KeyboardEnhancementFlags: u8 {
|
||||
/// Represent Escape and modified keys using CSI-u sequences, so they can be unambiguously
|
||||
/// read.
|
||||
const DISAMBIGUATE_ESCAPE_CODES = 0b0000_0001;
|
||||
/// Add extra events with [`KeyEvent.kind`] set to [`KeyEventKind::Repeat`] or
|
||||
/// [`KeyEventKind::Release`] when keys are autorepeated or released.
|
||||
const REPORT_EVENT_TYPES = 0b0000_0010;
|
||||
// Send [alternate keycodes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#key-codes)
|
||||
// in addition to the base keycode. The alternate keycode overrides the base keycode in
|
||||
// resulting `KeyEvent`s.
|
||||
const REPORT_ALTERNATE_KEYS = 0b0000_0100;
|
||||
/// Represent all keyboard events as CSI-u sequences. This is required to get repeat/release
|
||||
/// events for plain-text keys.
|
||||
const REPORT_ALL_KEYS_AS_ESCAPE_CODES = 0b0000_1000;
|
||||
// Send the Unicode codepoint as well as the keycode.
|
||||
//
|
||||
// *Note*: this is not yet supported by crossterm.
|
||||
// const REPORT_ASSOCIATED_TEXT = 0b0001_0000;
|
||||
}
|
||||
}
|
||||
|
||||
/// A command that enables mouse event capturing.
|
||||
///
|
||||
/// Mouse events can be captured with [read](./fn.read.html)/[poll](./fn.poll.html).
|
||||
@ -283,11 +309,9 @@ impl Command for EnableMouseCapture {
|
||||
/// A command that disables mouse event capturing.
|
||||
///
|
||||
/// Mouse events can be captured with [read](./fn.read.html)/[poll](./fn.poll.html).
|
||||
#[cfg(feature = "events")]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct DisableMouseCapture;
|
||||
|
||||
#[cfg(feature = "events")]
|
||||
impl Command for DisableMouseCapture {
|
||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||
f.write_str(concat!(
|
||||
@ -389,34 +413,6 @@ impl Command for DisableBracketedPaste {
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// Represents special flags that tell compatible terminals to add extra information to keyboard events.
|
||||
///
|
||||
/// 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))]
|
||||
pub struct KeyboardEnhancementFlags: u8 {
|
||||
/// Represent Escape and modified keys using CSI-u sequences, so they can be unambiguously
|
||||
/// read.
|
||||
const DISAMBIGUATE_ESCAPE_CODES = 0b0000_0001;
|
||||
/// Add extra events with [`KeyEvent.kind`] set to [`KeyEventKind::Repeat`] or
|
||||
/// [`KeyEventKind::Release`] when keys are autorepeated or released.
|
||||
const REPORT_EVENT_TYPES = 0b0000_0010;
|
||||
// Send [alternate keycodes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#key-codes)
|
||||
// in addition to the base keycode. The alternate keycode overrides the base keycode in
|
||||
// resulting `KeyEvent`s.
|
||||
const REPORT_ALTERNATE_KEYS = 0b0000_0100;
|
||||
/// Represent all keyboard events as CSI-u sequences. This is required to get repeat/release
|
||||
/// events for plain-text keys.
|
||||
const REPORT_ALL_KEYS_AS_ESCAPE_CODES = 0b0000_1000;
|
||||
// Send the Unicode codepoint as well as the keycode.
|
||||
//
|
||||
// *Note*: this is not yet supported by crossterm.
|
||||
// const REPORT_ASSOCIATED_TEXT = 0b0001_0000;
|
||||
}
|
||||
}
|
||||
|
||||
/// A command that enables the [kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/), which adds extra information to keyboard events and removes ambiguity for modifier keys.
|
||||
///
|
||||
/// It should be paired with [`PopKeyboardEnhancementFlags`] at the end of execution.
|
||||
|
@ -1,14 +0,0 @@
|
||||
mod api;
|
||||
pub(crate) mod filter;
|
||||
pub(crate) mod read;
|
||||
pub(crate) mod source;
|
||||
#[cfg(feature = "event-stream")]
|
||||
pub(crate) mod stream;
|
||||
pub(crate) mod sys;
|
||||
pub(crate) mod timeout;
|
||||
mod types;
|
||||
|
||||
#[cfg(feature = "event-stream")]
|
||||
pub use stream::EventStream;
|
||||
|
||||
pub use self::{api::*, types::*};
|
@ -11,15 +11,8 @@ use filedescriptor::{poll, pollfd, POLLIN};
|
||||
|
||||
#[cfg(feature = "event-stream")]
|
||||
use crate::event::sys::Waker;
|
||||
|
||||
use crate::event::{
|
||||
source::EventSource,
|
||||
sys::unix::{
|
||||
file_descriptor::{tty_fd, FileDesc},
|
||||
parse::parse_event,
|
||||
},
|
||||
InternalEvent,
|
||||
};
|
||||
use crate::event::{source::EventSource, sys::parse::parse_event, InternalEvent};
|
||||
use crate::terminal::file_descriptor::{tty_fd, FileDesc};
|
||||
|
||||
/// Holds a prototypical Waker and a receiver we can wait on when doing select().
|
||||
#[cfg(feature = "event-stream")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user