From a62f4ad2ad7d73662c9e3f2fe9ee6a533a89993c Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 16 Feb 2025 22:49:36 +0800 Subject: [PATCH] .. --- yazi-adapter/src/emulator.rs | 21 +++++++++------------ yazi-adapter/src/lib.rs | 2 +- yazi-adapter/src/stdin.rs | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/yazi-adapter/src/emulator.rs b/yazi-adapter/src/emulator.rs index 873f6851..57906ba9 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-adapter/src/emulator.rs @@ -106,28 +106,24 @@ impl Emulator { } pub fn read_until_da1() -> String { - let h = tokio::spawn(async move { - sleep(Duration::from_millis(300)).await; - Self::error_to_user().ok(); - }); - - let (buf, result) = AsyncStdin::default().read_until(Duration::from_secs(5), |b, buf| { + let h = tokio::spawn(Self::error_to_user()); + let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(300), |b, buf| { b == b'c' && buf.contains(&0x1b) && buf.rsplitn(2, |&b| b == 0x1b).next().is_some_and(|s| s.starts_with(b"[?")) }); + h.abort(); match result { Ok(()) => debug!("read_until_da1: {buf:?}"), Err(e) => error!("read_until_da1 failed: {buf:?}, error: {e:?}"), } - h.abort(); String::from_utf8_lossy(&buf).into_owned() } 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")) }); @@ -135,13 +131,14 @@ impl Emulator { Ok(()) => debug!("read_until_dsr: {buf:?}"), Err(e) => error!("read_until_dsr failed: {buf:?}, error: {e:?}"), } - 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}; - crossterm::execute!( + + sleep(Duration::from_millis(200)).await; + _ = crossterm::execute!( std::io::stderr(), SetForegroundColor(Color::Red), SetAttributes(Attribute::Bold.into()), @@ -153,7 +150,7 @@ impl Emulator { Print( "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)> { diff --git a/yazi-adapter/src/lib.rs b/yazi-adapter/src/lib.rs index be4b23e8..d931bc84 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -1,4 +1,4 @@ -#![allow(clippy::unit_arg)] +#![allow(clippy::unit_arg, clippy::option_map_unit_fn)] yazi_macro::mod_pub!(drivers); diff --git a/yazi-adapter/src/stdin.rs b/yazi-adapter/src/stdin.rs index 3c0e262b..00f5ecd1 100644 --- a/yazi-adapter/src/stdin.rs +++ b/yazi-adapter/src/stdin.rs @@ -17,7 +17,7 @@ impl AsyncStdin { loop { if now.elapsed() > timeout { 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; }