fix: broken DECSET and DECRQM requests in foot

This commit is contained in:
sxyazi 2024-07-26 22:20:22 +08:00
parent bf206fcf31
commit 60bef59598
No known key found for this signature in database
2 changed files with 18 additions and 22 deletions

View file

@ -190,9 +190,9 @@ impl Emulator {
} }
pub async fn read_until_da1() -> Result<String> { pub async fn read_until_da1() -> Result<String> {
let mut buf: Vec<u8> = Vec::with_capacity(200);
let read = async { let read = async {
let mut stdin = BufReader::new(tokio::io::stdin()); let mut stdin = BufReader::new(tokio::io::stdin());
let mut buf: Vec<u8> = Vec::with_capacity(200);
loop { loop {
let mut c = [0; 1]; let mut c = [0; 1];
if stdin.read(&mut c).await? == 0 { if stdin.read(&mut c).await? == 0 {
@ -206,14 +206,14 @@ impl Emulator {
break; break;
} }
} }
Ok(buf) Ok(())
}; };
let timeout = timeout(Duration::from_secs(10), read).await; match timeout(Duration::from_secs(10), read).await {
if let Err(ref e) = timeout { Err(e) => error!("read_until_da1 timed out: {buf:?}, error: {e:?}"),
error!("read_until_da1: {e:?}"); Ok(Err(e)) => error!("read_until_da1 failed: {buf:?}, error: {e:?}"),
Ok(Ok(())) => {}
} }
String::from_utf8(buf).map_err(Into::into)
String::from_utf8(timeout??).map_err(Into::into)
} }
} }

View file

@ -14,22 +14,18 @@ pub struct Plugin {
} }
impl Plugin { impl Plugin {
pub fn fetchers( pub fn fetchers<'a>(
&self, &'a self,
path: &Path, path: &'a Path,
mime: Option<&str>, mime: Option<&'a str>,
f: impl Fn(&str) -> bool + Copy, factor: impl Fn(&str) -> bool + Copy,
) -> Vec<&Fetcher> { ) -> impl Iterator<Item = &'a Fetcher> {
let is_dir = mime == Some(MIME_DIR); let is_dir = mime == Some(MIME_DIR);
self self.fetchers.iter().filter(move |&f| {
.fetchers f.if_.as_ref().and_then(|c| c.eval(factor)) != Some(false)
.iter() && (f.mime.as_ref().zip(mime).map_or(false, |(p, m)| p.match_mime(m))
.filter(|&p| { || f.name.as_ref().is_some_and(|p| p.match_path(path, is_dir)))
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()
} }
pub fn preloaders(&self, path: &Path, mime: Option<&str>) -> Vec<&Preloader> { pub fn preloaders(&self, path: &Path, mime: Option<&str>) -> Vec<&Preloader> {