Skip to content

Commit

Permalink
feat: make UI extensions easier (#1257)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Jul 12, 2024
1 parent 54eb0cc commit 5b75a8f
Show file tree
Hide file tree
Showing 63 changed files with 1,015 additions and 778 deletions.
189 changes: 130 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions yazi-boot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ yazi-config = { path = "../yazi-config", version = "0.2.5" }
yazi-shared = { path = "../yazi-shared", version = "0.2.5" }

# External dependencies
clap = { version = "4.5.7", features = [ "derive" ] }
serde = { version = "1.0.203", features = [ "derive" ] }
clap = { version = "4.5.9", features = [ "derive" ] }
serde = { version = "1.0.204", features = [ "derive" ] }

[build-dependencies]
clap = { version = "4.5.7", features = [ "derive" ] }
clap_complete = "4.5.6"
clap_complete_nushell = "4.5.2"
clap = { version = "4.5.9", features = [ "derive" ] }
clap_complete = "4.5.8"
clap_complete_fig = "4.5.1"
vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] }
clap_complete_nushell = "4.5.2"
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }
7 changes: 5 additions & 2 deletions yazi-boot/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ use std::{env, error::Error};

use clap::CommandFactory;
use clap_complete::{generate_to, Shell};
use vergen::EmitBuilder;
use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder};

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

if env::var_os("YAZI_GEN_COMPLETIONS").is_none() {
return Ok(());
Expand Down
14 changes: 7 additions & 7 deletions yazi-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }

# External dependencies
anyhow = "1.0.86"
clap = { version = "4.5.7", features = [ "derive" ] }
clap = { version = "4.5.9", features = [ "derive" ] }
crossterm = "0.27.0"
md-5 = "0.10.6"
serde_json = "1.0.117"
serde_json = "1.0.120"
tokio = { version = "1.38.0", features = [ "full" ] }
toml_edit = "0.22.14"
toml_edit = "0.22.15"

[build-dependencies]
anyhow = "1.0.86"
clap = { version = "4.5.7", features = [ "derive" ] }
clap_complete = "4.5.6"
clap = { version = "4.5.9", features = [ "derive" ] }
clap_complete = "4.5.8"
clap_complete_fig = "4.5.1"
clap_complete_nushell = "4.5.2"
serde_json = "1.0.117"
vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] }
serde_json = "1.0.120"
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }

[[bin]]
name = "ya"
Expand Down
7 changes: 5 additions & 2 deletions yazi-cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ use std::{env, error::Error};

use clap::CommandFactory;
use clap_complete::{generate_to, Shell};
use vergen::EmitBuilder;
use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder};

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

if env::var_os("YAZI_GEN_COMPLETIONS").is_none() {
return Ok(());
Expand Down
4 changes: 2 additions & 2 deletions yazi-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
# External dependencies
anyhow = "1.0.86"
arc-swap = "1.7.1"
bitflags = "2.5.0"
bitflags = "2.6.0"
crossterm = "0.27.0"
globset = "0.4.14"
indexmap = "2.2.6"
ratatui = "0.27.0"
serde = { version = "1.0.203", features = [ "derive" ] }
serde = { version = "1.0.204", features = [ "derive" ] }
toml = { version = "0.8.14", features = [ "preserve_order" ] }
validator = { version = "0.18.1", features = [ "derive" ] }
6 changes: 3 additions & 3 deletions yazi-config/preset/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,9 @@ conds = [
{ if = "sticky", text = "" },

# Fallback
{ if = "dir", text = "" },
{ if = "exec", text = "" },
{ if = "!dir", text = "" },
{ if = "dir", text = "󰉋" },
{ if = "exec", text = "" },
{ if = "!dir", text = "󰈔" },
]

# : }}}
2 changes: 1 addition & 1 deletion yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ previewers = [
]

[input]
cursor_blink = true
cursor_blink = false

# cd
cd_title = "Change directory:"
Expand Down
7 changes: 1 addition & 6 deletions yazi-config/src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use ratatui::layout::Rect;

#[derive(Default)]
#[derive(Clone, Copy, Default)]
pub struct Layout {
pub header: Rect,

pub parent: Rect,
pub current: Rect,
pub preview: Rect,

pub status: Rect,
}
9 changes: 8 additions & 1 deletion yazi-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ pub fn init() -> anyhow::Result<()> {
// TODO: Remove in v0.3.2
for c in &KEYMAP.manager {
for r in &c.run {
if r.name == "shell" && !r.bool("confirm") && !r.bool("interactive") {
if r.name != "shell" {
continue;
}
if !r.bool("confirm") && !r.bool("interactive") {
eprintln!(
r#"WARNING: In Yazi v0.3, the behavior of the interactive `shell` (i.e., shell templates) must be explicitly specified with `--interactive`.
Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` with `shell "my-template" --interactive`, in your keymap.toml"#
);
return Ok(());
} else if r.bool("confirm") && r.bool("interactive") {
eprintln!(
"The `shell` command cannot specify both `--confirm` and `--interactive` at the same time.",
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions yazi-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }

# External dependencies
anyhow = "1.0.86"
bitflags = "2.5.0"
bitflags = "2.6.0"
crossterm = "0.27.0"
dirs = "5.0.1"
futures = "0.3.30"
Expand All @@ -29,7 +29,7 @@ parking_lot = "0.12.3"
ratatui = "0.27.0"
regex = "1.10.5"
scopeguard = "1.2.0"
serde = "1.0.203"
serde = "1.0.204"
shell-words = "1.1.0"
tokio = { version = "1.38.0", features = [ "full" ] }
tokio-stream = "0.1.15"
Expand Down
6 changes: 3 additions & 3 deletions yazi-dds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
anyhow = "1.0.86"
mlua = { version = "0.9.9", features = [ "lua54" ] }
parking_lot = "0.12.3"
serde = { version = "1.0.203", features = [ "derive" ] }
serde_json = "1.0.117"
serde = { version = "1.0.204", features = [ "derive" ] }
serde_json = "1.0.120"
tokio = { version = "1.38.0", features = [ "full" ] }
tokio-stream = "0.1.15"
tokio-util = "0.7.11"

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

[target."cfg(unix)".dependencies]
uzers = "0.12.0"
6 changes: 4 additions & 2 deletions yazi-dds/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::error::Error;

use vergen::EmitBuilder;
use vergen_gitcl::{Emitter, GitclBuilder};

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

Ok(())
}
4 changes: 2 additions & 2 deletions yazi-fm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ name = "yazi"
path = "src/main.rs"

[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/v{ version }/yazi-{ target }{ archive-suffix }"
bin-dir = "yazi-{ target }/{ bin }{ binary-ext }"
pkg-url = "{repo}/releases/download/v{version}/yazi-{target}{archive-suffix}"
bin-dir = "yazi-{target}/{bin}{binary-ext}"
66 changes: 27 additions & 39 deletions yazi-fm/src/app/commands/mouse.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crossterm::event::{MouseEvent, MouseEventKind};
use mlua::Table;
use ratatui::layout::{Position, Rect};
use mlua::{Table, TableExt};
use tracing::error;
use yazi_config::{LAYOUT, MANAGER};
use yazi_config::MANAGER;
use yazi_plugin::{bindings::Cast, LUA};

use crate::{app::App, components, lives::Lives};
use crate::{app::App, lives::Lives};

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

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

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

if layout.current.contains(position) {
self.mouse_do(components::Current::mouse, event, Some(layout.current));
} else if layout.preview.contains(position) {
self.mouse_do(components::Preview::mouse, event, Some(layout.preview));
} else if layout.parent.contains(position) {
self.mouse_do(components::Parent::mouse, event, Some(layout.parent));
} else if layout.header.contains(position) {
self.mouse_do(components::Header::mouse, event, Some(layout.header));
} else if layout.status.contains(position) {
self.mouse_do(components::Status::mouse, event, Some(layout.status));
}
}
if matches!(event.kind, MouseEventKind::Down(_) if MANAGER.mouse_events.draggable()) {
root.raw_set("_drag_start", evt.clone())?;
}

match event.kind {
MouseEventKind::Down(_) => root.call_method("click", (evt, false))?,
MouseEventKind::Up(_) => root.call_method("click", (evt, true))?,

fn mouse_do(
&self,
f: impl FnOnce(MouseEvent) -> mlua::Result<()>,
mut event: MouseEvent,
rect: Option<Rect>,
) {
if matches!(event.kind, MouseEventKind::Down(_) if MANAGER.mouse_events.draggable()) {
let evt = yazi_plugin::bindings::MouseEvent::cast(&LUA, event);
if let (Ok(evt), Ok(root)) = (evt, LUA.globals().raw_get::<_, Table>("Root")) {
root.raw_set("drag_start", evt).ok();
MouseEventKind::ScrollDown => root.call_method("scroll", (evt, 1))?,
MouseEventKind::ScrollUp => root.call_method("scroll", (evt, -1))?,

MouseEventKind::ScrollRight => root.call_method("touch", (evt, 1))?,
MouseEventKind::ScrollLeft => root.call_method("touch", (evt, -1))?,

MouseEventKind::Moved => root.call_method("move", evt)?,
MouseEventKind::Drag(_) => root.call_method("drag", evt)?,
}
}

if let Some(rect) = rect {
event.row -= rect.y;
event.column -= rect.x;
}
Ok(())
});

if let Err(e) = Lives::scope(&self.cx, move |_| f(event)) {
error!("{:?}", e);
if let Err(e) = res {
error!("{e}");
}
}
}
23 changes: 0 additions & 23 deletions yazi-fm/src/components/current.rs

This file was deleted.

39 changes: 0 additions & 39 deletions yazi-fm/src/components/header.rs

This file was deleted.

20 changes: 0 additions & 20 deletions yazi-fm/src/components/manager.rs

This file was deleted.

10 changes: 0 additions & 10 deletions yazi-fm/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
#![allow(clippy::module_inception)]

mod current;
mod header;
mod manager;
mod parent;
mod preview;
mod progress;
mod status;

pub(super) use current::*;
pub(super) use header::*;
pub(super) use manager::*;
pub(super) use parent::*;
pub(super) use preview::*;
pub(super) use progress::*;
pub(super) use status::*;
Loading

0 comments on commit 5b75a8f

Please sign in to comment.