From c3a6e786381259e150030b3ef34306b78bce3556 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Sun, 24 May 2026 03:10:47 -0700 Subject: [PATCH] fix: don't require a TTY for `--version` --- yazi-boot/src/actions/actions.rs | 13 ++++++++----- yazi-boot/src/lib.rs | 6 +++++- yazi-fm/src/main.rs | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/yazi-boot/src/actions/actions.rs b/yazi-boot/src/actions/actions.rs index d4d120fa..03f17006 100644 --- a/yazi-boot/src/actions/actions.rs +++ b/yazi-boot/src/actions/actions.rs @@ -3,17 +3,20 @@ use std::process; pub struct Actions; impl Actions { + // Actions that require no terminal/config initialization, handled before it. + pub(crate) fn act_early(args: &crate::Args) { + if args.version { + println!("Yazi {}", Self::version()); + process::exit(0); + } + } + pub(crate) fn act(args: &crate::Args) { if args.debug { println!("{}", Self::debug().unwrap()); process::exit(0); } - if args.version { - println!("Yazi {}", Self::version()); - process::exit(0); - } - if args.clear_cache { Self::clear_cache(); process::exit(0); diff --git a/yazi-boot/src/lib.rs b/yazi-boot/src/lib.rs index 0f9f5f98..9ea5c3b7 100644 --- a/yazi-boot/src/lib.rs +++ b/yazi-boot/src/lib.rs @@ -8,8 +8,12 @@ use yazi_shim::cell::RoCell; pub static ARGS: RoCell = RoCell::new(); pub static BOOT: RoCell = RoCell::new(); -pub fn init() { +pub fn preflight() { ARGS.with(<_>::parse); + actions::Actions::act_early(&ARGS); +} + +pub fn init() { BOOT.init(<_>::from(&*ARGS)); actions::Actions::act(&ARGS); diff --git a/yazi-fm/src/main.rs b/yazi-fm/src/main.rs index c3ea749e..70b5ed3f 100644 --- a/yazi-fm/src/main.rs +++ b/yazi-fm/src/main.rs @@ -14,6 +14,8 @@ async fn main() -> anyhow::Result<()> { Logs::start()?; _ = fdlimit::raise_fd_limit(); + yazi_boot::preflight(); + yazi_tty::init(); yazi_term::init()?;