mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41: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 {
|
pub fn read_until_da1() -> String {
|
||||||
let h = tokio::spawn(Self::error_to_user());
|
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'
|
b == b'c'
|
||||||
&& buf.contains(&0x1b)
|
&& buf.contains(&0x1b)
|
||||||
&& buf.rsplitn(2, |&b| b == 0x1b).next().is_some_and(|s| s.starts_with(b"[?"))
|
&& 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() {
|
async fn error_to_user() {
|
||||||
use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttributes, SetForegroundColor};
|
use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttributes, SetForegroundColor};
|
||||||
|
|
||||||
sleep(Duration::from_millis(200)).await;
|
sleep(Duration::from_millis(400)).await;
|
||||||
_ = crossterm::execute!(
|
_ = crossterm::execute!(
|
||||||
std::io::stderr(),
|
std::io::stderr(),
|
||||||
SetForegroundColor(Color::Red),
|
SetForegroundColor(Color::Red),
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,11 @@
|
||||||
use std::{io::{Error, ErrorKind}, ops::Deref, time::{Duration, Instant}};
|
use std::{io::{Error, ErrorKind}, ops::Deref, time::{Duration, Instant}};
|
||||||
|
|
||||||
pub struct AsyncStdin {
|
pub struct AsyncStdin {
|
||||||
fd: Fd,
|
fd: Fd,
|
||||||
#[cfg(unix)]
|
|
||||||
fds: libc::fd_set,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AsyncStdin {
|
impl Default for AsyncStdin {
|
||||||
fn default() -> Self {
|
fn default() -> Self { Self { fd: Fd::new().expect("failed to open stdin") } }
|
||||||
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 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncStdin {
|
impl AsyncStdin {
|
||||||
|
|
@ -63,16 +49,16 @@ impl AsyncStdin {
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = unsafe {
|
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 {
|
match result {
|
||||||
-1 => Err(Error::last_os_error()),
|
-1 => Err(Error::last_os_error()),
|
||||||
0 => Ok(false),
|
0 => Ok(false),
|
||||||
_ => {
|
_ => Ok(true),
|
||||||
self.reset();
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,13 +70,6 @@ impl AsyncStdin {
|
||||||
_ => Ok(b),
|
_ => Ok(b),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
libc::FD_ZERO(&mut self.fds);
|
|
||||||
libc::FD_SET(*self.fd, &mut self.fds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Windows
|
// --- Windows
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue