From fce58c879a748f3159216f68833100aa16141ab0 Mon Sep 17 00:00:00 2001 From: Josh McKinney <joshka@users.noreply.github.com> Date: Sun, 5 May 2024 09:47:20 -0700 Subject: [PATCH] fix: broken build issues (#888) Co-authored-by: gwenn <gtreguier@gmail.com> --- .github/workflows/crossterm_test.yml | 4 ++++ Cargo.toml | 28 +++++++++++++++++++++------ src/cursor/sys.rs | 1 + src/event.rs | 3 +-- src/event/source/unix/mio.rs | 29 ++++++++++++---------------- src/event/source/unix/tty.rs | 2 +- src/style/attributes.rs | 9 ++++++--- src/style/types/color.rs | 8 ++------ 8 files changed, 49 insertions(+), 35 deletions(-) diff --git a/.github/workflows/crossterm_test.yml b/.github/workflows/crossterm_test.yml index c5cbe95c..31123080 100644 --- a/.github/workflows/crossterm_test.yml +++ b/.github/workflows/crossterm_test.yml @@ -66,6 +66,10 @@ jobs: if: matrix.os != 'windows-2019' run: cargo test --no-default-features -- --nocapture --test-threads 1 continue-on-error: ${{ matrix.can-fail }} + - name: Test no default features with use-dev-tty feature enabled + if: matrix.os != 'windows-2019' + run: cargo test --no-default-features --features "use-dev-tty events" -- --nocapture --test-threads 1 + 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 diff --git a/Cargo.toml b/Cargo.toml index 32006e52..2c53c14b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,18 +28,28 @@ all-features = true # [features] default = ["bracketed-paste", "windows", "events"] -windows = ["dep:winapi", "dep:crossterm_winapi"] # Disables winapi dependencies from being included into the binary (SHOULD NOT be disabled on windows). -bracketed-paste = [] # Enables triggering a `Event::Paste` when pasting text into the terminal. +windows = [ + "dep:winapi", + "dep:crossterm_winapi", +] # Disables winapi dependencies from being included into the binary (SHOULD NOT be disabled on windows). +bracketed-paste = [ +] # Enables triggering a `Event::Paste` when pasting text into the terminal. event-stream = ["dep:futures-core", "events"] # Enables async events -use-dev-tty = ["filedescriptor"] # Enables raw file descriptor polling / selecting instead of mio. -events = ["dep:mio", "dep:signal-hook", "dep:signal-hook-mio"] # Enables reading input/events from the system. +use-dev-tty = [ + "filedescriptor", +] # Enables raw file descriptor polling / selecting instead of mio. +events = [ + "dep:mio", + "dep:signal-hook", + "dep:signal-hook-mio", +] # Enables reading input/events from the system. serde = ["dep:serde", "bitflags/serde"] # Enables 'serde' for various types. # # Shared dependencies # [dependencies] -bitflags = {version = "2.3" } +bitflags = { version = "2.3" } parking_lot = "0.12" # optional deps only added when requested @@ -65,7 +75,9 @@ libc = "0.2" signal-hook = { version = "0.3.17", optional = true } filedescriptor = { version = "0.8", optional = true } mio = { version = "0.8", features = ["os-poll"], optional = true } -signal-hook-mio = { version = "0.2.3", features = ["support-v0_8"], optional = true } +signal-hook-mio = { version = "0.2.3", features = [ + "support-v0_8", +], optional = true } # # Dev dependencies (examples, ...) @@ -108,3 +120,7 @@ required-features = ["events"] [[example]] name = "stderr" required-features = ["events"] + +[[example]] +name = "key-display" +required-features = ["events"] diff --git a/src/cursor/sys.rs b/src/cursor/sys.rs index f85a95c6..1623740a 100644 --- a/src/cursor/sys.rs +++ b/src/cursor/sys.rs @@ -4,6 +4,7 @@ #[cfg(feature = "events")] pub use self::unix::position; #[cfg(windows)] +#[cfg(feature = "events")] pub use self::windows::position; #[cfg(windows)] pub(crate) use self::windows::{ diff --git a/src/event.rs b/src/event.rs index b3bf86a5..2a620e12 100644 --- a/src/event.rs +++ b/src/event.rs @@ -910,7 +910,7 @@ impl Display for ModifierKeyCode { /// /// # Platform-specific Notes /// - /// On macOS, the control, alt, and super keys is displayed as "Control", "Option", and + /// On macOS, the control, alt, and super keys are displayed as "Control", "Option", and /// "Command" respectively. See /// <https://support.apple.com/guide/applestyleguide/welcome/1.0/web>. /// @@ -920,7 +920,6 @@ impl Display for ModifierKeyCode { /// /// On other platforms, the super key is referred to as "Super". fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - #[cfg(target_os = "macos")] match self { ModifierKeyCode::LeftShift => write!(f, "Left Shift"), ModifierKeyCode::LeftHyper => write!(f, "Left Hyper"), diff --git a/src/event/source/unix/mio.rs b/src/event/source/unix/mio.rs index f9d595af..8372a1dd 100644 --- a/src/event/source/unix/mio.rs +++ b/src/event/source/unix/mio.rs @@ -120,23 +120,18 @@ impl EventSource for UnixInternalEventSource { } } SIGNAL_TOKEN => { - for signal in self.signals.pending() { - match signal { - signal_hook::consts::SIGWINCH => { - // TODO Should we remove tput? - // - // This can take a really long time, because terminal::size can - // launch new process (tput) and then it parses its output. It's - // not a really long time from the absolute time point of view, but - // it's a really long time from the mio, async-std/tokio executor, ... - // point of view. - let new_size = crate::terminal::size()?; - return Ok(Some(InternalEvent::Event(Event::Resize( - new_size.0, new_size.1, - )))); - } - _ => unreachable!("Synchronize signal registration & handling"), - }; + if self.signals.pending().next() == Some(signal_hook::consts::SIGWINCH) { + // TODO Should we remove tput? + // + // This can take a really long time, because terminal::size can + // launch new process (tput) and then it parses its output. It's + // not a really long time from the absolute time point of view, but + // it's a really long time from the mio, async-std/tokio executor, ... + // point of view. + let new_size = crate::terminal::size()?; + return Ok(Some(InternalEvent::Event(Event::Resize( + new_size.0, new_size.1, + )))); } } #[cfg(feature = "event-stream")] diff --git a/src/event/source/unix/tty.rs b/src/event/source/unix/tty.rs index 320a12ca..b8cbfeff 100644 --- a/src/event/source/unix/tty.rs +++ b/src/event/source/unix/tty.rs @@ -80,7 +80,7 @@ impl UnixInternalEventSource { /// only fills the given buffer and does not read beyond that. fn read_complete(fd: &FileDesc, buf: &mut [u8]) -> io::Result<usize> { loop { - match fd.read(buf, buf.len()) { + match fd.read(buf) { Ok(x) => return Ok(x), Err(e) => match e.kind() { io::ErrorKind::WouldBlock => return Ok(0), diff --git a/src/style/attributes.rs b/src/style/attributes.rs index aa481c3a..83dea3ed 100644 --- a/src/style/attributes.rs +++ b/src/style/attributes.rs @@ -140,8 +140,11 @@ mod tests { #[test] fn test_attributes_const() { - const ATTRIBUTES: Attributes = Attributes::none().with(Attribute::Bold).with(Attribute::Italic).without(Attribute::Bold); - assert!(!ATTRIBUTES.has(Attribute::Bold)); - assert!(ATTRIBUTES.has(Attribute::Italic)); + const ATTRIBUTES: Attributes = Attributes::none() + .with(Attribute::Bold) + .with(Attribute::Italic) + .without(Attribute::Bold); + assert!(!ATTRIBUTES.has(Attribute::Bold)); + assert!(ATTRIBUTES.has(Attribute::Italic)); } } diff --git a/src/style/types/color.rs b/src/style/types/color.rs index 026dc7ef..d4d52844 100644 --- a/src/style/types/color.rs +++ b/src/style/types/color.rs @@ -246,15 +246,11 @@ impl serde::ser::Serialize for Color { if str.is_empty() { match *self { - Color::AnsiValue(value) => { - serializer.serialize_str(&format!("ansi_({})", value)) - } + Color::AnsiValue(value) => serializer.serialize_str(&format!("ansi_({})", value)), Color::Rgb { r, g, b } => { serializer.serialize_str(&format!("rgb_({},{},{})", r, g, b)) } - _ => { - Err(serde::ser::Error::custom("Could not serialize enum type")) - } + _ => Err(serde::ser::Error::custom("Could not serialize enum type")), } } else { serializer.serialize_str(str)