Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into add_tar_lua
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkFi committed Sep 3, 2024
2 parents 9a4bfbb + ff04e2d commit 49b6e77
Show file tree
Hide file tree
Showing 28 changed files with 190 additions and 134 deletions.
134 changes: 69 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ panic = "abort"
strip = true

[workspace.dependencies]
ansi-to-tui = "5.0.0-rc.1"
ansi-to-tui = "6.0.0"
anyhow = "1.0.86"
arc-swap = "1.7.1"
base64 = "0.22.1"
bitflags = "2.6.0"
clap = { version = "4.5.16", features = [ "derive" ] }
crossterm = { version = "0.27.0", features = [ "event-stream" ] }
crossterm = { version = "0.28.1", features = [ "event-stream" ] }
dirs = "5.0.1"
futures = "0.3.30"
globset = "0.4.14"
libc = "0.2.158"
md-5 = "0.10.6"
mlua = { version = "0.9.9", features = [ "lua54", "serialize", "macros", "async" ] }
parking_lot = "0.12.3"
ratatui = { version = "0.27.0", features = [ "unstable-rendered-line-info" ] }
ratatui = { version = "0.28.1", features = [ "unstable-rendered-line-info" ] }
regex = "1.10.6"
scopeguard = "1.2.0"
serde = { version = "1.0.209", features = [ "derive" ] }
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@ https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265

## Image Preview

| Platform | Protocol | Support |
| ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [kitty](https://github.com/kovidgoyal/kitty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in |
| [Konsole](https://invent.kde.org/utilities/konsole) | [Kitty old protocol](https://github.com/sxyazi/yazi/blob/main/yazi-adapter/src/kitty_old.rs) | ✅ Built-in |
| [iTerm2](https://iterm2.com) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [WezTerm](https://github.com/wez/wezterm) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Mintty](https://github.com/mintty/mintty) (Git Bash) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [foot](https://codeberg.org/dnkl/foot) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| [Ghostty](https://mitchellh.com/ghostty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in |
| [Black Box](https://gitlab.gnome.org/raggesilver/blackbox) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| [VSCode](https://github.com/microsoft/vscode) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Tabby](https://github.com/Eugeny/tabby) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Hyper](https://github.com/vercel/hyper) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| X11 / Wayland | Window system protocol | ☑️ [Überzug++](https://github.com/jstkdng/ueberzugpp) required |
| Fallback | [ASCII art (Unicode block)](https://en.wikipedia.org/wiki/ASCII_art) | ☑️ [Chafa](https://hpjansson.org/chafa/) required |
| Platform | Protocol | Support |
| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [kitty](https://github.com/kovidgoyal/kitty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in |
| [Konsole](https://invent.kde.org/utilities/konsole) | [Kitty old protocol](https://github.com/sxyazi/yazi/blob/main/yazi-adapter/src/kitty_old.rs) | ✅ Built-in |
| [iTerm2](https://iterm2.com) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [WezTerm](https://github.com/wez/wezterm) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Mintty](https://github.com/mintty/mintty) (Git Bash) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [foot](https://codeberg.org/dnkl/foot) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| [Ghostty](https://mitchellh.com/ghostty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in |
| [Windows Terminal](https://github.com/microsoft/terminal) (>= v1.22.2362.0) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| [Black Box](https://gitlab.gnome.org/raggesilver/blackbox) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| [VSCode](https://github.com/microsoft/vscode) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Tabby](https://github.com/Eugeny/tabby) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| [Hyper](https://github.com/vercel/hyper) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| X11 / Wayland | Window system protocol | ☑️ [Überzug++](https://github.com/jstkdng/ueberzugpp) required |
| Fallback | [ASCII art (Unicode block)](https://en.wikipedia.org/wiki/ASCII_art) | ☑️ [Chafa](https://hpjansson.org/chafa/) required |

See https://yazi-rs.github.io/docs/image-preview for details.

Expand Down
2 changes: 1 addition & 1 deletion yazi-adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ tokio = { workspace = true }
tracing = { workspace = true }

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty" ] }
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }
7 changes: 6 additions & 1 deletion yazi-adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ impl Adapter {

impl Adapter {
pub fn matches() -> Self {
let mut protocols = Emulator::detect().adapters();
let emulator = Emulator::detect();
#[cfg(windows)]
if matches!(emulator, Emulator::Microsoft) {
return Self::Sixel;
}

let mut protocols = emulator.adapters();
#[cfg(windows)]
protocols.retain(|p| *p == Self::Iterm2);
if env_exists("ZELLIJ_SESSION_NAME") {
Expand Down
3 changes: 3 additions & 0 deletions yazi-adapter/src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Emulator {
WezTerm,
Foot,
Ghostty,
Microsoft,
BlackBox,
VSCode,
Tabby,
Expand All @@ -38,6 +39,7 @@ impl Emulator {
Self::WezTerm => vec![Adapter::Iterm2, Adapter::Sixel],
Self::Foot => vec![Adapter::Sixel],
Self::Ghostty => vec![Adapter::Kitty],
Self::Microsoft => vec![Adapter::Sixel],
Self::BlackBox => vec![Adapter::Sixel],
Self::VSCode => vec![Adapter::Iterm2, Adapter::Sixel],
Self::Tabby => vec![Adapter::Iterm2, Adapter::Sixel],
Expand All @@ -62,6 +64,7 @@ impl Emulator {
("ITERM_SESSION_ID", Self::Iterm2),
("WEZTERM_EXECUTABLE", Self::WezTerm),
("GHOSTTY_RESOURCES_DIR", Self::Ghostty),
("WT_Session", Self::Microsoft),
("VSCODE_INJECTION", Self::VSCode),
("TABBY_CONFIG_DIRECTORY", Self::Tabby),
];
Expand Down
2 changes: 1 addition & 1 deletion yazi-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ serde_json = { workspace = true }
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty" ] }
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }

[[bin]]
name = "ya"
Expand Down
2 changes: 1 addition & 1 deletion yazi-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ toml = { version = "0.8.19", features = [ "preserve_order" ] }
validator = { version = "0.18.1", features = [ "derive" ] }

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty" ] }
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }
35 changes: 25 additions & 10 deletions yazi-config/src/popup/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@ impl ConfirmCfg {

pub fn trash(urls: &[yazi_shared::fs::Url]) -> Self {
Self::new(
Self::replace_number(&CONFIRM.trash_title, urls.len(), usize::MAX),
Self::replace_number(&CONFIRM.trash_title, urls.len()),
(CONFIRM.trash_origin, CONFIRM.trash_offset),
None,
Some(urls.iter().map(ToString::to_string).collect()),
Self::truncate_list(urls.iter(), urls.len(), 100),
)
}

pub fn delete(urls: &[yazi_shared::fs::Url]) -> Self {
Self::new(
Self::replace_number(&CONFIRM.delete_title, urls.len(), usize::MAX),
Self::replace_number(&CONFIRM.delete_title, urls.len()),
(CONFIRM.delete_origin, CONFIRM.delete_offset),
None,
Some(urls.iter().map(ToString::to_string).collect()),
Self::truncate_list(urls.iter(), urls.len(), 100),
)
}

Expand All @@ -146,18 +146,33 @@ impl ConfirmCfg {
)
}

pub fn quit(left: Vec<String>) -> Self {
pub fn quit(len: usize, names: Vec<String>) -> Self {
Self::new(
Self::replace_number(&CONFIRM.quit_title, left.len(), 10),
Self::replace_number(&CONFIRM.quit_title, len),
(CONFIRM.quit_origin, CONFIRM.quit_offset),
Some(Text::raw(&CONFIRM.quit_content)),
Some(left.into_iter().collect()),
Self::truncate_list(names.into_iter(), len, 10),
)
}

fn replace_number(tpl: &str, n: usize, max: usize) -> String {
let s = tpl.replace("{s}", if n > 1 { "s" } else { "" });
s.replace("{n}", &if n > max { format!("{max}+") } else { n.to_string() })
fn replace_number(tpl: &str, n: usize) -> String {
tpl.replace("{n}", &n.to_string()).replace("{s}", if n > 1 { "s" } else { "" })
}

fn truncate_list(
it: impl Iterator<Item = impl Into<String>>,
len: usize,
max: usize,
) -> Option<Text<'static>> {
let mut lines = Vec::with_capacity(len.min(max + 1));
for (i, s) in it.enumerate() {
if i >= max {
lines.push(format!("... and {} more", len - max));
break;
}
lines.push(s.into());
}
Some(Text::from_iter(lines))
}
}

Expand Down
2 changes: 1 addition & 1 deletion yazi-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ unicode-width = { workspace = true }
libc = { workspace = true }

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty" ] }
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }
9 changes: 6 additions & 3 deletions yazi-core/src/manager/commands/quit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ impl Manager {
let opt = EventQuit { no_cwd_file: opt.into().no_cwd_file, ..Default::default() };

let ongoing = tasks.ongoing().clone();
let left: Vec<String> = ongoing.lock().values().take(11).map(|t| t.name.clone()).collect();
let (left, left_names) = {
let ongoing = ongoing.lock();
(ongoing.len(), ongoing.values().take(11).map(|t| t.name.clone()).collect())
};

if left.is_empty() {
if left == 0 {
emit!(Quit(opt));
return;
}

tokio::spawn(async move {
let mut i = 0;
let mut rx = ConfirmProxy::show_rx(ConfirmCfg::quit(left));
let mut rx = ConfirmProxy::show_rx(ConfirmCfg::quit(left, left_names));
loop {
select! {
_ = time::sleep(Duration::from_millis(100)) => {
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/manager/commands/tab_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Tabs {
}

let opt = opt.into() as Opt;
let mut tab = Tab::default();
let mut tab = Tab { idx: self.cursor + 1, ..Default::default() };

if !opt.current {
tab.cd(opt.url);
Expand Down
6 changes: 3 additions & 3 deletions yazi-core/src/tab/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub struct Tab {
pub history: HashMap<Url, Folder>,
pub selected: Selected,

pub preview: Preview,
pub finder: Option<Finder>,
pub(super) search: Option<JoinHandle<Result<()>>>,
pub preview: Preview,
pub finder: Option<Finder>,
pub search: Option<JoinHandle<Result<()>>>,
}

impl Tab {
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ libc = { workspace = true }
signal-hook-tokio = { version = "0.3.1", features = [ "futures-v0_3" ] }

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty" ] }
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }

[target.'cfg(all(not(target_os = "macos"), not(target_os = "windows")))'.dependencies]
tikv-jemallocator = "0.6.0"
Expand Down
22 changes: 11 additions & 11 deletions yazi-fm/src/app/commands/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ impl App {
let collision = COLLISION.swap(false, Ordering::Relaxed);
let frame = term
.draw(|f| {
_ = Lives::scope(&self.cx, |_| Ok(f.render_widget(Root::new(&self.cx), f.size())));
_ = Lives::scope(&self.cx, |_| Ok(f.render_widget(Root::new(&self.cx), f.area())));

if let Some((x, y)) = self.cx.cursor() {
f.set_cursor(x, y);
if let Some(pos) = self.cx.cursor() {
f.set_cursor_position(pos);
}
})
.unwrap();
Expand Down Expand Up @@ -51,10 +51,10 @@ impl App {

let frame = term
.draw_partial(|f| {
f.render_widget(crate::notify::Layout::new(&self.cx), f.size());
f.render_widget(crate::notify::Layout::new(&self.cx), f.area());

if let Some((x, y)) = self.cx.cursor() {
f.set_cursor(x, y);
if let Some(pos) = self.cx.cursor() {
f.set_cursor_position(pos);
}
})
.unwrap();
Expand All @@ -69,20 +69,20 @@ impl App {
let mut new = Buffer::empty(frame.area);
for y in new.area.top()..new.area.bottom() {
for x in new.area.left()..new.area.right() {
let cell = frame.buffer.get(x, y);
let cell = &frame.buffer[(x, y)];
if cell.skip {
*new.get_mut(x, y) = cell.clone();
new[(x, y)] = cell.clone();
}
new.get_mut(x, y).set_skip(!cell.skip);
new[(x, y)].set_skip(!cell.skip);
}
}

let patches = frame.buffer.diff(&new);
let mut backend = CrosstermBackend::new(BufWriter::new(stderr().lock()));
backend.draw(patches.into_iter()).ok();
if let Some((x, y)) = cursor {
if let Some(pos) = cursor {
backend.show_cursor().ok();
backend.set_cursor(x, y).ok();
backend.set_cursor_position(pos).ok();
}
backend.flush().ok();
}
Expand Down
4 changes: 2 additions & 2 deletions yazi-fm/src/app/commands/update_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ impl App {
_ = Lives::scope(&self.cx, |_| {
for patch in Progress::partial_render(term.current_buffer_mut()) {
term.backend_mut().draw(patch.iter().map(|(x, y, cell)| (*x, *y, cell)))?;
if let Some((x, y)) = self.cx.cursor() {
if let Some(pos) = self.cx.cursor() {
term.show_cursor()?;
term.set_cursor(x, y)?;
term.set_cursor_position(pos)?;
}
term.backend_mut().flush()?;
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-fm/src/components/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Progress {
let mut patch = Vec::with_capacity(area.width as usize * area.height as usize);
for y in area.top()..area.bottom() {
for x in area.left()..area.right() {
patch.push((x, y, mem::take(buf.get_mut(x, y))));
patch.push((x, y, mem::take(&mut buf[(x, y)])));
}
}

Expand Down
4 changes: 4 additions & 0 deletions yazi-fm/src/lives/tab.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ops::Deref;

use mlua::{AnyUserData, Lua, UserDataFields, UserDataMethods};
use yazi_plugin::url::UrlRef;

use super::{Config, Finder, Folder, Mode, Preview, Selected, SCOPE};

Expand Down Expand Up @@ -41,6 +42,9 @@ impl Tab {
me.parent.as_ref().map(|f| Folder::make(None, f, me)).transpose()
});

reg.add_method("history", |_, me, url: UrlRef| {
me.history.get(&url).map(|f| Folder::make(None, f, me)).transpose()
});
reg.add_field_method_get("selected", |_, me| Selected::make(&me.selected));

reg.add_field_method_get("preview", |_, me| Preview::make(me));
Expand Down
6 changes: 3 additions & 3 deletions yazi-fm/src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ impl Term {
let buffer = frame.buffer_mut();
for y in self.last_area.top()..self.last_area.bottom() {
for x in self.last_area.left()..self.last_area.right() {
let mut cell = self.last_buffer.get(x, y).clone();
let mut cell = self.last_buffer[(x, y)].clone();
cell.skip = false;
*buffer.get_mut(x, y) = cell;
buffer[(x, y)] = cell;
}
}

Expand All @@ -130,7 +130,7 @@ impl Term {

#[inline]
pub(super) fn can_partial(&mut self) -> bool {
self.inner.autoresize().is_ok() && self.last_area == self.inner.get_frame().size()
self.inner.autoresize().is_ok() && self.last_area == self.inner.get_frame().area()
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ uzers = { workspace = true }
clipboard-win = "5.4.0"

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { workspace = true, features = [ "use-dev-tty" ] }
crossterm = { workspace = true, features = [ "use-dev-tty", "libc" ] }
7 changes: 6 additions & 1 deletion yazi-plugin/preset/components/linemode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ end

function Linemode:size()
local size = self._file:size()
return ui.Line(size and ya.readable_size(size) or "")
if size then
return ui.Line(ya.readable_size(size))
else
local folder = cx.active:history(self._file.url)
return ui.Line(folder and tostring(#folder.files) or "")
end
end

function Linemode:ctime()
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/src/bindings/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl<'lua, T> IntoLua<'lua> for Range<T>
where
T: IntoLua<'lua>,
{
fn into_lua(self, lua: &'lua mlua::Lua) -> mlua::Result<mlua::Value> {
fn into_lua(self, lua: &'lua mlua::Lua) -> mlua::Result<mlua::Value<'lua>> {
lua.create_sequence_from([self.0.start, self.0.end])?.into_lua(lua)
}
}
Loading

0 comments on commit 49b6e77

Please sign in to comment.