Skip to content

Commit 94ff413

Browse files
authored
fix: STDIN_FILENO poll always returns 0 under SSH (#2427)
1 parent 541d849 commit 94ff413

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

yazi-adapter/src/emulator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Emulator {
107107

108108
pub fn read_until_da1() -> String {
109109
let h = tokio::spawn(Self::error_to_user());
110-
let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(300), |b, buf| {
110+
let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(500), |b, buf| {
111111
b == b'c'
112112
&& buf.contains(&0x1b)
113113
&& buf.rsplitn(2, |&b| b == 0x1b).next().is_some_and(|s| s.starts_with(b"[?"))
@@ -137,7 +137,7 @@ impl Emulator {
137137
async fn error_to_user() {
138138
use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttributes, SetForegroundColor};
139139

140-
sleep(Duration::from_millis(200)).await;
140+
sleep(Duration::from_millis(400)).await;
141141
_ = crossterm::execute!(
142142
std::io::stderr(),
143143
SetForegroundColor(Color::Red),

yazi-adapter/src/stdin.rs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
use std::{io::{Error, ErrorKind}, ops::Deref, time::{Duration, Instant}};
22

33
pub struct AsyncStdin {
4-
fd: Fd,
5-
#[cfg(unix)]
6-
fds: libc::fd_set,
4+
fd: Fd,
75
}
86

97
impl Default for AsyncStdin {
10-
fn default() -> Self {
11-
let fd = Fd::new().expect("failed to open stdin");
12-
#[cfg(unix)]
13-
{
14-
let mut me = Self { fd, fds: unsafe { std::mem::MaybeUninit::zeroed().assume_init() } };
15-
me.reset();
16-
me
17-
}
18-
#[cfg(windows)]
19-
{
20-
Self { fd }
21-
}
22-
}
8+
fn default() -> Self { Self { fd: Fd::new().expect("failed to open stdin") } }
239
}
2410

2511
impl AsyncStdin {
@@ -63,16 +49,16 @@ impl AsyncStdin {
6349
};
6450

6551
let result = unsafe {
66-
libc::select(*self.fd + 1, &mut self.fds, std::ptr::null_mut(), std::ptr::null_mut(), &mut tv)
52+
let mut set: libc::fd_set = std::mem::zeroed();
53+
libc::FD_ZERO(&mut set);
54+
libc::FD_SET(*self.fd, &mut set);
55+
libc::select(*self.fd + 1, &mut set, std::ptr::null_mut(), std::ptr::null_mut(), &mut tv)
6756
};
6857

6958
match result {
7059
-1 => Err(Error::last_os_error()),
7160
0 => Ok(false),
72-
_ => {
73-
self.reset();
74-
Ok(true)
75-
}
61+
_ => Ok(true),
7662
}
7763
}
7864

@@ -84,13 +70,6 @@ impl AsyncStdin {
8470
_ => Ok(b),
8571
}
8672
}
87-
88-
fn reset(&mut self) {
89-
unsafe {
90-
libc::FD_ZERO(&mut self.fds);
91-
libc::FD_SET(*self.fd, &mut self.fds);
92-
}
93-
}
9473
}
9574

9675
// --- Windows

0 commit comments

Comments
 (0)