diff --git a/yazi-adapter/src/emulator.rs b/yazi-adapter/src/emulator.rs index 832233bf..00ba24fb 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-adapter/src/emulator.rs @@ -190,9 +190,9 @@ impl Emulator { } pub async fn read_until_da1() -> Result { + let mut buf: Vec = Vec::with_capacity(200); let read = async { let mut stdin = BufReader::new(tokio::io::stdin()); - let mut buf: Vec = Vec::with_capacity(200); loop { let mut c = [0; 1]; if stdin.read(&mut c).await? == 0 { @@ -206,14 +206,14 @@ impl Emulator { break; } } - Ok(buf) + Ok(()) }; - let timeout = timeout(Duration::from_secs(10), read).await; - if let Err(ref e) = timeout { - error!("read_until_da1: {e:?}"); + match timeout(Duration::from_secs(10), read).await { + Err(e) => error!("read_until_da1 timed out: {buf:?}, error: {e:?}"), + Ok(Err(e)) => error!("read_until_da1 failed: {buf:?}, error: {e:?}"), + Ok(Ok(())) => {} } - - String::from_utf8(timeout??).map_err(Into::into) + String::from_utf8(buf).map_err(Into::into) } } diff --git a/yazi-config/src/plugin/plugin.rs b/yazi-config/src/plugin/plugin.rs index 9e51fa0e..7a9b96ff 100644 --- a/yazi-config/src/plugin/plugin.rs +++ b/yazi-config/src/plugin/plugin.rs @@ -14,22 +14,18 @@ pub struct Plugin { } impl Plugin { - pub fn fetchers( - &self, - path: &Path, - mime: Option<&str>, - f: impl Fn(&str) -> bool + Copy, - ) -> Vec<&Fetcher> { + pub fn fetchers<'a>( + &'a self, + path: &'a Path, + mime: Option<&'a str>, + factor: impl Fn(&str) -> bool + Copy, + ) -> impl Iterator { let is_dir = mime == Some(MIME_DIR); - self - .fetchers - .iter() - .filter(|&p| { - p.if_.as_ref().and_then(|c| c.eval(f)) != Some(false) - && (p.mime.as_ref().zip(mime).map_or(false, |(p, m)| p.match_mime(m)) - || p.name.as_ref().is_some_and(|p| p.match_path(path, is_dir))) - }) - .collect() + self.fetchers.iter().filter(move |&f| { + f.if_.as_ref().and_then(|c| c.eval(factor)) != Some(false) + && (f.mime.as_ref().zip(mime).map_or(false, |(p, m)| p.match_mime(m)) + || f.name.as_ref().is_some_and(|p| p.match_path(path, is_dir))) + }) } pub fn preloaders(&self, path: &Path, mime: Option<&str>) -> Vec<&Preloader> {