Skip to content

Commit 23a56c2

Browse files
committed
feat: new extract builtin plugin for archive extracting (#1321)
1 parent f024ce0 commit 23a56c2

Some content is hidden

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

71 files changed

+1436
-571
lines changed

Cargo.lock

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

flake.lock

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

yazi-adapter/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ base64 = "0.22.1"
2020
color_quant = "1.1.0"
2121
crossterm = "0.27.0"
2222
futures = "0.3.30"
23-
image = "=0.24.9"
23+
image = "0.25.2"
2424
imagesize = "0.13.0"
2525
kamadak-exif = "0.5.5"
2626
ratatui = "0.27.0"
2727
scopeguard = "1.2.0"
28-
tokio = { version = "1.39.1", features = [ "full" ] }
28+
tokio = { version = "1.39.2", features = [ "full" ] }
2929

3030
# Logging
3131
tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_level_warn" ] }

yazi-adapter/src/image.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{fs::File, io::BufReader, path::{Path, PathBuf}};
22

33
use anyhow::Result;
44
use exif::{In, Tag};
5-
use image::{codecs::jpeg::JpegEncoder, imageops::{self, FilterType}, io::Limits, DynamicImage};
5+
use image::{codecs::jpeg::JpegEncoder, imageops::{self, FilterType}, DynamicImage, Limits};
66
use ratatui::layout::Rect;
77
use yazi_config::{PREVIEW, TASKS};
88

@@ -16,7 +16,7 @@ impl Image {
1616

1717
let path = path.to_owned();
1818
let mut img = tokio::task::spawn_blocking(move || {
19-
Self::set_limits(image::io::Reader::open(path)?.with_guessed_format()?).decode()
19+
Self::set_limits(image::ImageReader::open(path)?.with_guessed_format()?).decode()
2020
})
2121
.await??;
2222

@@ -54,7 +54,7 @@ impl Image {
5454

5555
let path = path.to_owned();
5656
let mut img = tokio::task::spawn_blocking(move || {
57-
Self::set_limits(image::io::Reader::open(path)?.with_guessed_format()?).decode()
57+
Self::set_limits(image::ImageReader::open(path)?.with_guessed_format()?).decode()
5858
})
5959
.await??;
6060

@@ -155,7 +155,7 @@ impl Image {
155155
img
156156
}
157157

158-
fn set_limits(mut r: image::io::Reader<BufReader<File>>) -> image::io::Reader<BufReader<File>> {
158+
fn set_limits(mut r: image::ImageReader<BufReader<File>>) -> image::ImageReader<BufReader<File>> {
159159
let mut limits = Limits::no_limits();
160160
if TASKS.image_alloc > 0 {
161161
limits.max_alloc = Some(TASKS.image_alloc as u64);

yazi-boot/Cargo.toml

Lines changed: 5 additions & 5 deletions
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.10", features = [ "derive" ] }
18+
clap = { version = "4.5.11", features = [ "derive" ] }
1919
serde = { version = "1.0.204", features = [ "derive" ] }
2020

2121
[build-dependencies]
22-
clap = { version = "4.5.10", features = [ "derive" ] }
23-
clap_complete = "4.5.9"
24-
clap_complete_fig = "4.5.1"
25-
clap_complete_nushell = "4.5.2"
22+
clap = { version = "4.5.11", features = [ "derive" ] }
23+
clap_complete = "4.5.11"
24+
clap_complete_fig = "4.5.2"
25+
clap_complete_nushell = "4.5.3"
2626
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }

yazi-boot/src/actions/debug.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ impl Actions {
4444
writeln!(s, "\nVariables")?;
4545
writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?;
4646
writeln!(s, " EDITOR : {:?}", env::var_os("EDITOR"))?;
47-
writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?;
4847
writeln!(s, " YAZI_FILE_ONE : {:?}", env::var_os("YAZI_FILE_ONE"))?;
4948
writeln!(s, " YAZI_CONFIG_HOME : {:?}", env::var_os("YAZI_CONFIG_HOME"))?;
49+
writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?;
5050

5151
writeln!(s, "\nText Opener")?;
5252
writeln!(
@@ -74,7 +74,8 @@ impl Actions {
7474
writeln!(s, " rg : {}", Self::process_output("rg", "--version"))?;
7575
writeln!(s, " chafa : {}", Self::process_output("chafa", "--version"))?;
7676
writeln!(s, " zoxide : {}", Self::process_output("zoxide", "--version"))?;
77-
writeln!(s, " unar : {}", Self::process_output("unar", "--version"))?;
77+
writeln!(s, " 7z : {}", Self::process_output("7z", "i"))?;
78+
writeln!(s, " 7zz : {}", Self::process_output("7zz", "i"))?;
7879
writeln!(s, " jq : {}", Self::process_output("jq", "--version"))?;
7980

8081
writeln!(s, "\n\n--------------------------------------------------")?;

yazi-cli/Cargo.toml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
1515

1616
# External dependencies
1717
anyhow = "1.0.86"
18-
clap = { version = "4.5.10", features = [ "derive" ] }
18+
clap = { version = "4.5.11", features = [ "derive" ] }
1919
crossterm = "0.27.0"
2020
md-5 = "0.10.6"
21-
serde_json = "1.0.120"
22-
tokio = { version = "1.39.1", features = [ "full" ] }
23-
toml_edit = "0.22.16"
21+
serde_json = "1.0.121"
22+
tokio = { version = "1.39.2", features = [ "full" ] }
23+
toml_edit = "0.22.17"
2424

2525
[build-dependencies]
26+
yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
27+
28+
# External build dependencies
2629
anyhow = "1.0.86"
27-
clap = { version = "4.5.10", features = [ "derive" ] }
28-
clap_complete = "4.5.9"
29-
clap_complete_fig = "4.5.1"
30-
clap_complete_nushell = "4.5.2"
31-
serde_json = "1.0.120"
30+
clap = { version = "4.5.11", features = [ "derive" ] }
31+
clap_complete = "4.5.11"
32+
clap_complete_fig = "4.5.2"
33+
clap_complete_nushell = "4.5.3"
34+
serde_json = "1.0.121"
3235
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }
3336

3437
[target.'cfg(target_os = "macos")'.dependencies]

yazi-cli/src/args.rs

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,67 @@ pub(super) struct Args {
1616

1717
#[derive(Subcommand)]
1818
pub(super) enum Command {
19-
/// Publish a message to remote instance(s).
19+
/// Publish a message to the current instance.
2020
Pub(CommandPub),
21-
/// Manage packages.
22-
Pack(CommandPack),
21+
/// Publish a message to the specified instance.
22+
PubTo(CommandPubTo),
2323
/// Subscribe to messages from all remote instances.
2424
Sub(CommandSub),
25+
/// Manage packages.
26+
Pack(CommandPack),
2527
}
2628

2729
#[derive(clap::Args)]
2830
pub(super) struct CommandPub {
2931
/// The kind of message.
3032
#[arg(index = 1)]
31-
pub(super) kind: String,
32-
/// The receiver ID.
33-
#[arg(index = 2)]
34-
pub(super) receiver: Option<u64>,
33+
pub(super) kind: String,
3534
/// Send the message with a string body.
3635
#[arg(long)]
37-
pub(super) str: Option<String>,
36+
pub(super) str: Option<String>,
3837
/// Send the message with a JSON body.
3938
#[arg(long)]
40-
pub(super) json: Option<String>,
39+
pub(super) json: Option<String>,
40+
/// Send the message as string of list.
41+
#[arg(long, num_args = 0..)]
42+
pub(super) list: Vec<String>,
4143
}
4244

4345
impl CommandPub {
4446
#[allow(dead_code)]
4547
pub(super) fn receiver(&self) -> Result<u64> {
46-
if let Some(receiver) = self.receiver {
47-
Ok(receiver)
48-
} else if let Some(s) = std::env::var("YAZI_PID").ok().filter(|s| !s.is_empty()) {
48+
if let Some(s) = std::env::var("YAZI_PID").ok().filter(|s| !s.is_empty()) {
4949
Ok(s.parse()?)
5050
} else {
51-
bail!("No receiver ID provided, neither YAZI_ID environment variable found.")
51+
bail!("No `YAZI_ID` environment variable found.")
5252
}
5353
}
54+
}
5455

55-
#[allow(dead_code)]
56-
pub(super) fn body(&self) -> Result<Cow<str>> {
57-
if let Some(json) = &self.json {
58-
Ok(json.into())
59-
} else if let Some(str) = &self.str {
60-
Ok(serde_json::to_string(str)?.into())
61-
} else {
62-
Ok("".into())
63-
}
64-
}
56+
#[derive(clap::Args)]
57+
pub(super) struct CommandPubTo {
58+
/// The receiver ID.
59+
#[arg(index = 1)]
60+
pub(super) receiver: u64,
61+
/// The kind of message.
62+
#[arg(index = 2)]
63+
pub(super) kind: String,
64+
/// Send the message with a string body.
65+
#[arg(long)]
66+
pub(super) str: Option<String>,
67+
/// Send the message with a JSON body.
68+
#[arg(long)]
69+
pub(super) json: Option<String>,
70+
/// Send the message as string of list.
71+
#[arg(long, num_args = 0..)]
72+
pub(super) list: Vec<String>,
73+
}
74+
75+
#[derive(clap::Args)]
76+
pub(super) struct CommandSub {
77+
/// The kind of messages to subscribe to, separated by commas if multiple.
78+
#[arg(index = 1)]
79+
pub(super) kinds: String,
6580
}
6681

6782
#[derive(clap::Args)]
@@ -81,9 +96,25 @@ pub(super) struct CommandPack {
8196
pub(super) upgrade: bool,
8297
}
8398

84-
#[derive(clap::Args)]
85-
pub(super) struct CommandSub {
86-
/// The kind of messages to subscribe to, separated by commas if multiple.
87-
#[arg(index = 1)]
88-
pub(super) kinds: String,
99+
// --- Macros
100+
macro_rules! impl_body {
101+
($name:ident) => {
102+
impl $name {
103+
#[allow(dead_code)]
104+
pub(super) fn body(&self) -> Result<Cow<str>> {
105+
if let Some(json) = &self.json {
106+
Ok(json.into())
107+
} else if let Some(str) = &self.str {
108+
Ok(serde_json::to_string(str)?.into())
109+
} else if !self.list.is_empty() {
110+
Ok(serde_json::to_string(&self.list)?.into())
111+
} else {
112+
Ok("".into())
113+
}
114+
}
115+
}
116+
};
89117
}
118+
119+
impl_body!(CommandPub);
120+
impl_body!(CommandPubTo);

yazi-cli/src/main.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ async fn main() -> anyhow::Result<()> {
2525
std::process::exit(1);
2626
}
2727
}
28+
29+
Command::PubTo(cmd) => {
30+
yazi_boot::init_default();
31+
yazi_dds::init();
32+
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await {
33+
eprintln!("Cannot send message: {e}");
34+
std::process::exit(1);
35+
}
36+
}
37+
38+
Command::Sub(cmd) => {
39+
yazi_boot::init_default();
40+
yazi_dds::init();
41+
yazi_dds::Client::draw(cmd.kinds.split(',').collect()).await?;
42+
43+
tokio::signal::ctrl_c().await?;
44+
}
45+
2846
Command::Pack(cmd) => {
2947
package::init();
3048
if cmd.install {
@@ -40,14 +58,6 @@ async fn main() -> anyhow::Result<()> {
4058
package::Package::add_to_config(repo).await?;
4159
}
4260
}
43-
44-
Command::Sub(cmd) => {
45-
yazi_boot::init_default();
46-
yazi_dds::init();
47-
yazi_dds::Client::draw(cmd.kinds.split(',').collect()).await?;
48-
49-
tokio::signal::ctrl_c().await?;
50-
}
5161
}
5262

5363
Ok(())

yazi-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ indexmap = "2.2.6"
2121
ratatui = "0.27.0"
2222
regex = "1.10.5"
2323
serde = { version = "1.0.204", features = [ "derive" ] }
24-
toml = { version = "0.8.15", features = [ "preserve_order" ] }
24+
toml = { version = "0.8.16", features = [ "preserve_order" ] }
2525
validator = { version = "0.18.1", features = [ "derive" ] }
2626

2727
[target.'cfg(target_os = "macos")'.dependencies]

0 commit comments

Comments
 (0)