Skip to content

Commit

Permalink
feat: new extract builtin plugin for archive extracting (#1321)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Jul 31, 2024
1 parent f024ce0 commit 23a56c2
Show file tree
Hide file tree
Showing 71 changed files with 1,436 additions and 571 deletions.
525 changes: 457 additions & 68 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions flake.lock

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

4 changes: 2 additions & 2 deletions yazi-adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ base64 = "0.22.1"
color_quant = "1.1.0"
crossterm = "0.27.0"
futures = "0.3.30"
image = "=0.24.9"
image = "0.25.2"
imagesize = "0.13.0"
kamadak-exif = "0.5.5"
ratatui = "0.27.0"
scopeguard = "1.2.0"
tokio = { version = "1.39.1", features = [ "full" ] }
tokio = { version = "1.39.2", features = [ "full" ] }

# Logging
tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_level_warn" ] }
Expand Down
8 changes: 4 additions & 4 deletions yazi-adapter/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fs::File, io::BufReader, path::{Path, PathBuf}};

use anyhow::Result;
use exif::{In, Tag};
use image::{codecs::jpeg::JpegEncoder, imageops::{self, FilterType}, io::Limits, DynamicImage};
use image::{codecs::jpeg::JpegEncoder, imageops::{self, FilterType}, DynamicImage, Limits};
use ratatui::layout::Rect;
use yazi_config::{PREVIEW, TASKS};

Expand All @@ -16,7 +16,7 @@ impl Image {

let path = path.to_owned();
let mut img = tokio::task::spawn_blocking(move || {
Self::set_limits(image::io::Reader::open(path)?.with_guessed_format()?).decode()
Self::set_limits(image::ImageReader::open(path)?.with_guessed_format()?).decode()
})
.await??;

Expand Down Expand Up @@ -54,7 +54,7 @@ impl Image {

let path = path.to_owned();
let mut img = tokio::task::spawn_blocking(move || {
Self::set_limits(image::io::Reader::open(path)?.with_guessed_format()?).decode()
Self::set_limits(image::ImageReader::open(path)?.with_guessed_format()?).decode()
})
.await??;

Expand Down Expand Up @@ -155,7 +155,7 @@ impl Image {
img
}

fn set_limits(mut r: image::io::Reader<BufReader<File>>) -> image::io::Reader<BufReader<File>> {
fn set_limits(mut r: image::ImageReader<BufReader<File>>) -> image::ImageReader<BufReader<File>> {
let mut limits = Limits::no_limits();
if TASKS.image_alloc > 0 {
limits.max_alloc = Some(TASKS.image_alloc as u64);
Expand Down
10 changes: 5 additions & 5 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.10", features = [ "derive" ] }
clap = { version = "4.5.11", features = [ "derive" ] }
serde = { version = "1.0.204", features = [ "derive" ] }

[build-dependencies]
clap = { version = "4.5.10", features = [ "derive" ] }
clap_complete = "4.5.9"
clap_complete_fig = "4.5.1"
clap_complete_nushell = "4.5.2"
clap = { version = "4.5.11", features = [ "derive" ] }
clap_complete = "4.5.11"
clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.3"
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }
5 changes: 3 additions & 2 deletions yazi-boot/src/actions/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ impl Actions {
writeln!(s, "\nVariables")?;
writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?;
writeln!(s, " EDITOR : {:?}", env::var_os("EDITOR"))?;
writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?;
writeln!(s, " YAZI_FILE_ONE : {:?}", env::var_os("YAZI_FILE_ONE"))?;
writeln!(s, " YAZI_CONFIG_HOME : {:?}", env::var_os("YAZI_CONFIG_HOME"))?;
writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?;

writeln!(s, "\nText Opener")?;
writeln!(
Expand Down Expand Up @@ -74,7 +74,8 @@ impl Actions {
writeln!(s, " rg : {}", Self::process_output("rg", "--version"))?;
writeln!(s, " chafa : {}", Self::process_output("chafa", "--version"))?;
writeln!(s, " zoxide : {}", Self::process_output("zoxide", "--version"))?;
writeln!(s, " unar : {}", Self::process_output("unar", "--version"))?;
writeln!(s, " 7z : {}", Self::process_output("7z", "i"))?;
writeln!(s, " 7zz : {}", Self::process_output("7zz", "i"))?;
writeln!(s, " jq : {}", Self::process_output("jq", "--version"))?;

writeln!(s, "\n\n--------------------------------------------------")?;
Expand Down
21 changes: 12 additions & 9 deletions yazi-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }

# External dependencies
anyhow = "1.0.86"
clap = { version = "4.5.10", features = [ "derive" ] }
clap = { version = "4.5.11", features = [ "derive" ] }
crossterm = "0.27.0"
md-5 = "0.10.6"
serde_json = "1.0.120"
tokio = { version = "1.39.1", features = [ "full" ] }
toml_edit = "0.22.16"
serde_json = "1.0.121"
tokio = { version = "1.39.2", features = [ "full" ] }
toml_edit = "0.22.17"

[build-dependencies]
yazi-shared = { path = "../yazi-shared", version = "0.2.5" }

# External build dependencies
anyhow = "1.0.86"
clap = { version = "4.5.10", features = [ "derive" ] }
clap_complete = "4.5.9"
clap_complete_fig = "4.5.1"
clap_complete_nushell = "4.5.2"
serde_json = "1.0.120"
clap = { version = "4.5.11", features = [ "derive" ] }
clap_complete = "4.5.11"
clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.3"
serde_json = "1.0.121"
vergen-gitcl = { version = "1.0.0", features = [ "build" ] }

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
87 changes: 59 additions & 28 deletions yazi-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,67 @@ pub(super) struct Args {

#[derive(Subcommand)]
pub(super) enum Command {
/// Publish a message to remote instance(s).
/// Publish a message to the current instance.
Pub(CommandPub),
/// Manage packages.
Pack(CommandPack),
/// Publish a message to the specified instance.
PubTo(CommandPubTo),
/// Subscribe to messages from all remote instances.
Sub(CommandSub),
/// Manage packages.
Pack(CommandPack),
}

#[derive(clap::Args)]
pub(super) struct CommandPub {
/// The kind of message.
#[arg(index = 1)]
pub(super) kind: String,
/// The receiver ID.
#[arg(index = 2)]
pub(super) receiver: Option<u64>,
pub(super) kind: String,
/// Send the message with a string body.
#[arg(long)]
pub(super) str: Option<String>,
pub(super) str: Option<String>,
/// Send the message with a JSON body.
#[arg(long)]
pub(super) json: Option<String>,
pub(super) json: Option<String>,
/// Send the message as string of list.
#[arg(long, num_args = 0..)]
pub(super) list: Vec<String>,
}

impl CommandPub {
#[allow(dead_code)]
pub(super) fn receiver(&self) -> Result<u64> {
if let Some(receiver) = self.receiver {
Ok(receiver)
} else if let Some(s) = std::env::var("YAZI_PID").ok().filter(|s| !s.is_empty()) {
if let Some(s) = std::env::var("YAZI_PID").ok().filter(|s| !s.is_empty()) {
Ok(s.parse()?)
} else {
bail!("No receiver ID provided, neither YAZI_ID environment variable found.")
bail!("No `YAZI_ID` environment variable found.")
}
}
}

#[allow(dead_code)]
pub(super) fn body(&self) -> Result<Cow<str>> {
if let Some(json) = &self.json {
Ok(json.into())
} else if let Some(str) = &self.str {
Ok(serde_json::to_string(str)?.into())
} else {
Ok("".into())
}
}
#[derive(clap::Args)]
pub(super) struct CommandPubTo {
/// The receiver ID.
#[arg(index = 1)]
pub(super) receiver: u64,
/// The kind of message.
#[arg(index = 2)]
pub(super) kind: String,
/// Send the message with a string body.
#[arg(long)]
pub(super) str: Option<String>,
/// Send the message with a JSON body.
#[arg(long)]
pub(super) json: Option<String>,
/// Send the message as string of list.
#[arg(long, num_args = 0..)]
pub(super) list: Vec<String>,
}

#[derive(clap::Args)]
pub(super) struct CommandSub {
/// The kind of messages to subscribe to, separated by commas if multiple.
#[arg(index = 1)]
pub(super) kinds: String,
}

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

#[derive(clap::Args)]
pub(super) struct CommandSub {
/// The kind of messages to subscribe to, separated by commas if multiple.
#[arg(index = 1)]
pub(super) kinds: String,
// --- Macros
macro_rules! impl_body {
($name:ident) => {
impl $name {
#[allow(dead_code)]
pub(super) fn body(&self) -> Result<Cow<str>> {
if let Some(json) = &self.json {
Ok(json.into())
} else if let Some(str) = &self.str {
Ok(serde_json::to_string(str)?.into())
} else if !self.list.is_empty() {
Ok(serde_json::to_string(&self.list)?.into())
} else {
Ok("".into())
}
}
}
};
}

impl_body!(CommandPub);
impl_body!(CommandPubTo);
26 changes: 18 additions & 8 deletions yazi-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ async fn main() -> anyhow::Result<()> {
std::process::exit(1);
}
}

Command::PubTo(cmd) => {
yazi_boot::init_default();
yazi_dds::init();
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await {
eprintln!("Cannot send message: {e}");
std::process::exit(1);
}
}

Command::Sub(cmd) => {
yazi_boot::init_default();
yazi_dds::init();
yazi_dds::Client::draw(cmd.kinds.split(',').collect()).await?;

tokio::signal::ctrl_c().await?;
}

Command::Pack(cmd) => {
package::init();
if cmd.install {
Expand All @@ -40,14 +58,6 @@ async fn main() -> anyhow::Result<()> {
package::Package::add_to_config(repo).await?;
}
}

Command::Sub(cmd) => {
yazi_boot::init_default();
yazi_dds::init();
yazi_dds::Client::draw(cmd.kinds.split(',').collect()).await?;

tokio::signal::ctrl_c().await?;
}
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion yazi-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ indexmap = "2.2.6"
ratatui = "0.27.0"
regex = "1.10.5"
serde = { version = "1.0.204", features = [ "derive" ] }
toml = { version = "0.8.15", features = [ "preserve_order" ] }
toml = { version = "0.8.16", features = [ "preserve_order" ] }
validator = { version = "0.18.1", features = [ "derive" ] }

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
Loading

0 comments on commit 23a56c2

Please sign in to comment.