diff --git a/yazi-adapter/src/ueberzug.rs b/yazi-adapter/src/ueberzug.rs index d7a07cbb..6feb9a0d 100644 --- a/yazi-adapter/src/ueberzug.rs +++ b/yazi-adapter/src/ueberzug.rs @@ -10,8 +10,9 @@ use yazi_shared::{RoCell, env_exists}; use crate::{Adapter, Dimension}; -#[allow(clippy::type_complexity)] -static DEMON: RoCell>>> = RoCell::new(); +type Cmd = Option<(PathBuf, Rect)>; + +static DEMON: RoCell>> = RoCell::new(); pub(super) struct Ueberzug; @@ -34,7 +35,7 @@ impl Ueberzug { child = Self::create_demon(adapter).ok(); } if let Some(c) = &mut child { - Self::send_command(c, cmd).await.ok(); + Self::send_command(adapter, c, cmd).await.ok(); } } }); @@ -108,30 +109,28 @@ impl Ueberzug { rect } - async fn send_command(child: &mut Child, cmd: Option<(PathBuf, Rect)>) -> Result<()> { - let stdin = child.stdin.as_mut().unwrap(); - if let Some((path, rect)) = cmd { + async fn send_command(adapter: Adapter, child: &mut Child, cmd: Cmd) -> Result<()> { + let s = if let Some((path, rect)) = cmd { debug!("ueberzugpp rect before adjustment: {:?}", rect); let rect = Self::adjust_rect(rect); debug!("ueberzugpp rect after adjustment: {:?}", rect); - let s = format!( + format!( r#"{{"action":"add","identifier":"yazi","x":{},"y":{},"max_width":{},"max_height":{},"path":"{}"}}{}"#, rect.x, rect.y, rect.width, rect.height, path.to_string_lossy(), - "\n" - ); - debug!("ueberzugpp command: {}", s); - stdin.write_all(s.as_bytes()).await?; + '\n' + ) } else { - debug!("ueberzugpp command: remove"); - stdin - .write_all(format!(r#"{{"action":"remove","identifier":"yazi"}}{}"#, "\n").as_bytes()) - .await?; - } + format!(r#"{{"action":"remove","identifier":"yazi"}}{}"#, '\n') + }; + + debug!("`ueberzugpp layer -so {adapter}` command: {s}"); + child.stdin.as_mut().unwrap().write_all(s.as_bytes()).await?; + Ok(()) } } diff --git a/yazi-fm/src/signals.rs b/yazi-fm/src/signals.rs index ae57df2c..02d6b83f 100644 --- a/yazi-fm/src/signals.rs +++ b/yazi-fm/src/signals.rs @@ -26,12 +26,13 @@ impl Signals { #[cfg(unix)] #[inline] fn handle_sys(n: libc::c_int) -> bool { - use libc::{SIGCONT, SIGHUP, SIGQUIT, SIGSTOP, SIGTERM, SIGTSTP}; + use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGSTOP, SIGTERM, SIGTSTP}; use tracing::error; use yazi_proxy::{AppProxy, HIDER}; match n { - SIGHUP | SIGTERM | SIGQUIT => { + SIGINT => { /* ignored */ } + SIGQUIT | SIGHUP | SIGTERM => { Event::Quit(Default::default()).emit(); return false; } @@ -73,13 +74,17 @@ impl Signals { fn spawn(mut rx: mpsc::UnboundedReceiver<(bool, Option>)>) -> Result<()> { #[cfg(unix)] - use libc::{SIGCONT, SIGHUP, SIGQUIT, SIGTERM, SIGTSTP}; + use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGTSTP}; #[cfg(unix)] let mut sys = signal_hook_tokio::Signals::new([ - // Terminating signals - SIGHUP, SIGTERM, SIGQUIT, // - // Job control signals + // Interrupt signals (Ctrl-C, Ctrl-\) + SIGINT, SIGQUIT, // + // Hangup signal (Terminal closed) + SIGHUP, // + // Termination signal (kill) + SIGTERM, // + // Job control signals (Ctrl-Z, fg/bg) SIGTSTP, SIGCONT, ])?; #[cfg(windows)]