Skip to content

Commit fc8f977

Browse files
authored
Document feature flags in lib.rs (#947)
* Autoformat Cargo.toml Uses VSCode Even Better TOML plugin for opinionated formatting * Document feature flags Use the document-features crate to automatically add documentation about the features to the crate documentation at the crate level.
1 parent 56ee252 commit fc8f977

File tree

5 files changed

+37
-60
lines changed

5 files changed

+37
-60
lines changed

Cargo.toml

+32-57
Original file line numberDiff line numberDiff line change
@@ -17,91 +17,66 @@ categories = ["command-line-interface", "command-line-utilities"]
1717
name = "crossterm"
1818
path = "src/lib.rs"
1919

20-
#
21-
# Build documentation with all features -> EventStream is available
22-
#
2320
[package.metadata.docs.rs]
2421
all-features = true
2522

26-
#
27-
# Features
28-
#
2923
[features]
30-
default = ["bracketed-paste", "windows", "events"]
31-
windows = [
32-
"dep:winapi",
33-
"dep:crossterm_winapi",
34-
] # Disables winapi dependencies from being included into the binary (SHOULD NOT be disabled on windows).
35-
bracketed-paste = [
36-
] # Enables triggering a `Event::Paste` when pasting text into the terminal.
37-
event-stream = ["dep:futures-core", "events"] # Enables async events
38-
use-dev-tty = [
39-
"filedescriptor",
40-
"rustix/process",
41-
] # Enables raw file descriptor polling / selecting instead of mio.
42-
events = [
43-
"dep:mio",
44-
"dep:signal-hook",
45-
"dep:signal-hook-mio",
46-
] # Enables reading input/events from the system.
47-
serde = ["dep:serde", "bitflags/serde"] # Enables 'serde' for various types.
48-
49-
#
50-
# Shared dependencies
51-
#
24+
default = ["bracketed-paste", "events", "windows"]
25+
26+
#! ### Default features
27+
## Enables triggering [`Event::Paste`](event::Event::Paste) when pasting text into the terminal.
28+
bracketed-paste = []
29+
30+
## Enables reading input/events from the system using the [`event`] module.
31+
events = ["dep:mio", "dep:signal-hook", "dep:signal-hook-mio"]
32+
33+
## Enables windows specific crates.
34+
windows = ["dep:winapi", "dep:crossterm_winapi"]
35+
36+
#! ### Optional Features
37+
38+
## Enables the [EventStream](event::EventStream) struct for async event reading.
39+
event-stream = ["dep:futures-core", "events"]
40+
41+
## Enables [`serde`] for various types.
42+
serde = ["dep:serde", "bitflags/serde"]
43+
44+
## Enables raw file descriptor polling / selecting instead of mio.
45+
use-dev-tty = ["filedescriptor", "rustix/process"]
46+
5247
[dependencies]
5348
bitflags = { version = "2.3" }
54-
parking_lot = "0.12"
55-
56-
# optional deps only added when requested
49+
document-features = "0.2.10"
5750
futures-core = { version = "0.3", optional = true, default-features = false }
51+
parking_lot = "0.12"
5852
serde = { version = "1.0", features = ["derive"], optional = true }
5953

60-
#
6154
# Windows dependencies
62-
#
63-
[target.'cfg(windows)'.dependencies.winapi]
64-
version = "0.3.9"
65-
features = ["winuser", "winerror"]
66-
optional = true
67-
6855
[target.'cfg(windows)'.dependencies]
6956
crossterm_winapi = { version = "0.9.1", optional = true }
57+
winapi = { version = "0.3.9", optional = true, features = ["winuser", "winerror"] }
7058

71-
#
7259
# UNIX dependencies
73-
#
7460
[target.'cfg(unix)'.dependencies]
61+
filedescriptor = { version = "0.8", optional = true }
7562
# Default to using rustix for UNIX systems, but provide an option to use libc for backwards
7663
# compatibility.
7764
libc = { version = "0.2", default-features = false, optional = true }
78-
rustix = { version = "0.38.34", default-features = false, features = [
79-
"std",
80-
"stdio",
81-
"termios",
82-
] }
83-
signal-hook = { version = "0.3.17", optional = true }
84-
filedescriptor = { version = "0.8", optional = true }
8565
mio = { version = "1.0", features = ["os-poll"], optional = true }
86-
signal-hook-mio = { version = "0.2.4", features = [
87-
"support-v1_0",
88-
], optional = true }
66+
rustix = { version = "0.38.34", default-features = false, features = ["std", "stdio", "termios"] }
67+
signal-hook = { version = "0.3.17", optional = true }
68+
signal-hook-mio = { version = "0.2.4", features = ["support-v1_0"], optional = true }
8969

90-
#
91-
# Dev dependencies (examples, ...)
92-
#
9370
[dev-dependencies]
94-
tokio = { version = "1.25", features = ["full"] }
71+
async-std = "1.12"
9572
futures = "0.3"
9673
futures-timer = "3.0"
97-
async-std = "1.12"
9874
serde_json = "1.0"
9975
serial_test = "2.0.0"
10076
temp-env = "0.3.6"
77+
tokio = { version = "1.25", features = ["full"] }
10178

102-
#
10379
# Examples
104-
#
10580
[[example]]
10681
name = "event-read"
10782
required-features = ["bracketed-paste", "events"]

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@
223223
//! Ok(())
224224
//! }
225225
//!```
226+
//! ## Feature Flags
227+
#![doc = document_features::document_features!()]
226228
//!
227229
//! [write]: https://doc.rust-lang.org/std/io/trait.Write.html
228230
//! [stdout]: https://doc.rust-lang.org/std/io/fn.stdout.html

src/style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub fn available_color_count() -> u16 {
184184
///
185185
/// # Notes
186186
///
187-
/// crossterm supports NO_COLOR (https://no-color.org/) to disabled colored output.
187+
/// crossterm supports NO_COLOR (<https://no-color.org/>) to disabled colored output.
188188
///
189189
/// This API allows applications to override that behavior and force colorized output
190190
/// even if NO_COLOR is set.

src/style/types/colored.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Colored {
7171
}
7272

7373
/// Checks whether ansi color sequences are disabled by setting of NO_COLOR
74-
/// in environment as per https://no-color.org/
74+
/// in environment as per <https://no-color.org/>
7575
pub fn ansi_color_disabled() -> bool {
7676
!std::env::var("NO_COLOR")
7777
.unwrap_or("".to_string())

src/terminal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub struct WindowSize {
148148
/// Returns the terminal size `[WindowSize]`.
149149
///
150150
/// The width and height in pixels may not be reliably implemented or default to 0.
151-
/// For unix, https://man7.org/linux/man-pages/man4/tty_ioctl.4.html documents them as "unused".
151+
/// For unix, <https://man7.org/linux/man-pages/man4/tty_ioctl.4.html> documents them as "unused".
152152
/// For windows it is not implemented.
153153
pub fn window_size() -> io::Result<WindowSize> {
154154
sys::window_size()

0 commit comments

Comments
 (0)