mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: STDIN_FILENO poll always returns 0 under SSH (#2427)
This commit is contained in:
parent
541d849157
commit
94ff413e23
2 changed files with 9 additions and 30 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue