From f5d48d8b94b97bfbee8f7c50df57bf71cdea1abc Mon Sep 17 00:00:00 2001 From: Austin Schey Date: Sat, 14 Dec 2024 16:57:06 -0800 Subject: [PATCH] fix: fix build failure with event-stream, rustix, and use-dev-tty --- .github/workflows/crossterm_test.yml | 2 +- src/event/source/unix/tty.rs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/crossterm_test.yml b/.github/workflows/crossterm_test.yml index 9088af51..bde4d37b 100644 --- a/.github/workflows/crossterm_test.yml +++ b/.github/workflows/crossterm_test.yml @@ -68,7 +68,7 @@ jobs: 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 bracketed-paste" -- --nocapture --test-threads 1 + run: cargo test --no-default-features --features "use-dev-tty events event-stream bracketed-paste" -- --nocapture --test-threads 1 continue-on-error: ${{ matrix.can-fail }} - name: Test no default features with windows feature enabled if: matrix.os == 'windows-2019' diff --git a/src/event/source/unix/tty.rs b/src/event/source/unix/tty.rs index 03d76b40..ea62f7aa 100644 --- a/src/event/source/unix/tty.rs +++ b/src/event/source/unix/tty.rs @@ -78,6 +78,14 @@ impl UnixInternalEventSource { wake_pipe: WakePipe::new()?, }) } + + #[cfg(feature = "event-stream")] + fn receiver_fd(&self) -> FileDesc { + #[cfg(feature = "libc")] + return FileDesc::new(self.wake_pipe.receiver.as_raw_fd(), false); + #[cfg(not(feature = "libc"))] + return FileDesc::Borrowed(self.wake_pipe.receiver.as_fd()); + } } /// read_complete reads from a non-blocking file descriptor @@ -164,10 +172,7 @@ impl EventSource for UnixInternalEventSource { } } if fds[1].revents & POLLIN != 0 { - #[cfg(feature = "libc")] - let fd = FileDesc::new(self.winch_signal_receiver.as_raw_fd(), false); - #[cfg(not(feature = "libc"))] - let fd = FileDesc::Borrowed(self.winch_signal_receiver.as_fd()); + let fd = self.receiver_fd(); // drain the pipe while read_complete(&fd, &mut [0; 1024])? != 0 {} // TODO Should we remove tput? @@ -185,7 +190,7 @@ impl EventSource for UnixInternalEventSource { #[cfg(feature = "event-stream")] if fds[2].revents & POLLIN != 0 { - let fd = FileDesc::new(self.wake_pipe.receiver.as_raw_fd(), false); + let fd = self.receiver_fd(); // drain the pipe while read_complete(&fd, &mut [0; 1024])? != 0 {}