feat: reduce terminal response wait timeout (#2314)

This commit is contained in:
三咲雅 · Misaki Masa 2025-02-10 18:46:38 +08:00 committed by GitHub
parent 793c90f021
commit d75a5d6628
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 33 deletions

View file

@ -1,9 +1,9 @@
use std::{io::{LineWriter, Read, stderr}, time::Duration};
use std::{io::{LineWriter, stderr}, time::Duration};
use anyhow::{Result, bail};
use crossterm::{cursor::{RestorePosition, SavePosition}, execute, style::Print, terminal::{disable_raw_mode, enable_raw_mode}};
use scopeguard::defer;
use tokio::{io::{AsyncReadExt, BufReader}, time::timeout};
use tokio::{io::{AsyncReadExt, BufReader}, time::{sleep, timeout}};
use tracing::{debug, error, warn};
use yazi_shared::Either;
@ -125,17 +125,18 @@ impl Emulator {
Ok(())
};
match timeout(Duration::from_secs(5), read).await {
let h = tokio::spawn(async move {
sleep(Duration::from_millis(300)).await;
Self::error_to_user().ok();
});
match timeout(Duration::from_secs(2), read).await {
Ok(Ok(())) => debug!("read_until_da1: {buf:?}"),
Err(e) => {
error!("read_until_da1 timed out: {buf:?}, error: {e:?}");
Self::error_to_user().ok();
}
Ok(Err(e)) => {
error!("read_until_da1 failed: {buf:?}, error: {e:?}");
Self::error_to_user().ok();
}
Err(e) => error!("read_until_da1 timed out: {buf:?}, error: {e:?}"),
Ok(Err(e)) => error!("read_until_da1 failed: {buf:?}, error: {e:?}"),
}
h.abort();
String::from_utf8_lossy(&buf).into_owned()
}
@ -156,21 +157,15 @@ impl Emulator {
Ok(())
};
match timeout(Duration::from_secs(5), read).await {
match timeout(Duration::from_millis(500), read).await {
Ok(Ok(())) => debug!("read_until_dsr: {buf:?}"),
Err(e) => {
error!("read_until_dsr timed out: {buf:?}, error: {e:?}");
Self::error_to_user().ok();
}
Ok(Err(e)) => {
error!("read_until_dsr failed: {buf:?}, error: {e:?}");
Self::error_to_user().ok();
}
Err(e) => error!("read_until_dsr timed out: {buf:?}, error: {e:?}"),
Ok(Err(e)) => error!("read_until_dsr failed: {buf:?}, error: {e:?}"),
}
String::from_utf8_lossy(&buf).into_owned()
}
fn error_to_user() -> Result<()> {
fn error_to_user() -> Result<(), std::io::Error> {
use crossterm::style::{Attribute, Color, Print, ResetColor, SetAttributes, SetForegroundColor};
crossterm::execute!(
std::io::stderr(),
@ -184,15 +179,7 @@ impl Emulator {
Print(
"Please check your terminal environment as per: https://yazi-rs.github.io/docs/faq#trt\r\n"
),
//
SetAttributes(Attribute::Bold.into()),
SetAttributes(Attribute::Reverse.into()),
Print("Press any key to continue...\r\n"),
SetAttributes(Attribute::Reset.into()),
)?;
std::io::stdin().read_exact(&mut [0])?;
Ok(())
)
}
fn cell_size(resp: &str) -> Option<(u16, u16)> {

View file

@ -1,11 +1,10 @@
use mlua::{ExternalError, ExternalResult, FromLua, IntoLua, Lua, ObjectLike, Table, Value};
use tokio::runtime::Handle;
use yazi_config::LAYOUT;
use yazi_dds::Sendable;
use yazi_shared::event::CmdCow;
use super::slim_lua;
use crate::{Error, elements::Rect, file::File, loader::LOADER};
use crate::{Error, file::File, loader::LOADER};
pub async fn fetch(
cmd: CmdCow,
@ -27,7 +26,6 @@ pub async fn fetch(
Handle::current().block_on(plugin.call_async_method(
"fetch",
lua.create_table_from([
("area", Rect::from(LAYOUT.get().preview).into_lua(&lua)?),
("args", Sendable::args_to_table_ref(&lua, &cmd.args)?.into_lua(&lua)?),
("files", lua.create_sequence_from(files.into_iter().map(File))?.into_lua(&lua)?),
])?,