diff --git a/Cargo.toml b/Cargo.toml index 27d6448e..fdd1778e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "crossterm" -version = "0.28.1" +version = "0.28.2" authors = ["T. Post"] description = "A crossplatform terminal library for manipulating terminals." repository = "https://github.com/crossterm-rs/crossterm" diff --git a/src/event.rs b/src/event.rs index 4d28dc15..dd027565 100644 --- a/src/event.rs +++ b/src/event.rs @@ -245,13 +245,31 @@ pub fn poll(timeout: Duration) -> std::io::Result { /// } /// ``` pub fn read() -> std::io::Result { - match read_internal(&EventFilter)? { + // #[cfg(target_os = "macos")] + #[cfg(unix)] + let _ = set_nonblocking(true); + + let readed_event = read_internal(&EventFilter)?; + + // #[cfg(target_os = "macos")] + #[cfg(unix)] + let _ = set_nonblocking(false); + + match readed_event { InternalEvent::Event(event) => Ok(event), #[cfg(unix)] _ => unreachable!(), } } +fn set_nonblocking(is_nonblock: bool) { + use rustix::fd::AsRawFd; + let stdin_fd = std::io::stdin().as_raw_fd(); + let fd = unsafe { rustix::fd::BorrowedFd::borrow_raw(stdin_fd) }; + + let _ = rustix::io::ioctl_fionbio(fd, is_nonblock); +} + /// Polls to check if there are any `InternalEvent`s that can be read within the given duration. pub(crate) fn poll_internal(timeout: Option, filter: &F) -> std::io::Result where