Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ regex = "1.11.1"
scopeguard = "1.2.0"
serde = { version = "1.0.218", features = [ "derive" ] }
serde_json = "1.0.140"
tokio = { version = "1.43.0", features = [ "full" ] }
tokio = { version = "1.44.0", features = [ "full" ] }
tokio-stream = "0.1.17"
tokio-util = "0.7.13"
toml = { version = "0.8.20" }
Expand Down
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -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"}
{"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"]}
6 changes: 0 additions & 6 deletions yazi-adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,5 @@ scopeguard = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }

[target."cfg(unix)".dependencies]
libc = { workspace = true }

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59.0", features = [ "Win32_Security", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Threading" ] }

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }
3 changes: 3 additions & 0 deletions yazi-adapter/src/brand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum Brand {
Foot,
Ghostty,
Microsoft,
Warp,
Rio,
BlackBox,
VSCode,
Expand Down Expand Up @@ -69,6 +70,7 @@ impl Brand {
"iTerm.app" => return Some(B::Iterm2),
"WezTerm" => return Some(B::WezTerm),
"ghostty" => return Some(B::Ghostty),
"WarpTerminal" => return Some(B::Warp),
"rio" => return Some(B::Rio),
"BlackBox" => return Some(B::BlackBox),
"vscode" => return Some(B::VSCode),
Expand Down Expand Up @@ -99,6 +101,7 @@ impl Brand {
B::Foot => &[A::Sixel],
B::Ghostty => &[A::Kgp],
B::Microsoft => &[A::Sixel],
B::Warp => &[],
B::Rio => &[A::Iip, A::Sixel],
B::BlackBox => &[A::Sixel],
B::VSCode => &[A::Iip, A::Sixel],
Expand Down
9 changes: 5 additions & 4 deletions yazi-adapter/src/drivers/kgp_old.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use core::str;
use std::{io::{LineWriter, Write, stderr}, path::Path};
use std::{io::Write, path::Path};

use anyhow::Result;
use base64::{Engine, engine::general_purpose};
use image::DynamicImage;
use ratatui::layout::Rect;
use yazi_shared::tty::TTY;

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

Expand All @@ -26,9 +27,9 @@ impl KgpOld {

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

Expand Down
32 changes: 16 additions & 16 deletions yazi-adapter/src/emulator.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::{io::{LineWriter, stderr}, time::Duration};
use std::{io::BufWriter, time::Duration};

use anyhow::Result;
use crossterm::{cursor::{RestorePosition, SavePosition}, execute, style::Print, terminal::{disable_raw_mode, enable_raw_mode}};
use scopeguard::defer;
use tokio::time::sleep;
use tracing::{debug, error, warn};
use yazi_shared::Either;
use yazi_shared::{Either, tty::{Handle, TTY}};

use crate::{Adapter, AsyncStdin, Brand, Mux, TMUX, Unknown};
use crate::{Adapter, Brand, Mux, TMUX, Unknown};

#[derive(Clone, Copy, Debug)]
pub struct Emulator {
Expand All @@ -33,7 +33,7 @@ impl Emulator {
};

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

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

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

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

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

let result = cb(&mut buf);
let result = cb(&mut w);
if TMUX.get() || cfg!(windows) {
queue!(buf, Hide, RestorePosition)?;
queue!(w, Hide, RestorePosition)?;
} else {
queue!(buf, RestorePosition)?;
queue!(w, RestorePosition)?;
}

buf.flush()?;
w.flush()?;
result
}

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion yazi-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

yazi_macro::mod_pub!(drivers);

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

use yazi_shared::{SyncCell, in_wsl};

Expand Down
3 changes: 2 additions & 1 deletion yazi-adapter/src/mux.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use tracing::error;
use yazi_macro::time;
use yazi_shared::tty::TTY;

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

Expand Down Expand Up @@ -47,7 +48,7 @@ impl Mux {

pub fn tmux_drain() -> Result<()> {
if TMUX.get() {
crossterm::execute!(std::io::stderr(), crossterm::style::Print(Mux::csi("\x1b[5n")))?;
crossterm::execute!(TTY.writer(), crossterm::style::Print(Mux::csi("\x1b[5n")))?;
_ = Emulator::read_until_dsr();
}
Ok(())
Expand Down
174 changes: 0 additions & 174 deletions yazi-adapter/src/stdin.rs

This file was deleted.

3 changes: 2 additions & 1 deletion yazi-boot/src/actions/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ impl Actions {
writeln!(s, " Emulator.detect : {:?}", yazi_adapter::EMULATOR)?;

writeln!(s, "\nAdapter")?;
writeln!(s, " Adapter.matches: {:?}", yazi_adapter::ADAPTOR)?;
writeln!(s, " Adapter.matches : {:?}", yazi_adapter::ADAPTOR)?;
writeln!(s, " Dimension.available: {:?}", yazi_adapter::Dimension::available())?;

writeln!(s, "\nDesktop")?;
writeln!(s, " XDG_SESSION_TYPE : {:?}", env::var_os("XDG_SESSION_TYPE"))?;
Expand Down
Loading
Loading