Skip to content

Commit

Permalink
Make the events module an optional feature (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimonPost committed Apr 7, 2023
1 parent b354b4c commit 03c2517
Show file tree
Hide file tree
Showing 21 changed files with 234 additions and 195 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/crossterm_test.yml
Expand Up @@ -57,7 +57,7 @@ jobs:
run: cargo test --lib --features serde -- --nocapture --test-threads 1
continue-on-error: ${{ matrix.can-fail }}
- name: Test event-stream feature
run: cargo test --lib --features event-stream -- --nocapture --test-threads 1
run: cargo test --lib --features "event-stream,events" -- --nocapture --test-threads 1
continue-on-error: ${{ matrix.can-fail }}
- name: Test all features
run: cargo test --all-features -- --nocapture --test-threads 1
Expand All @@ -68,7 +68,7 @@ jobs:
continue-on-error: ${{ matrix.can-fail }}
- name: Test no default features with windows feature enabled
if: matrix.os == 'windows-2019'
run: cargo test --no-default-features --features windows -- --nocapture --test-threads 1
run: cargo test --no-default-features --features "windows" -- --nocapture --test-threads 1
- name: Test Packaging
if: matrix.rust == 'stable'
run: cargo package
Expand Down
34 changes: 25 additions & 9 deletions Cargo.toml
Expand Up @@ -26,12 +26,12 @@ all-features = true
# Features
#
[features]
default = ["bracketed-paste", "windows"]
default = ["bracketed-paste", "windows", "events"]
windows = ["winapi", "crossterm_winapi"]
bracketed-paste = []
event-stream = ["futures-core"]
event-stream = ["futures-core", "events"]
use-dev-tty = ["filedescriptor"]

events = ["mio", "signal-hook", "signal-hook-mio"]
#
# Shared dependencies
#
Expand Down Expand Up @@ -59,10 +59,10 @@ crossterm_winapi = { version = "0.9", optional = true }
#
[target.'cfg(unix)'.dependencies]
libc = "0.2"
signal-hook = { version = "0.3.13" }
signal-hook = { version = "0.3.13", optional = true }
filedescriptor = { version = "0.8", optional = true }
mio = { version = "0.8", features = ["os-poll"] }
signal-hook-mio = { version = "0.2.3", features = ["support-v0_8"] }
mio = { version = "0.8", features = ["os-poll"], optional = true }
signal-hook-mio = { version = "0.2.3", features = ["support-v0_8"], optional = true }

#
# Dev dependencies (examples, ...)
Expand All @@ -79,12 +79,28 @@ serde_json = "1.0"
#
[[example]]
name = "event-read"
required-features = ["bracketed-paste"]
required-features = ["bracketed-paste", "events"]

[[example]]
name = "event-match-modifiers"
required-features = ["bracketed-paste", "events"]

[[example]]
name = "event-poll-read"
required-features = ["bracketed-paste", "events"]

[[example]]
name = "event-stream-async-std"
required-features = ["event-stream"]
required-features = ["event-stream", "events"]

[[example]]
name = "event-stream-tokio"
required-features = ["event-stream"]
required-features = ["event-stream", "events"]

[[example]]
name = "event-read-char-line"
required-features = ["events"]

[[example]]
name = "stderr"
required-features = ["events"]
12 changes: 9 additions & 3 deletions README.md
Expand Up @@ -144,16 +144,22 @@ features = ["event-stream"]
|:---------------|:---------------------------------------------|
| `event-stream` | `futures::Stream` producing `Result<Event>`. |
| `serde` | (De)serializing of events. |
| `events` | Reading input/system events (enabled by default) |
| `filedescriptor` | Use raw filedescriptor for all events rather then mio dependency |


To use crossterm as a very tin layer you can disable the `events` feature or use `filedescriptor` feature.
This can disable `mio` / `signal-hook` / `signal-hook-mio` dependencies.

### Dependency Justification

| Dependency | Used for | Included |
|:---------------|:---------------------------------------------------------------------------------|:--------------------------------------|
| `bitflags` | `KeyModifiers`, those are differ based on input. | always |
| `parking_lot` | locking `RwLock`s with a timeout, const mutexes. | always |
| `libc` | UNIX terminal_size/raw modes/set_title and several other low level functionality. | UNIX only |
| `Mio` | event readiness polling, waking up poller | UNIX only |
| `signal-hook` | signal-hook is used to handle terminal resize SIGNAL with Mio. | UNIX only |
| `libc` | UNIX terminal_size/raw modes/set_title and several other low level functionality. | optional (`events` feature), UNIX only |
| `Mio` | event readiness polling, waking up poller | optional (`events` feature), UNIX only |
| `signal-hook` | signal-hook is used to handle terminal resize SIGNAL with Mio. | optional (`events` feature),UNIX 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 |
| `serde` | ***ser***ializing and ***de***serializing of events | only with `serde` feature flag |
Expand Down
8 changes: 5 additions & 3 deletions src/cursor.rs
Expand Up @@ -48,10 +48,11 @@ use std::fmt;
use crate::Result;
use crate::{csi, impl_display, Command};

pub use sys::position;

pub(crate) mod sys;

#[cfg(feature = "events")]
pub use sys::position;

/// A command that moves the terminal cursor to the given position (column, row).
///
/// # Notes
Expand Down Expand Up @@ -426,13 +427,14 @@ impl_display!(for DisableBlinking);
impl_display!(for SetCursorStyle);

#[cfg(test)]
#[cfg(feature = "events")]
mod tests {
use std::io::{self, stdout};

use crate::execute;

use super::{
position, MoveDown, MoveLeft, MoveRight, MoveTo, MoveUp, RestorePosition, SavePosition,
sys::position, MoveDown, MoveLeft, MoveRight, MoveTo, MoveUp, RestorePosition, SavePosition,
};

// Test is disabled, because it's failing on Travis
Expand Down
2 changes: 2 additions & 0 deletions src/cursor/sys.rs
@@ -1,6 +1,7 @@
//! This module provides platform related functions.

#[cfg(unix)]
#[cfg(feature = "events")]
pub use self::unix::position;
#[cfg(windows)]
pub use self::windows::position;
Expand All @@ -14,4 +15,5 @@ pub(crate) use self::windows::{
pub(crate) mod windows;

#[cfg(unix)]
#[cfg(feature = "events")]
pub(crate) mod unix;

0 comments on commit 03c2517

Please sign in to comment.