diff --git a/yazi-adapter/src/emulator.rs b/yazi-adapter/src/emulator.rs index 57906ba9..9939eda9 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-adapter/src/emulator.rs @@ -107,7 +107,7 @@ impl Emulator { pub fn read_until_da1() -> String { let h = tokio::spawn(Self::error_to_user()); - let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(300), |b, buf| { + let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(500), |b, buf| { b == b'c' && buf.contains(&0x1b) && buf.rsplitn(2, |&b| b == 0x1b).next().is_some_and(|s| s.starts_with(b"[?")) @@ -137,7 +137,7 @@ impl Emulator { async fn error_to_user() { use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttributes, SetForegroundColor}; - sleep(Duration::from_millis(200)).await; + sleep(Duration::from_millis(400)).await; _ = crossterm::execute!( std::io::stderr(), SetForegroundColor(Color::Red), diff --git a/yazi-adapter/src/stdin.rs b/yazi-adapter/src/stdin.rs index f8fd2031..8cf9ca95 100644 --- a/yazi-adapter/src/stdin.rs +++ b/yazi-adapter/src/stdin.rs @@ -1,25 +1,11 @@ use std::{io::{Error, ErrorKind}, ops::Deref, time::{Duration, Instant}}; pub struct AsyncStdin { - fd: Fd, - #[cfg(unix)] - fds: libc::fd_set, + fd: Fd, } impl Default for AsyncStdin { - fn default() -> Self { - let fd = Fd::new().expect("failed to open stdin"); - #[cfg(unix)] - { - let mut me = Self { fd, fds: unsafe { std::mem::MaybeUninit::zeroed().assume_init() } }; - me.reset(); - me - } - #[cfg(windows)] - { - Self { fd } - } - } + fn default() -> Self { Self { fd: Fd::new().expect("failed to open stdin") } } } impl AsyncStdin { @@ -63,16 +49,16 @@ impl AsyncStdin { }; let result = unsafe { - libc::select(*self.fd + 1, &mut self.fds, std::ptr::null_mut(), std::ptr::null_mut(), &mut tv) + let mut set: libc::fd_set = std::mem::zeroed(); + libc::FD_ZERO(&mut set); + libc::FD_SET(*self.fd, &mut set); + libc::select(*self.fd + 1, &mut set, std::ptr::null_mut(), std::ptr::null_mut(), &mut tv) }; match result { -1 => Err(Error::last_os_error()), 0 => Ok(false), - _ => { - self.reset(); - Ok(true) - } + _ => Ok(true), } } @@ -84,13 +70,6 @@ impl AsyncStdin { _ => Ok(b), } } - - fn reset(&mut self) { - unsafe { - libc::FD_ZERO(&mut self.fds); - libc::FD_SET(*self.fd, &mut self.fds); - } - } } // --- Windows