Skip to content

Commit 6c0a482

Browse files
committed
feat: make UI extensions easier (#1257)
1 parent 54eb0cc commit 6c0a482

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1034
-788
lines changed

Cargo.lock

+130-59
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yazi-boot/Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ yazi-config = { path = "../yazi-config", version = "0.2.5" }
1515
yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
1616

1717
# External dependencies
18-
clap = { version = "4.5.7", features = [ "derive" ] }
19-
serde = { version = "1.0.203", features = [ "derive" ] }
18+
clap = { version = "4.5.9", features = [ "derive" ] }
19+
serde = { version = "1.0.204", features = [ "derive" ] }
2020

2121
[build-dependencies]
22-
clap = { version = "4.5.7", features = [ "derive" ] }
23-
clap_complete = "4.5.6"
24-
clap_complete_nushell = "4.5.2"
22+
clap = { version = "4.5.9", features = [ "derive" ] }
23+
clap_complete = "4.5.8"
2524
clap_complete_fig = "4.5.1"
26-
vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] }
25+
clap_complete_nushell = "4.5.2"
26+
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }

yazi-boot/build.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use std::{env, error::Error};
55

66
use clap::CommandFactory;
77
use clap_complete::{generate_to, Shell};
8-
use vergen::EmitBuilder;
8+
use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder};
99

1010
fn main() -> Result<(), Box<dyn Error>> {
11-
EmitBuilder::builder().build_date().git_sha(true).emit()?;
11+
Emitter::default()
12+
.add_instructions(&BuildBuilder::default().build_date(true).build()?)?
13+
.add_instructions(&GitclBuilder::default().commit_date(true).sha(true).build()?)?
14+
.emit()?;
1215

1316
if env::var_os("YAZI_GEN_COMPLETIONS").is_none() {
1417
return Ok(());

yazi-cli/Cargo.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
1414

1515
# External dependencies
1616
anyhow = "1.0.86"
17-
clap = { version = "4.5.7", features = [ "derive" ] }
17+
clap = { version = "4.5.9", features = [ "derive" ] }
1818
crossterm = "0.27.0"
1919
md-5 = "0.10.6"
20-
serde_json = "1.0.117"
20+
serde_json = "1.0.120"
2121
tokio = { version = "1.38.0", features = [ "full" ] }
22-
toml_edit = "0.22.14"
22+
toml_edit = "0.22.15"
2323

2424
[build-dependencies]
2525
anyhow = "1.0.86"
26-
clap = { version = "4.5.7", features = [ "derive" ] }
27-
clap_complete = "4.5.6"
26+
clap = { version = "4.5.9", features = [ "derive" ] }
27+
clap_complete = "4.5.8"
2828
clap_complete_fig = "4.5.1"
2929
clap_complete_nushell = "4.5.2"
30-
serde_json = "1.0.117"
31-
vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] }
30+
serde_json = "1.0.120"
31+
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }
3232

3333
[[bin]]
3434
name = "ya"

yazi-cli/build.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use std::{env, error::Error};
55

66
use clap::CommandFactory;
77
use clap_complete::{generate_to, Shell};
8-
use vergen::EmitBuilder;
8+
use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder};
99

1010
fn main() -> Result<(), Box<dyn Error>> {
11-
EmitBuilder::builder().build_date().git_sha(true).emit()?;
11+
Emitter::default()
12+
.add_instructions(&BuildBuilder::default().build_date(true).build()?)?
13+
.add_instructions(&GitclBuilder::default().commit_date(true).sha(true).build()?)?
14+
.emit()?;
1215

1316
if env::var_os("YAZI_GEN_COMPLETIONS").is_none() {
1417
return Ok(());

yazi-config/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
1414
# External dependencies
1515
anyhow = "1.0.86"
1616
arc-swap = "1.7.1"
17-
bitflags = "2.5.0"
17+
bitflags = "2.6.0"
1818
crossterm = "0.27.0"
1919
globset = "0.4.14"
2020
indexmap = "2.2.6"
2121
ratatui = "0.27.0"
22-
serde = { version = "1.0.203", features = [ "derive" ] }
22+
serde = { version = "1.0.204", features = [ "derive" ] }
2323
toml = { version = "0.8.14", features = [ "preserve_order" ] }
2424
validator = { version = "0.18.1", features = [ "derive" ] }

yazi-config/preset/theme.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,9 @@ conds = [
773773
{ if = "sticky", text = "" },
774774

775775
# Fallback
776-
{ if = "dir", text = "" },
777-
{ if = "exec", text = "" },
778-
{ if = "!dir", text = "" },
776+
{ if = "dir", text = "󰉋" },
777+
{ if = "exec", text = "" },
778+
{ if = "!dir", text = "󰈔" },
779779
]
780780

781781
# : }}}

yazi-config/preset/yazi.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ previewers = [
122122
]
123123

124124
[input]
125-
cursor_blink = true
125+
cursor_blink = false
126126

127127
# cd
128128
cd_title = "Change directory:"

yazi-config/src/layout.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
use ratatui::layout::Rect;
22

3-
#[derive(Default)]
3+
#[derive(Clone, Copy, Default)]
44
pub struct Layout {
5-
pub header: Rect,
6-
7-
pub parent: Rect,
85
pub current: Rect,
96
pub preview: Rect,
10-
11-
pub status: Rect,
127
}

yazi-config/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ pub fn init() -> anyhow::Result<()> {
6161
// TODO: Remove in v0.3.2
6262
for c in &KEYMAP.manager {
6363
for r in &c.run {
64-
if r.name == "shell" && !r.bool("confirm") && !r.bool("interactive") {
64+
if r.name != "shell" {
65+
continue;
66+
}
67+
if !r.bool("confirm") && !r.bool("interactive") {
6568
eprintln!(
6669
r#"WARNING: In Yazi v0.3, the behavior of the interactive `shell` (i.e., shell templates) must be explicitly specified with `--interactive`.
6770
6871
Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` with `shell "my-template" --interactive`, in your keymap.toml"#
6972
);
7073
return Ok(());
74+
} else if r.bool("confirm") && r.bool("interactive") {
75+
eprintln!(
76+
"The `shell` command cannot specify both `--confirm` and `--interactive` at the same time.",
77+
);
7178
}
7279
}
7380
}

yazi-core/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
2020

2121
# External dependencies
2222
anyhow = "1.0.86"
23-
bitflags = "2.5.0"
23+
bitflags = "2.6.0"
2424
crossterm = "0.27.0"
2525
dirs = "5.0.1"
2626
futures = "0.3.30"
@@ -29,7 +29,7 @@ parking_lot = "0.12.3"
2929
ratatui = "0.27.0"
3030
regex = "1.10.5"
3131
scopeguard = "1.2.0"
32-
serde = "1.0.203"
32+
serde = "1.0.204"
3333
shell-words = "1.1.0"
3434
tokio = { version = "1.38.0", features = [ "full" ] }
3535
tokio-stream = "0.1.15"

yazi-dds/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
2020
anyhow = "1.0.86"
2121
mlua = { version = "0.9.9", features = [ "lua54" ] }
2222
parking_lot = "0.12.3"
23-
serde = { version = "1.0.203", features = [ "derive" ] }
24-
serde_json = "1.0.117"
23+
serde = { version = "1.0.204", features = [ "derive" ] }
24+
serde_json = "1.0.120"
2525
tokio = { version = "1.38.0", features = [ "full" ] }
2626
tokio-stream = "0.1.15"
2727
tokio-util = "0.7.11"
2828

2929
[build-dependencies]
30-
vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] }
30+
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }
3131

3232
[target."cfg(unix)".dependencies]
3333
uzers = "0.12.0"

yazi-dds/build.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::error::Error;
22

3-
use vergen::EmitBuilder;
3+
use vergen_gitcl::{Emitter, GitclBuilder};
44

55
fn main() -> Result<(), Box<dyn Error>> {
6-
EmitBuilder::builder().git_sha(true).emit()?;
6+
Emitter::default()
7+
.add_instructions(&GitclBuilder::default().commit_date(true).sha(true).build()?)?
8+
.emit()?;
79

810
Ok(())
911
}

yazi-fm/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ name = "yazi"
5252
path = "src/main.rs"
5353

5454
[package.metadata.binstall]
55-
pkg-url = "{ repo }/releases/download/v{ version }/yazi-{ target }{ archive-suffix }"
56-
bin-dir = "yazi-{ target }/{ bin }{ binary-ext }"
55+
pkg-url = "{repo}/releases/download/v{version}/yazi-{target}{archive-suffix}"
56+
bin-dir = "yazi-{target}/{bin}{binary-ext}"

yazi-fm/src/app/commands/mouse.rs

+27-39
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crossterm::event::{MouseEvent, MouseEventKind};
2-
use mlua::Table;
3-
use ratatui::layout::{Position, Rect};
2+
use mlua::{Table, TableExt};
43
use tracing::error;
5-
use yazi_config::{LAYOUT, MANAGER};
4+
use yazi_config::MANAGER;
65
use yazi_plugin::{bindings::Cast, LUA};
76

8-
use crate::{app::App, components, lives::Lives};
7+
use crate::{app::App, lives::Lives};
98

109
pub struct Opt {
1110
event: MouseEvent,
@@ -19,47 +18,36 @@ impl App {
1918
pub(crate) fn mouse(&mut self, opt: impl Into<Opt>) {
2019
let event = (opt.into() as Opt).event;
2120

22-
let layout = LAYOUT.load();
23-
let position = Position { x: event.column, y: event.row };
21+
let Some(size) = self.term.as_ref().and_then(|t| t.size().ok()) else { return };
22+
let Ok(evt) = yazi_plugin::bindings::MouseEvent::cast(&LUA, event) else { return };
2423

25-
if matches!(event.kind, MouseEventKind::Moved | MouseEventKind::Drag(_)) {
26-
self.mouse_do(crate::Root::mouse, event, None);
27-
return;
28-
}
24+
let res = Lives::scope(&self.cx, move |_| {
25+
let area = yazi_plugin::elements::Rect::cast(&LUA, size)?;
26+
let root = LUA.globals().raw_get::<_, Table>("Root")?.call_method::<_, Table>("new", area)?;
2927

30-
if layout.current.contains(position) {
31-
self.mouse_do(components::Current::mouse, event, Some(layout.current));
32-
} else if layout.preview.contains(position) {
33-
self.mouse_do(components::Preview::mouse, event, Some(layout.preview));
34-
} else if layout.parent.contains(position) {
35-
self.mouse_do(components::Parent::mouse, event, Some(layout.parent));
36-
} else if layout.header.contains(position) {
37-
self.mouse_do(components::Header::mouse, event, Some(layout.header));
38-
} else if layout.status.contains(position) {
39-
self.mouse_do(components::Status::mouse, event, Some(layout.status));
40-
}
41-
}
28+
if matches!(event.kind, MouseEventKind::Down(_) if MANAGER.mouse_events.draggable()) {
29+
root.raw_set("_drag_start", evt.clone())?;
30+
}
31+
32+
match event.kind {
33+
MouseEventKind::Down(_) => root.call_method("click", (evt, false))?,
34+
MouseEventKind::Up(_) => root.call_method("click", (evt, true))?,
4235

43-
fn mouse_do(
44-
&self,
45-
f: impl FnOnce(MouseEvent) -> mlua::Result<()>,
46-
mut event: MouseEvent,
47-
rect: Option<Rect>,
48-
) {
49-
if matches!(event.kind, MouseEventKind::Down(_) if MANAGER.mouse_events.draggable()) {
50-
let evt = yazi_plugin::bindings::MouseEvent::cast(&LUA, event);
51-
if let (Ok(evt), Ok(root)) = (evt, LUA.globals().raw_get::<_, Table>("Root")) {
52-
root.raw_set("drag_start", evt).ok();
36+
MouseEventKind::ScrollDown => root.call_method("scroll", (evt, 1))?,
37+
MouseEventKind::ScrollUp => root.call_method("scroll", (evt, -1))?,
38+
39+
MouseEventKind::ScrollRight => root.call_method("touch", (evt, 1))?,
40+
MouseEventKind::ScrollLeft => root.call_method("touch", (evt, -1))?,
41+
42+
MouseEventKind::Moved => root.call_method("move", evt)?,
43+
MouseEventKind::Drag(_) => root.call_method("drag", evt)?,
5344
}
54-
}
5545

56-
if let Some(rect) = rect {
57-
event.row -= rect.y;
58-
event.column -= rect.x;
59-
}
46+
Ok(())
47+
});
6048

61-
if let Err(e) = Lives::scope(&self.cx, move |_| f(event)) {
62-
error!("{:?}", e);
49+
if let Err(e) = res {
50+
error!("{e}");
6351
}
6452
}
6553
}

yazi-fm/src/components/current.rs

-23
This file was deleted.

yazi-fm/src/components/header.rs

-39
This file was deleted.

yazi-fm/src/components/manager.rs

-20
This file was deleted.

yazi-fm/src/components/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
#![allow(clippy::module_inception)]
22

3-
mod current;
4-
mod header;
5-
mod manager;
6-
mod parent;
73
mod preview;
84
mod progress;
9-
mod status;
105

11-
pub(super) use current::*;
12-
pub(super) use header::*;
13-
pub(super) use manager::*;
14-
pub(super) use parent::*;
156
pub(super) use preview::*;
167
pub(super) use progress::*;
17-
pub(super) use status::*;

0 commit comments

Comments
 (0)