mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
339fb14402
commit
a62f4ad2ad
3 changed files with 11 additions and 14 deletions
|
|
@ -106,28 +106,24 @@ impl Emulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_until_da1() -> String {
|
pub fn read_until_da1() -> String {
|
||||||
let h = tokio::spawn(async move {
|
let h = tokio::spawn(Self::error_to_user());
|
||||||
sleep(Duration::from_millis(300)).await;
|
let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(300), |b, buf| {
|
||||||
Self::error_to_user().ok();
|
|
||||||
});
|
|
||||||
|
|
||||||
let (buf, result) = AsyncStdin::default().read_until(Duration::from_secs(5), |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"[?"))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
h.abort();
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => debug!("read_until_da1: {buf:?}"),
|
Ok(()) => debug!("read_until_da1: {buf:?}"),
|
||||||
Err(e) => error!("read_until_da1 failed: {buf:?}, error: {e:?}"),
|
Err(e) => error!("read_until_da1 failed: {buf:?}, error: {e:?}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
h.abort();
|
|
||||||
String::from_utf8_lossy(&buf).into_owned()
|
String::from_utf8_lossy(&buf).into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_until_dsr() -> String {
|
pub fn read_until_dsr() -> String {
|
||||||
let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(500), |b, buf| {
|
let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(100), |b, buf| {
|
||||||
b == b'n' && (buf.ends_with(b"\x1b[0n") || buf.ends_with(b"\x1b[3n"))
|
b == b'n' && (buf.ends_with(b"\x1b[0n") || buf.ends_with(b"\x1b[3n"))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -135,13 +131,14 @@ impl Emulator {
|
||||||
Ok(()) => debug!("read_until_dsr: {buf:?}"),
|
Ok(()) => debug!("read_until_dsr: {buf:?}"),
|
||||||
Err(e) => error!("read_until_dsr failed: {buf:?}, error: {e:?}"),
|
Err(e) => error!("read_until_dsr failed: {buf:?}, error: {e:?}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
String::from_utf8_lossy(&buf).into_owned()
|
String::from_utf8_lossy(&buf).into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_to_user() -> Result<(), std::io::Error> {
|
async fn error_to_user() {
|
||||||
use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttributes, SetForegroundColor};
|
use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttributes, SetForegroundColor};
|
||||||
crossterm::execute!(
|
|
||||||
|
sleep(Duration::from_millis(200)).await;
|
||||||
|
_ = crossterm::execute!(
|
||||||
std::io::stderr(),
|
std::io::stderr(),
|
||||||
SetForegroundColor(Color::Red),
|
SetForegroundColor(Color::Red),
|
||||||
SetAttributes(Attribute::Bold.into()),
|
SetAttributes(Attribute::Bold.into()),
|
||||||
|
|
@ -153,7 +150,7 @@ impl Emulator {
|
||||||
Print(
|
Print(
|
||||||
"Please check your terminal environment as per: https://yazi-rs.github.io/docs/faq#trt\r\n"
|
"Please check your terminal environment as per: https://yazi-rs.github.io/docs/faq#trt\r\n"
|
||||||
),
|
),
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cell_size(resp: &str) -> Option<(u16, u16)> {
|
fn cell_size(resp: &str) -> Option<(u16, u16)> {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#![allow(clippy::unit_arg)]
|
#![allow(clippy::unit_arg, clippy::option_map_unit_fn)]
|
||||||
|
|
||||||
yazi_macro::mod_pub!(drivers);
|
yazi_macro::mod_pub!(drivers);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ impl AsyncStdin {
|
||||||
loop {
|
loop {
|
||||||
if now.elapsed() > timeout {
|
if now.elapsed() > timeout {
|
||||||
return Err(Error::new(ErrorKind::TimedOut, "timed out"));
|
return Err(Error::new(ErrorKind::TimedOut, "timed out"));
|
||||||
} else if !self.poll(Duration::from_millis(50))? {
|
} else if !self.poll(Duration::from_millis(30))? {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue