Skip to content

Commit

Permalink
Merge branch 'sxyazi:main' into statusline-enhance
Browse files Browse the repository at this point in the history
  • Loading branch information
PFiS1737 authored Feb 10, 2025
2 parents 340d043 + d75a5d6 commit 66b7eae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
47 changes: 17 additions & 30 deletions yazi-adapter/src/emulator.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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()
}

Expand All @@ -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(),
Expand All @@ -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)> {
Expand Down
4 changes: 1 addition & 3 deletions yazi-plugin/src/isolate/fetch.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)?),
])?,
Expand Down

0 comments on commit 66b7eae

Please sign in to comment.