From 24c60419bb19c49e1a8fc7a2b6900ae0365fb502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Tue, 27 Jan 2026 22:37:34 +0800 Subject: [PATCH] refactor: new `yazi-emulator` crate (#3624) --- Cargo.lock | 76 +++++++++++-------- yazi-actor/Cargo.toml | 1 - yazi-adapter/Cargo.toml | 13 ++-- yazi-adapter/src/adapter.rs | 3 +- yazi-adapter/src/adapters.rs | 16 ++-- yazi-adapter/src/drivers/chafa.rs | 3 +- yazi-adapter/src/drivers/iip.rs | 3 +- yazi-adapter/src/drivers/kgp.rs | 3 +- yazi-adapter/src/drivers/kgp_old.rs | 3 +- yazi-adapter/src/drivers/sixel.rs | 3 +- yazi-adapter/src/drivers/ueberzug.rs | 3 +- yazi-adapter/src/image.rs | 3 +- yazi-adapter/src/lib.rs | 12 +-- yazi-boot/Cargo.toml | 13 ++-- yazi-boot/src/actions/debug.rs | 10 +-- yazi-build/Cargo.toml | 1 - yazi-config/Cargo.toml | 1 - yazi-core/Cargo.toml | 1 + yazi-core/src/help/help.rs | 2 +- yazi-core/src/mgr/mgr.rs | 2 +- yazi-core/src/tab/tab.rs | 2 +- yazi-core/src/tasks/tasks.rs | 2 +- yazi-emulator/Cargo.toml | 27 +++++++ yazi-emulator/README.md | 5 ++ {yazi-adapter => yazi-emulator}/src/brand.rs | 0 .../src/dimension.rs | 0 .../src/emulator.rs | 4 +- yazi-emulator/src/lib.rs | 1 + {yazi-adapter => yazi-emulator}/src/mux.rs | 8 +- .../src/unknown.rs | 0 yazi-fm/Cargo.toml | 37 ++++----- yazi-fm/src/app/commands/update_notify.rs | 2 +- yazi-fm/src/cmp/cmp.rs | 2 +- yazi-fm/src/term.rs | 6 +- yazi-parser/Cargo.toml | 2 +- yazi-parser/src/app/notify.rs | 2 +- yazi-plugin/Cargo.toml | 27 +++---- yazi-plugin/src/runtime/term.rs | 2 +- yazi-proxy/Cargo.toml | 1 - yazi-term/Cargo.toml | 3 - yazi-widgets/Cargo.toml | 1 - 41 files changed, 178 insertions(+), 128 deletions(-) create mode 100644 yazi-emulator/Cargo.toml create mode 100644 yazi-emulator/README.md rename {yazi-adapter => yazi-emulator}/src/brand.rs (100%) rename {yazi-adapter => yazi-emulator}/src/dimension.rs (100%) rename {yazi-adapter => yazi-emulator}/src/emulator.rs (98%) create mode 100644 yazi-emulator/src/lib.rs rename {yazi-adapter => yazi-emulator}/src/mux.rs (88%) rename {yazi-adapter => yazi-emulator}/src/unknown.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index a6793513..670937bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1240,9 +1240,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.11.0-rc.8" +version = "0.11.0-rc.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fc1408b7a9f59a7b933faff3e9e7fc15a05a524effd3b3d1601156944c8077f" +checksum = "bff8de092798697546237a3a701e4174fe021579faec9b854379af9bf1e31962" dependencies = [ "block-buffer 0.11.0", "const-oid 0.10.2", @@ -2064,7 +2064,7 @@ checksum = "fe44f2bbd99fcb302e246e2d6bcf51aeda346d02a365f80296a07a8c711b6da6" dependencies = [ "argon2", "bcrypt-pbkdf", - "digest 0.11.0-rc.8", + "digest 0.11.0-rc.9", "ecdsa", "ed25519-dalek", "hex", @@ -2585,9 +2585,12 @@ dependencies = [ [[package]] name = "notify-types" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d" +checksum = "42b8cfee0e339a0337359f3c88165702ac6e600dc01c0cc9579a92d62b08477a" +dependencies = [ + "bitflags 2.10.0", +] [[package]] name = "nu-ansi-term" @@ -3130,9 +3133,9 @@ dependencies = [ [[package]] name = "pkcs8" -version = "0.11.0-rc.9" +version = "0.11.0-rc.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80f8fa6196ede5a9f9ee95b44ca134bddc9b70e8913f9297bd58c909f5889a09" +checksum = "b226d2cc389763951db8869584fd800cbbe2962bf454e2edeb5172b31ee99774" dependencies = [ "der 0.8.0-rc.10", "spki 0.8.0-rc.4", @@ -3688,9 +3691,9 @@ dependencies = [ "const-oid 0.10.2", "crypto-bigint 0.7.0-rc.18", "crypto-primes", - "digest 0.11.0-rc.8", + "digest 0.11.0-rc.9", "pkcs1", - "pkcs8 0.11.0-rc.9", + "pkcs8 0.11.0-rc.10", "rand_core 0.10.0-rc-3", "sha2 0.11.0-rc.4", "signature 3.0.0-rc.6", @@ -4053,7 +4056,7 @@ checksum = "9c777f0a122a53fddb0beb6e706771197000b8eb5c9f42b5b850f450ef48c788" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.11.0-rc.8", + "digest 0.11.0-rc.9", ] [[package]] @@ -4075,7 +4078,7 @@ checksum = "7535f94fa3339fe9e5e9be6260a909e62af97f6e14b32345ccf79b92b8b81233" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.11.0-rc.8", + "digest 0.11.0-rc.9", ] [[package]] @@ -4162,7 +4165,7 @@ version = "3.0.0-rc.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a96996ccff7dfa16f052bd995b4cecc72af22c35138738dc029f0ead6608d" dependencies = [ - "digest 0.11.0-rc.8", + "digest 0.11.0-rc.9", "rand_core 0.10.0-rc-3", ] @@ -4189,9 +4192,9 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" [[package]] name = "siphasher" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" +checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" [[package]] name = "slab" @@ -4849,9 +4852,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e054861b4bd027cd373e18e8d8d8e6548085000e41290d95ce0c373a654b4a" +checksum = "ee48d38b119b0cd71fe4141b30f5ba9c7c5d9f4e7a3a8b4a674e4b6ef789976f" dependencies = [ "atomic", "getrandom 0.3.4", @@ -5555,7 +5558,6 @@ dependencies = [ "yazi-proxy", "yazi-scheduler", "yazi-shared", - "yazi-term", "yazi-tty", "yazi-vfs", "yazi-watcher", @@ -5575,14 +5577,13 @@ dependencies = [ "palette", "quantette", "ratatui", - "scopeguard", "tokio", "tracing", "yazi-config", + "yazi-emulator", "yazi-fs", "yazi-macro", "yazi-shared", - "yazi-term", "yazi-tty", ] @@ -5622,6 +5623,7 @@ dependencies = [ "vergen-gitcl", "yazi-adapter", "yazi-config", + "yazi-emulator", "yazi-fs", "yazi-macro", "yazi-shared", @@ -5632,7 +5634,6 @@ dependencies = [ name = "yazi-build" version = "26.1.22" dependencies = [ - "yazi-term", "yazi-tty", ] @@ -5689,7 +5690,6 @@ dependencies = [ "yazi-fs", "yazi-macro", "yazi-shared", - "yazi-term", "yazi-tty", ] @@ -5711,6 +5711,7 @@ dependencies = [ "yazi-adapter", "yazi-config", "yazi-dds", + "yazi-emulator", "yazi-fs", "yazi-macro", "yazi-parser", @@ -5748,6 +5749,20 @@ dependencies = [ "yazi-shared", ] +[[package]] +name = "yazi-emulator" +version = "26.1.22" +dependencies = [ + "anyhow", + "crossterm 0.29.0", + "scopeguard", + "tokio", + "tracing", + "yazi-macro", + "yazi-shared", + "yazi-tty", +] + [[package]] name = "yazi-ffi" version = "26.1.22" @@ -5787,6 +5802,7 @@ dependencies = [ "yazi-config", "yazi-core", "yazi-dds", + "yazi-emulator", "yazi-fs", "yazi-macro", "yazi-parser", @@ -5890,6 +5906,7 @@ dependencies = [ "yazi-boot", "yazi-config", "yazi-dds", + "yazi-emulator", "yazi-fs", "yazi-macro", "yazi-parser", @@ -5911,7 +5928,6 @@ checksum = "33232d9116df6415ddfcdf72701b1b7439ce87f240a14723e8dd5d17e7ed5f98" name = "yazi-proxy" version = "26.1.22" dependencies = [ - "anyhow", "tokio", "yazi-config", "yazi-macro", @@ -5998,10 +6014,7 @@ version = "26.1.22" dependencies = [ "crossterm 0.29.0", "libc", - "parking_lot", - "tracing", "yazi-macro", - "yazi-shared", ] [[package]] @@ -6075,24 +6088,23 @@ dependencies = [ "yazi-macro", "yazi-parser", "yazi-shared", - "yazi-term", "yazi-tty", ] [[package]] name = "zerocopy" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" +checksum = "71ddd76bcebeed25db614f82bf31a9f4222d3fbba300e6fb6c00afa26cbd4d9d" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" +checksum = "d8187381b52e32220d50b255276aa16a084ec0a9017a0ca2152a1f55c539758d" dependencies = [ "proc-macro2", "quote", @@ -6121,9 +6133,9 @@ dependencies = [ [[package]] name = "zmij" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65" +checksum = "02aae0f83f69aafc94776e879363e9771d7ecbffe2c7fbb6c14c5e00dfe88439" [[package]] name = "zune-core" diff --git a/yazi-actor/Cargo.toml b/yazi-actor/Cargo.toml index e94ab82d..66a2e067 100644 --- a/yazi-actor/Cargo.toml +++ b/yazi-actor/Cargo.toml @@ -28,7 +28,6 @@ yazi-plugin = { path = "../yazi-plugin", version = "26.1.22" } yazi-proxy = { path = "../yazi-proxy", version = "26.1.22" } yazi-scheduler = { path = "../yazi-scheduler", version = "26.1.22" } yazi-shared = { path = "../yazi-shared", version = "26.1.22" } -yazi-term = { path = "../yazi-term", version = "26.1.22" } yazi-tty = { path = "../yazi-tty", version = "26.1.22" } yazi-vfs = { path = "../yazi-vfs", version = "26.1.22" } yazi-watcher = { path = "../yazi-watcher", version = "26.1.22" } diff --git a/yazi-adapter/Cargo.toml b/yazi-adapter/Cargo.toml index 49bf7dff..ced68daa 100644 --- a/yazi-adapter/Cargo.toml +++ b/yazi-adapter/Cargo.toml @@ -12,12 +12,12 @@ repository = "https://github.com/sxyazi/yazi" workspace = true [dependencies] -yazi-config = { path = "../yazi-config", version = "26.1.22" } -yazi-fs = { path = "../yazi-fs", version = "26.1.22" } -yazi-macro = { path = "../yazi-macro", version = "26.1.22" } -yazi-shared = { path = "../yazi-shared", version = "26.1.22" } -yazi-term = { path = "../yazi-term", version = "26.1.22" } -yazi-tty = { path = "../yazi-tty", version = "26.1.22" } +yazi-config = { path = "../yazi-config", version = "26.1.22" } +yazi-emulator = { path = "../yazi-emulator", version = "26.1.22" } +yazi-fs = { path = "../yazi-fs", version = "26.1.22" } +yazi-macro = { path = "../yazi-macro", version = "26.1.22" } +yazi-shared = { path = "../yazi-shared", version = "26.1.22" } +yazi-tty = { path = "../yazi-tty", version = "26.1.22" } # External dependencies ansi-to-tui = { workspace = true } @@ -29,7 +29,6 @@ moxcms = "0.8.0" palette = { version = "0.7.6", default-features = false } quantette = { version = "0.5.1", default-features = false } ratatui = { workspace = true } -scopeguard = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } diff --git a/yazi-adapter/src/adapter.rs b/yazi-adapter/src/adapter.rs index 1011f611..f04765c8 100644 --- a/yazi-adapter/src/adapter.rs +++ b/yazi-adapter/src/adapter.rs @@ -3,9 +3,10 @@ use std::{env, fmt::Display, path::PathBuf}; use anyhow::Result; use ratatui::layout::Rect; use tracing::warn; +use yazi_emulator::{Emulator, TMUX}; use yazi_shared::env_exists; -use crate::{Adapters, Emulator, SHOWN, TMUX, drivers}; +use crate::{Adapters, SHOWN, drivers}; #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Adapter { diff --git a/yazi-adapter/src/adapters.rs b/yazi-adapter/src/adapters.rs index ca4a5e89..d5a5510a 100644 --- a/yazi-adapter/src/adapters.rs +++ b/yazi-adapter/src/adapters.rs @@ -2,7 +2,7 @@ use std::ops::{Deref, DerefMut}; use yazi_shared::Either; -use crate::{Adapter, Brand, Emulator, Unknown}; +use crate::Adapter; pub(super) struct Adapters(Vec); @@ -16,8 +16,8 @@ impl DerefMut for Adapters { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } -impl From<&Emulator> for Adapters { - fn from(value: &Emulator) -> Self { +impl From<&yazi_emulator::Emulator> for Adapters { + fn from(value: &yazi_emulator::Emulator) -> Self { match value.kind { Either::Left(b) => b.into(), Either::Right(u) => u.into(), @@ -25,9 +25,9 @@ impl From<&Emulator> for Adapters { } } -impl From for Adapters { - fn from(value: Brand) -> Self { - use Brand as B; +impl From for Adapters { + fn from(value: yazi_emulator::Brand) -> Self { + use yazi_emulator::Brand as B; use crate::Adapter as A; @@ -55,8 +55,8 @@ impl From for Adapters { } } -impl From for Adapters { - fn from(value: Unknown) -> Self { +impl From for Adapters { + fn from(value: yazi_emulator::Unknown) -> Self { use Adapter as A; Self(match (value.kgp, value.sixel) { diff --git a/yazi-adapter/src/drivers/chafa.rs b/yazi-adapter/src/drivers/chafa.rs index 9fe759b4..f4c1c511 100644 --- a/yazi-adapter/src/drivers/chafa.rs +++ b/yazi-adapter/src/drivers/chafa.rs @@ -5,8 +5,9 @@ use anyhow::{Result, anyhow, bail}; use crossterm::{cursor::MoveTo, queue}; use ratatui::layout::Rect; use tokio::process::Command; +use yazi_emulator::Emulator; -use crate::{Adapter, Emulator}; +use crate::Adapter; pub(crate) struct Chafa; diff --git a/yazi-adapter/src/drivers/iip.rs b/yazi-adapter/src/drivers/iip.rs index c4612960..8bcd3066 100644 --- a/yazi-adapter/src/drivers/iip.rs +++ b/yazi-adapter/src/drivers/iip.rs @@ -6,8 +6,9 @@ use crossterm::{cursor::MoveTo, queue}; use image::{DynamicImage, ExtendedColorType, ImageEncoder, codecs::{jpeg::JpegEncoder, png::PngEncoder}}; use ratatui::layout::Rect; use yazi_config::YAZI; +use yazi_emulator::{CLOSE, Emulator, START}; -use crate::{CLOSE, Emulator, Image, START, adapter::Adapter}; +use crate::{Image, adapter::Adapter}; pub(crate) struct Iip; diff --git a/yazi-adapter/src/drivers/kgp.rs b/yazi-adapter/src/drivers/kgp.rs index 7d673b1a..b2498448 100644 --- a/yazi-adapter/src/drivers/kgp.rs +++ b/yazi-adapter/src/drivers/kgp.rs @@ -6,9 +6,10 @@ use base64::{Engine, engine::general_purpose}; use crossterm::{cursor::MoveTo, queue}; use image::DynamicImage; use ratatui::layout::Rect; +use yazi_emulator::{CLOSE, ESCAPE, Emulator, START}; use yazi_shared::SyncCell; -use crate::{CLOSE, ESCAPE, Emulator, START, adapter::Adapter, image::Image}; +use crate::{adapter::Adapter, image::Image}; static DIACRITICS: [char; 297] = [ '\u{0305}', diff --git a/yazi-adapter/src/drivers/kgp_old.rs b/yazi-adapter/src/drivers/kgp_old.rs index 9f87ba35..bb78103b 100644 --- a/yazi-adapter/src/drivers/kgp_old.rs +++ b/yazi-adapter/src/drivers/kgp_old.rs @@ -5,9 +5,10 @@ use anyhow::Result; use base64::{Engine, engine::general_purpose}; use image::DynamicImage; use ratatui::layout::Rect; +use yazi_emulator::{CLOSE, ESCAPE, Emulator, START}; use yazi_tty::TTY; -use crate::{CLOSE, ESCAPE, Emulator, Image, START, adapter::Adapter}; +use crate::{Image, adapter::Adapter}; pub(crate) struct KgpOld; diff --git a/yazi-adapter/src/drivers/sixel.rs b/yazi-adapter/src/drivers/sixel.rs index bcb4bfd8..daa7ca00 100644 --- a/yazi-adapter/src/drivers/sixel.rs +++ b/yazi-adapter/src/drivers/sixel.rs @@ -6,8 +6,9 @@ use image::{DynamicImage, GenericImageView, RgbImage}; use palette::{Srgb, cast::ComponentsAs}; use quantette::{PaletteSize, color_map::IndexedColorMap, wu::{BinnerU8x3, WuU8x3}}; use ratatui::layout::Rect; +use yazi_emulator::{CLOSE, ESCAPE, Emulator, START}; -use crate::{CLOSE, ESCAPE, Emulator, Image, START, adapter::Adapter}; +use crate::{Image, adapter::Adapter}; pub(crate) struct Sixel; diff --git a/yazi-adapter/src/drivers/ueberzug.rs b/yazi-adapter/src/drivers/ueberzug.rs index 088d67fa..54c64526 100644 --- a/yazi-adapter/src/drivers/ueberzug.rs +++ b/yazi-adapter/src/drivers/ueberzug.rs @@ -6,9 +6,10 @@ use ratatui::layout::Rect; use tokio::{io::AsyncWriteExt, process::{Child, Command}, sync::mpsc::{self, UnboundedSender}}; use tracing::{debug, warn}; use yazi_config::YAZI; +use yazi_emulator::Dimension; use yazi_shared::{LOG_LEVEL, RoCell, env_exists}; -use crate::{Adapter, Dimension}; +use crate::Adapter; type Cmd = Option<(PathBuf, Rect)>; diff --git a/yazi-adapter/src/image.rs b/yazi-adapter/src/image.rs index 35b8a52a..84355b19 100644 --- a/yazi-adapter/src/image.rs +++ b/yazi-adapter/src/image.rs @@ -4,9 +4,10 @@ use anyhow::Result; use image::{DynamicImage, ImageDecoder, ImageError, ImageReader, Limits, codecs::{jpeg::JpegEncoder, png::PngEncoder}, imageops::FilterType, metadata::Orientation}; use ratatui::layout::Rect; use yazi_config::YAZI; +use yazi_emulator::Dimension; use yazi_fs::provider::{Provider, local::Local}; -use crate::{Dimension, Icc}; +use crate::Icc; pub struct Image; diff --git a/yazi-adapter/src/lib.rs b/yazi-adapter/src/lib.rs index 1bf99bf9..4cb03b2c 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -1,10 +1,10 @@ yazi_macro::mod_pub!(drivers); -yazi_macro::mod_flat!(adapter adapters brand dimension emulator icc image info mux unknown); +yazi_macro::mod_flat!(adapter adapters icc image info); -use yazi_shared::{RoCell, SyncCell, in_wsl}; +use yazi_emulator::{Brand, CLOSE, EMULATOR, ESCAPE, Emulator, Mux, START, TMUX}; +use yazi_shared::{SyncCell, in_wsl}; -pub static EMULATOR: RoCell = RoCell::new(); pub static ADAPTOR: SyncCell = SyncCell::new(Adapter::Chafa); // Image state @@ -13,12 +13,6 @@ static SHOWN: SyncCell> = SyncCell::new(None); // WSL support pub static WSL: SyncCell = SyncCell::new(false); -// Tmux support -pub static TMUX: SyncCell = SyncCell::new(false); -static ESCAPE: SyncCell<&'static str> = SyncCell::new("\x1b"); -static START: SyncCell<&'static str> = SyncCell::new("\x1b"); -static CLOSE: SyncCell<&'static str> = SyncCell::new(""); - pub fn init() -> anyhow::Result<()> { // WSL support WSL.set(in_wsl()); diff --git a/yazi-boot/Cargo.toml b/yazi-boot/Cargo.toml index 80b886be..e1803b33 100644 --- a/yazi-boot/Cargo.toml +++ b/yazi-boot/Cargo.toml @@ -12,12 +12,13 @@ repository = "https://github.com/sxyazi/yazi" workspace = true [dependencies] -yazi-adapter = { path = "../yazi-adapter", version = "26.1.22" } -yazi-config = { path = "../yazi-config", version = "26.1.22" } -yazi-fs = { path = "../yazi-fs", version = "26.1.22" } -yazi-macro = { path = "../yazi-macro", version = "26.1.22" } -yazi-shared = { path = "../yazi-shared", version = "26.1.22" } -yazi-vfs = { path = "../yazi-vfs", version = "26.1.22" } +yazi-adapter = { path = "../yazi-adapter", version = "26.1.22" } +yazi-config = { path = "../yazi-config", version = "26.1.22" } +yazi-emulator = { path = "../yazi-emulator", version = "26.1.22" } +yazi-fs = { path = "../yazi-fs", version = "26.1.22" } +yazi-macro = { path = "../yazi-macro", version = "26.1.22" } +yazi-shared = { path = "../yazi-shared", version = "26.1.22" } +yazi-vfs = { path = "../yazi-vfs", version = "26.1.22" } # External dependencies clap = { workspace = true } diff --git a/yazi-boot/src/actions/debug.rs b/yazi-boot/src/actions/debug.rs index 59034370..0b338e2e 100644 --- a/yazi-boot/src/actions/debug.rs +++ b/yazi-boot/src/actions/debug.rs @@ -1,8 +1,8 @@ use std::{env, ffi::OsStr, fmt::Write, path::Path}; use regex::Regex; -use yazi_adapter::Mux; use yazi_config::{THEME, YAZI}; +use yazi_emulator::Mux; use yazi_fs::Xdg; use yazi_shared::timestamp_us; @@ -33,12 +33,12 @@ impl Actions { writeln!(s, " TERM : {:?}", env::var_os("TERM"))?; writeln!(s, " TERM_PROGRAM : {:?}", env::var_os("TERM_PROGRAM"))?; writeln!(s, " TERM_PROGRAM_VERSION: {:?}", env::var_os("TERM_PROGRAM_VERSION"))?; - writeln!(s, " Brand.from_env : {:?}", yazi_adapter::Brand::from_env())?; - writeln!(s, " Emulator.detect : {:?}", &*yazi_adapter::EMULATOR)?; + writeln!(s, " Brand.from_env : {:?}", yazi_emulator::Brand::from_env())?; + writeln!(s, " Emulator.detect : {:?}", &*yazi_emulator::EMULATOR)?; writeln!(s, "\nAdapter")?; writeln!(s, " Adapter.matches : {:?}", yazi_adapter::ADAPTOR)?; - writeln!(s, " Dimension.available: {:?}", yazi_adapter::Dimension::available())?; + writeln!(s, " Dimension.available: {:?}", yazi_emulator::Dimension::available())?; writeln!(s, "\nDesktop")?; writeln!(s, " XDG_SESSION_TYPE : {:?}", env::var_os("XDG_SESSION_TYPE"))?; @@ -83,7 +83,7 @@ impl Actions { )?; writeln!(s, "\nMultiplexers")?; - writeln!(s, " TMUX : {}", yazi_adapter::TMUX)?; + writeln!(s, " TMUX : {}", yazi_emulator::TMUX)?; writeln!(s, " tmux version : {}", Self::process_output("tmux", "-V"))?; writeln!(s, " tmux build flags : enable-sixel={}", Mux::tmux_sixel_flag())?; writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?; diff --git a/yazi-build/Cargo.toml b/yazi-build/Cargo.toml index 98d00fea..ab72c4b0 100644 --- a/yazi-build/Cargo.toml +++ b/yazi-build/Cargo.toml @@ -18,7 +18,6 @@ panic = "abort" strip = true [build-dependencies] -yazi-term = { path = "../yazi-term", version = "26.1.22" } yazi-tty = { path = "../yazi-tty", version = "26.1.22" } [[bin]] diff --git a/yazi-config/Cargo.toml b/yazi-config/Cargo.toml index 61573e79..bda51c21 100644 --- a/yazi-config/Cargo.toml +++ b/yazi-config/Cargo.toml @@ -16,7 +16,6 @@ yazi-codegen = { path = "../yazi-codegen", version = "26.1.22" } yazi-fs = { path = "../yazi-fs", version = "26.1.22" } yazi-macro = { path = "../yazi-macro", version = "26.1.22" } yazi-shared = { path = "../yazi-shared", version = "26.1.22" } -yazi-term = { path = "../yazi-term", version = "26.1.22" } yazi-tty = { path = "../yazi-tty", version = "26.1.22" } # External dependencies diff --git a/yazi-core/Cargo.toml b/yazi-core/Cargo.toml index 7c4a2ac1..cc64d624 100644 --- a/yazi-core/Cargo.toml +++ b/yazi-core/Cargo.toml @@ -15,6 +15,7 @@ workspace = true yazi-adapter = { path = "../yazi-adapter", version = "26.1.22" } yazi-config = { path = "../yazi-config", version = "26.1.22" } yazi-dds = { path = "../yazi-dds", version = "26.1.22" } +yazi-emulator = { path = "../yazi-emulator", version = "26.1.22" } yazi-fs = { path = "../yazi-fs", version = "26.1.22" } yazi-macro = { path = "../yazi-macro", version = "26.1.22" } yazi-parser = { path = "../yazi-parser", version = "26.1.22" } diff --git a/yazi-core/src/help/help.rs b/yazi-core/src/help/help.rs index 72866681..1cb4a05b 100644 --- a/yazi-core/src/help/help.rs +++ b/yazi-core/src/help/help.rs @@ -1,8 +1,8 @@ use anyhow::Result; use crossterm::{cursor::SetCursorStyle, event::KeyCode}; use unicode_width::UnicodeWidthStr; -use yazi_adapter::Dimension; use yazi_config::{KEYMAP, YAZI, keymap::{Chord, Key}}; +use yazi_emulator::Dimension; use yazi_macro::{act, render, render_and}; use yazi_shared::Layer; use yazi_widgets::Scrollable; diff --git a/yazi-core/src/mgr/mgr.rs b/yazi-core/src/mgr/mgr.rs index 7eae736e..42e2a28b 100644 --- a/yazi-core/src/mgr/mgr.rs +++ b/yazi-core/src/mgr/mgr.rs @@ -1,8 +1,8 @@ use std::iter; use ratatui::layout::Rect; -use yazi_adapter::Dimension; use yazi_config::popup::{Origin, Position}; +use yazi_emulator::Dimension; use yazi_fs::Splatable; use yazi_shared::url::{AsUrl, Url, UrlBuf}; use yazi_watcher::Watcher; diff --git a/yazi-core/src/tab/tab.rs b/yazi-core/src/tab/tab.rs index a7c25901..3050ad2a 100644 --- a/yazi-core/src/tab/tab.rs +++ b/yazi-core/src/tab/tab.rs @@ -1,8 +1,8 @@ use anyhow::Result; use ratatui::layout::Rect; use tokio::task::JoinHandle; -use yazi_adapter::Dimension; use yazi_config::{LAYOUT, popup::{Origin, Position}}; +use yazi_emulator::Dimension; use yazi_fs::File; use yazi_shared::{Id, Ids, url::UrlBuf}; diff --git a/yazi-core/src/tasks/tasks.rs b/yazi-core/src/tasks/tasks.rs index c3a2f973..8cded4af 100644 --- a/yazi-core/src/tasks/tasks.rs +++ b/yazi-core/src/tasks/tasks.rs @@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration}; use parking_lot::Mutex; use tokio::{task::JoinHandle, time::sleep}; -use yazi_adapter::Dimension; +use yazi_emulator::Dimension; use yazi_parser::app::TaskSummary; use yazi_proxy::AppProxy; use yazi_scheduler::{Ongoing, Scheduler, TaskSnap}; diff --git a/yazi-emulator/Cargo.toml b/yazi-emulator/Cargo.toml new file mode 100644 index 00000000..36fb8169 --- /dev/null +++ b/yazi-emulator/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "yazi-emulator" +version = "26.1.22" +edition = "2024" +license = "MIT" +authors = [ "sxyazi " ] +description = "Yazi terminal emulator database" +homepage = "https://yazi-rs.github.io" +repository = "https://github.com/sxyazi/yazi" + +[lints] +workspace = true + +[dependencies] +yazi-macro = { path = "../yazi-macro", version = "26.1.22" } +yazi-shared = { path = "../yazi-shared", version = "26.1.22" } +yazi-tty = { path = "../yazi-tty", version = "26.1.22" } + +# External dependencies +anyhow = { workspace = true } +crossterm = { workspace = true } +scopeguard = { workspace = true } +tokio = { workspace = true } +tracing = { workspace = true } + +[target.'cfg(target_os = "macos")'.dependencies] +crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] } diff --git a/yazi-emulator/README.md b/yazi-emulator/README.md new file mode 100644 index 00000000..c36b858b --- /dev/null +++ b/yazi-emulator/README.md @@ -0,0 +1,5 @@ +# yazi-emulator + +This crate is part of [Yazi][source], and it is not supposed to be used outside, as there are no guarantees about the stability of its API. + +[source]: https://github.com/sxyazi/yazi diff --git a/yazi-adapter/src/brand.rs b/yazi-emulator/src/brand.rs similarity index 100% rename from yazi-adapter/src/brand.rs rename to yazi-emulator/src/brand.rs diff --git a/yazi-adapter/src/dimension.rs b/yazi-emulator/src/dimension.rs similarity index 100% rename from yazi-adapter/src/dimension.rs rename to yazi-emulator/src/dimension.rs diff --git a/yazi-adapter/src/emulator.rs b/yazi-emulator/src/emulator.rs similarity index 98% rename from yazi-adapter/src/emulator.rs rename to yazi-emulator/src/emulator.rs index 6ee8e3fe..d2947dc7 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-emulator/src/emulator.rs @@ -5,11 +5,13 @@ use crossterm::{cursor::{RestorePosition, SavePosition}, execute, style::Print, use scopeguard::defer; use tokio::time::sleep; use tracing::{debug, error, warn}; -use yazi_shared::Either; +use yazi_shared::{Either, RoCell}; use yazi_tty::{Handle, TTY}; use crate::{Brand, Dimension, Mux, TMUX, Unknown}; +pub static EMULATOR: RoCell = RoCell::new(); + #[derive(Clone, Debug)] pub struct Emulator { pub kind: Either, diff --git a/yazi-emulator/src/lib.rs b/yazi-emulator/src/lib.rs new file mode 100644 index 00000000..f2f949fa --- /dev/null +++ b/yazi-emulator/src/lib.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(brand dimension emulator mux unknown); diff --git a/yazi-adapter/src/mux.rs b/yazi-emulator/src/mux.rs similarity index 88% rename from yazi-adapter/src/mux.rs rename to yazi-emulator/src/mux.rs index 3bc396cb..8c1abc57 100644 --- a/yazi-adapter/src/mux.rs +++ b/yazi-emulator/src/mux.rs @@ -3,9 +3,15 @@ use std::borrow::Cow; use anyhow::Result; use tracing::error; use yazi_macro::time; +use yazi_shared::SyncCell; use yazi_tty::TTY; -use crate::{CLOSE, ESCAPE, Emulator, START, TMUX}; +use crate::Emulator; + +pub static TMUX: SyncCell = SyncCell::new(false); +pub static ESCAPE: SyncCell<&'static str> = SyncCell::new("\x1b"); +pub static START: SyncCell<&'static str> = SyncCell::new("\x1b"); +pub static CLOSE: SyncCell<&'static str> = SyncCell::new(""); pub struct Mux; diff --git a/yazi-adapter/src/unknown.rs b/yazi-emulator/src/unknown.rs similarity index 100% rename from yazi-adapter/src/unknown.rs rename to yazi-emulator/src/unknown.rs diff --git a/yazi-fm/Cargo.toml b/yazi-fm/Cargo.toml index 81f34d46..87f7ff9d 100644 --- a/yazi-fm/Cargo.toml +++ b/yazi-fm/Cargo.toml @@ -26,24 +26,25 @@ default = [ "vendored-lua" ] vendored-lua = [ "mlua/vendored" ] [dependencies] -yazi-actor = { path = "../yazi-actor", version = "26.1.22" } -yazi-adapter = { path = "../yazi-adapter", version = "26.1.22" } -yazi-binding = { path = "../yazi-binding", version = "26.1.22" } -yazi-boot = { path = "../yazi-boot", version = "26.1.22" } -yazi-config = { path = "../yazi-config", version = "26.1.22" } -yazi-core = { path = "../yazi-core", version = "26.1.22" } -yazi-dds = { path = "../yazi-dds", version = "26.1.22" } -yazi-fs = { path = "../yazi-fs", version = "26.1.22" } -yazi-macro = { path = "../yazi-macro", version = "26.1.22" } -yazi-parser = { path = "../yazi-parser", version = "26.1.22" } -yazi-plugin = { path = "../yazi-plugin", version = "26.1.22" } -yazi-proxy = { path = "../yazi-proxy", version = "26.1.22" } -yazi-shared = { path = "../yazi-shared", version = "26.1.22" } -yazi-term = { path = "../yazi-term", version = "26.1.22" } -yazi-tty = { path = "../yazi-tty", version = "26.1.22" } -yazi-vfs = { path = "../yazi-vfs", version = "26.1.22" } -yazi-watcher = { path = "../yazi-watcher", version = "26.1.22" } -yazi-widgets = { path = "../yazi-widgets", version = "26.1.22" } +yazi-actor = { path = "../yazi-actor", version = "26.1.22" } +yazi-adapter = { path = "../yazi-adapter", version = "26.1.22" } +yazi-binding = { path = "../yazi-binding", version = "26.1.22" } +yazi-boot = { path = "../yazi-boot", version = "26.1.22" } +yazi-config = { path = "../yazi-config", version = "26.1.22" } +yazi-core = { path = "../yazi-core", version = "26.1.22" } +yazi-dds = { path = "../yazi-dds", version = "26.1.22" } +yazi-emulator = { path = "../yazi-emulator", version = "26.1.22" } +yazi-fs = { path = "../yazi-fs", version = "26.1.22" } +yazi-macro = { path = "../yazi-macro", version = "26.1.22" } +yazi-parser = { path = "../yazi-parser", version = "26.1.22" } +yazi-plugin = { path = "../yazi-plugin", version = "26.1.22" } +yazi-proxy = { path = "../yazi-proxy", version = "26.1.22" } +yazi-shared = { path = "../yazi-shared", version = "26.1.22" } +yazi-term = { path = "../yazi-term", version = "26.1.22" } +yazi-tty = { path = "../yazi-tty", version = "26.1.22" } +yazi-vfs = { path = "../yazi-vfs", version = "26.1.22" } +yazi-watcher = { path = "../yazi-watcher", version = "26.1.22" } +yazi-widgets = { path = "../yazi-widgets", version = "26.1.22" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-fm/src/app/commands/update_notify.rs b/yazi-fm/src/app/commands/update_notify.rs index cb1a5e79..317adff7 100644 --- a/yazi-fm/src/app/commands/update_notify.rs +++ b/yazi-fm/src/app/commands/update_notify.rs @@ -1,6 +1,6 @@ use anyhow::Result; use ratatui::layout::Rect; -use yazi_adapter::Dimension; +use yazi_emulator::Dimension; use yazi_macro::act; use yazi_parser::notify::TickOpt; use yazi_shared::data::Data; diff --git a/yazi-fm/src/cmp/cmp.rs b/yazi-fm/src/cmp/cmp.rs index 9a7376df..db2fad52 100644 --- a/yazi-fm/src/cmp/cmp.rs +++ b/yazi-fm/src/cmp/cmp.rs @@ -1,9 +1,9 @@ use std::path::MAIN_SEPARATOR_STR; use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, List, ListItem, Widget}}; -use yazi_adapter::Dimension; use yazi_config::{THEME, popup::{Offset, Position}}; use yazi_core::Core; +use yazi_emulator::Dimension; use yazi_shared::strand::StrandLike; pub(crate) struct Cmp<'a> { diff --git a/yazi-fm/src/term.rs b/yazi-fm/src/term.rs index 9527d9bd..cf104619 100644 --- a/yazi-fm/src/term.rs +++ b/yazi-fm/src/term.rs @@ -3,8 +3,8 @@ use std::{io, ops::{Deref, DerefMut}, sync::atomic::{AtomicBool, Ordering}}; use anyhow::Result; use crossterm::{event::{DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste, EnableFocusChange, EnableMouseCapture, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags}, execute, queue, style::Print, terminal::{EnterAlternateScreen, LeaveAlternateScreen, SetTitle, disable_raw_mode, enable_raw_mode}}; use ratatui::{CompletedFrame, Frame, Terminal, backend::CrosstermBackend, buffer::Buffer, layout::Rect}; -use yazi_adapter::{Emulator, Mux, TMUX}; use yazi_config::{THEME, YAZI}; +use yazi_emulator::{Emulator, Mux, TMUX}; use yazi_shared::SyncCell; use yazi_tty::{TTY, TtyWriter}; @@ -26,8 +26,8 @@ impl Term { enable_raw_mode()?; static FIRST: SyncCell = SyncCell::new(false); - if FIRST.replace(true) && yazi_adapter::TMUX.get() { - yazi_adapter::Mux::tmux_passthrough(); + if FIRST.replace(true) && yazi_emulator::TMUX.get() { + yazi_emulator::Mux::tmux_passthrough(); } execute!( diff --git a/yazi-parser/Cargo.toml b/yazi-parser/Cargo.toml index b0bd11b1..1a23037d 100644 --- a/yazi-parser/Cargo.toml +++ b/yazi-parser/Cargo.toml @@ -33,5 +33,5 @@ hashbrown = { workspace = true } mlua = { workspace = true } ordered-float = { workspace = true } serde = { workspace = true } -serde_with = { workspace = true } +serde_with = { workspace = true } tokio = { workspace = true } diff --git a/yazi-parser/src/app/notify.rs b/yazi-parser/src/app/notify.rs index 08622b1f..b18ff32a 100644 --- a/yazi-parser/src/app/notify.rs +++ b/yazi-parser/src/app/notify.rs @@ -13,7 +13,7 @@ pub struct NotifyOpt { pub title: String, pub content: String, pub level: NotifyLevel, - #[serde_as(as = "DurationSeconds")] // FIXME + #[serde_as(as = "DurationSeconds")] // FIXME pub timeout: Duration, } diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index a18bfc08..6f430798 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -16,19 +16,20 @@ default = [ "vendored-lua" ] vendored-lua = [ "mlua/vendored" ] [dependencies] -yazi-adapter = { path = "../yazi-adapter", version = "26.1.22" } -yazi-binding = { path = "../yazi-binding", version = "26.1.22" } -yazi-boot = { path = "../yazi-boot", version = "26.1.22" } -yazi-config = { path = "../yazi-config", version = "26.1.22" } -yazi-dds = { path = "../yazi-dds", version = "26.1.22" } -yazi-fs = { path = "../yazi-fs", version = "26.1.22" } -yazi-macro = { path = "../yazi-macro", version = "26.1.22" } -yazi-parser = { path = "../yazi-parser", version = "26.1.22" } -yazi-proxy = { path = "../yazi-proxy", version = "26.1.22" } -yazi-shared = { path = "../yazi-shared", version = "26.1.22" } -yazi-shim = { path = "../yazi-shim", version = "26.1.22" } -yazi-vfs = { path = "../yazi-vfs", version = "26.1.22" } -yazi-widgets = { path = "../yazi-widgets", version = "26.1.22" } +yazi-adapter = { path = "../yazi-adapter", version = "26.1.22" } +yazi-binding = { path = "../yazi-binding", version = "26.1.22" } +yazi-boot = { path = "../yazi-boot", version = "26.1.22" } +yazi-config = { path = "../yazi-config", version = "26.1.22" } +yazi-dds = { path = "../yazi-dds", version = "26.1.22" } +yazi-emulator = { path = "../yazi-emulator", version = "26.1.22" } +yazi-fs = { path = "../yazi-fs", version = "26.1.22" } +yazi-macro = { path = "../yazi-macro", version = "26.1.22" } +yazi-parser = { path = "../yazi-parser", version = "26.1.22" } +yazi-proxy = { path = "../yazi-proxy", version = "26.1.22" } +yazi-shared = { path = "../yazi-shared", version = "26.1.22" } +yazi-shim = { path = "../yazi-shim", version = "26.1.22" } +yazi-vfs = { path = "../yazi-vfs", version = "26.1.22" } +yazi-widgets = { path = "../yazi-widgets", version = "26.1.22" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-plugin/src/runtime/term.rs b/yazi-plugin/src/runtime/term.rs index a4ba61b4..06e47e9d 100644 --- a/yazi-plugin/src/runtime/term.rs +++ b/yazi-plugin/src/runtime/term.rs @@ -1,6 +1,6 @@ use mlua::{Function, IntoLua, IntoLuaMulti, Lua, Value}; -use yazi_adapter::{Dimension, EMULATOR}; use yazi_binding::{Composer, ComposerGet, ComposerSet}; +use yazi_emulator::{Dimension, EMULATOR}; pub(super) fn term() -> Composer { fn get(lua: &Lua, key: &[u8]) -> mlua::Result { diff --git a/yazi-proxy/Cargo.toml b/yazi-proxy/Cargo.toml index b1076daf..dc943d21 100644 --- a/yazi-proxy/Cargo.toml +++ b/yazi-proxy/Cargo.toml @@ -18,5 +18,4 @@ yazi-parser = { path = "../yazi-parser", version = "26.1.22" } yazi-shared = { path = "../yazi-shared", version = "26.1.22" } # External dependencies -anyhow = { workspace = true } tokio = { workspace = true } diff --git a/yazi-term/Cargo.toml b/yazi-term/Cargo.toml index 3199591a..e6147e41 100644 --- a/yazi-term/Cargo.toml +++ b/yazi-term/Cargo.toml @@ -13,12 +13,9 @@ workspace = true [dependencies] yazi-macro = { path = "../yazi-macro", version = "26.1.22" } -yazi-shared = { path = "../yazi-shared", version = "26.1.22" } # External dependencies crossterm = { workspace = true } -parking_lot = { workspace = true } -tracing = { workspace = true } [target."cfg(unix)".dependencies] libc = { workspace = true } diff --git a/yazi-widgets/Cargo.toml b/yazi-widgets/Cargo.toml index 843bff4a..35bcd9b7 100644 --- a/yazi-widgets/Cargo.toml +++ b/yazi-widgets/Cargo.toml @@ -17,7 +17,6 @@ yazi-config = { path = "../yazi-config", version = "26.1.22" } yazi-macro = { path = "../yazi-macro", version = "26.1.22" } yazi-parser = { path = "../yazi-parser", version = "26.1.22" } yazi-shared = { path = "../yazi-shared", version = "26.1.22" } -yazi-term = { path = "../yazi-term", version = "26.1.22" } yazi-tty = { path = "../yazi-tty", version = "26.1.22" } # External dependencies