Skip to content

Commit 5b77bc2

Browse files
committed
feat: support using Yazi in Helix directly without Zellij or tmux
1 parent 31177fd commit 5b77bc2

File tree

25 files changed

+354
-284
lines changed

25 files changed

+354
-284
lines changed

Cargo.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ regex = "1.11.1"
3737
scopeguard = "1.2.0"
3838
serde = { version = "1.0.218", features = [ "derive" ] }
3939
serde_json = "1.0.140"
40-
tokio = { version = "1.43.0", features = [ "full" ] }
40+
tokio = { version = "1.44.0", features = [ "full" ] }
4141
tokio-stream = "0.1.17"
4242
tokio-util = "0.7.13"
4343
toml = { version = "0.8.20" }

cspell.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","Konsole","Überzug","pkgs","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR","libvterm","Uninit"],"flagWords":[],"version":"0.2","language":"en"}
1+
{"version":"0.2","language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","Konsole","Überzug","pkgs","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR","libvterm","Uninit","lockin"]}

yazi-adapter/Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,5 @@ scopeguard = { workspace = true }
2525
tokio = { workspace = true }
2626
tracing = { workspace = true }
2727

28-
[target."cfg(unix)".dependencies]
29-
libc = { workspace = true }
30-
31-
[target.'cfg(windows)'.dependencies]
32-
windows-sys = { version = "0.59.0", features = [ "Win32_Security", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Threading" ] }
33-
3428
[target.'cfg(target_os = "macos")'.dependencies]
3529
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }

yazi-adapter/src/brand.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub enum Brand {
1212
Foot,
1313
Ghostty,
1414
Microsoft,
15+
Warp,
1516
Rio,
1617
BlackBox,
1718
VSCode,
@@ -69,6 +70,7 @@ impl Brand {
6970
"iTerm.app" => return Some(B::Iterm2),
7071
"WezTerm" => return Some(B::WezTerm),
7172
"ghostty" => return Some(B::Ghostty),
73+
"WarpTerminal" => return Some(B::Warp),
7274
"rio" => return Some(B::Rio),
7375
"BlackBox" => return Some(B::BlackBox),
7476
"vscode" => return Some(B::VSCode),
@@ -99,6 +101,7 @@ impl Brand {
99101
B::Foot => &[A::Sixel],
100102
B::Ghostty => &[A::Kgp],
101103
B::Microsoft => &[A::Sixel],
104+
B::Warp => &[],
102105
B::Rio => &[A::Iip, A::Sixel],
103106
B::BlackBox => &[A::Sixel],
104107
B::VSCode => &[A::Iip, A::Sixel],

yazi-adapter/src/drivers/kgp_old.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use core::str;
2-
use std::{io::{LineWriter, Write, stderr}, path::Path};
2+
use std::{io::Write, path::Path};
33

44
use anyhow::Result;
55
use base64::{Engine, engine::general_purpose};
66
use image::DynamicImage;
77
use ratatui::layout::Rect;
8+
use yazi_shared::tty::TTY;
89

910
use crate::{CLOSE, ESCAPE, Emulator, Image, START, adapter::Adapter};
1011

@@ -26,9 +27,9 @@ impl KgpOld {
2627

2728
#[inline]
2829
pub(crate) fn image_erase(_: Rect) -> Result<()> {
29-
let mut stderr = LineWriter::new(stderr());
30-
write!(stderr, "{START}_Gq=2,a=d,d=A{ESCAPE}\\{CLOSE}")?;
31-
stderr.flush()?;
30+
let mut w = TTY.lockout();
31+
write!(w, "{START}_Gq=2,a=d,d=A{ESCAPE}\\{CLOSE}")?;
32+
w.flush()?;
3233
Ok(())
3334
}
3435

yazi-adapter/src/emulator.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use std::{io::{LineWriter, stderr}, time::Duration};
1+
use std::{io::BufWriter, time::Duration};
22

33
use anyhow::Result;
44
use crossterm::{cursor::{RestorePosition, SavePosition}, execute, style::Print, terminal::{disable_raw_mode, enable_raw_mode}};
55
use scopeguard::defer;
66
use tokio::time::sleep;
77
use tracing::{debug, error, warn};
8-
use yazi_shared::Either;
8+
use yazi_shared::{Either, tty::{Handle, TTY}};
99

10-
use crate::{Adapter, AsyncStdin, Brand, Mux, TMUX, Unknown};
10+
use crate::{Adapter, Brand, Mux, TMUX, Unknown};
1111

1212
#[derive(Clone, Copy, Debug)]
1313
pub struct Emulator {
@@ -33,7 +33,7 @@ impl Emulator {
3333
};
3434

3535
execute!(
36-
LineWriter::new(stderr()),
36+
TTY.writer(),
3737
SavePosition,
3838
Print(kgp_seq), // Detect KGP
3939
Print(Mux::csi("\x1b[>q")), // Request terminal version
@@ -75,41 +75,41 @@ impl Emulator {
7575

7676
pub fn move_lock<F, T>((x, y): (u16, u16), cb: F) -> Result<T>
7777
where
78-
F: FnOnce(&mut std::io::BufWriter<std::io::StderrLock>) -> Result<T>,
78+
F: FnOnce(&mut BufWriter<Handle>) -> Result<T>,
7979
{
8080
use std::{io::Write, thread, time::Duration};
8181

8282
use crossterm::{cursor::{Hide, MoveTo, RestorePosition, SavePosition, Show}, queue};
8383

84-
let mut buf = std::io::BufWriter::new(stderr().lock());
84+
let mut w = TTY.lockout();
8585

8686
// I really don't want to add this,
8787
// But tmux and ConPTY sometimes cause the cursor position to get out of sync.
8888
if TMUX.get() || cfg!(windows) {
89-
execute!(buf, SavePosition, MoveTo(x, y), Show)?;
90-
execute!(buf, MoveTo(x, y), Show)?;
91-
execute!(buf, MoveTo(x, y), Show)?;
89+
execute!(w, SavePosition, MoveTo(x, y), Show)?;
90+
execute!(w, MoveTo(x, y), Show)?;
91+
execute!(w, MoveTo(x, y), Show)?;
9292
thread::sleep(Duration::from_millis(1));
9393
} else {
94-
queue!(buf, SavePosition, MoveTo(x, y))?;
94+
queue!(w, SavePosition, MoveTo(x, y))?;
9595
}
9696

97-
let result = cb(&mut buf);
97+
let result = cb(&mut w);
9898
if TMUX.get() || cfg!(windows) {
99-
queue!(buf, Hide, RestorePosition)?;
99+
queue!(w, Hide, RestorePosition)?;
100100
} else {
101-
queue!(buf, RestorePosition)?;
101+
queue!(w, RestorePosition)?;
102102
}
103103

104-
buf.flush()?;
104+
w.flush()?;
105105
result
106106
}
107107

108108
pub fn read_until_da1() -> String {
109109
let now = std::time::Instant::now();
110110
let h = tokio::spawn(Self::error_to_user());
111111

112-
let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(500), |b, buf| {
112+
let (buf, result) = TTY.read_until(Duration::from_millis(500), |b, buf| {
113113
b == b'c'
114114
&& buf.contains(&0x1b)
115115
&& buf.rsplitn(2, |&b| b == 0x1b).next().is_some_and(|s| s.starts_with(b"[?"))
@@ -128,7 +128,7 @@ impl Emulator {
128128

129129
pub fn read_until_dsr() -> String {
130130
let now = std::time::Instant::now();
131-
let (buf, result) = AsyncStdin::default().read_until(Duration::from_millis(100), |b, buf| {
131+
let (buf, result) = TTY.read_until(Duration::from_millis(100), |b, buf| {
132132
b == b'n' && (buf.ends_with(b"\x1b[0n") || buf.ends_with(b"\x1b[3n"))
133133
});
134134

yazi-adapter/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
yazi_macro::mod_pub!(drivers);
44

5-
yazi_macro::mod_flat!(adapter brand dimension emulator image info mux stdin unknown);
5+
yazi_macro::mod_flat!(adapter brand dimension emulator image info mux unknown);
66

77
use yazi_shared::{SyncCell, in_wsl};
88

yazi-adapter/src/mux.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use anyhow::Result;
22
use tracing::error;
33
use yazi_macro::time;
4+
use yazi_shared::tty::TTY;
45

56
use crate::{CLOSE, ESCAPE, Emulator, START, TMUX};
67

@@ -47,7 +48,7 @@ impl Mux {
4748

4849
pub fn tmux_drain() -> Result<()> {
4950
if TMUX.get() {
50-
crossterm::execute!(std::io::stderr(), crossterm::style::Print(Mux::csi("\x1b[5n")))?;
51+
crossterm::execute!(TTY.writer(), crossterm::style::Print(Mux::csi("\x1b[5n")))?;
5152
_ = Emulator::read_until_dsr();
5253
}
5354
Ok(())

yazi-adapter/src/stdin.rs

Lines changed: 0 additions & 174 deletions
This file was deleted.

0 commit comments

Comments
 (0)