feat: ya pack supports adding and deleting multiple packages at the same time (#2257)

This commit is contained in:
evpeople 2025-01-30 02:21:55 +08:00 committed by sxyazi
parent c061397a09
commit 77624ba6dc
No known key found for this signature in database
11 changed files with 118 additions and 82 deletions

49
Cargo.lock generated
View file

@ -289,9 +289,9 @@ checksum = "c360505aed52b7ec96a3636c3f039d99103c37d1d9b4f7a8c743d3ea9ffcd03b"
[[package]]
name = "bumpalo"
version = "3.16.0"
version = "3.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
[[package]]
name = "bytemuck"
@ -395,9 +395,9 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "4.5.42"
version = "4.5.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33a7e468e750fa4b6be660e8b5651ad47372e8fb114030b594c2d75d48c5ffd0"
checksum = "375f9d8255adeeedd51053574fd8d4ba875ea5fa558e86617b07f09f1680c8b6"
dependencies = [
"clap",
]
@ -1385,9 +1385,9 @@ checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
[[package]]
name = "libfuzzer-sys"
version = "0.4.8"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b9569d2f74e257076d8c6bfa73fb505b46b851e51ddaecc825944aa3bed17fa"
checksum = "cf78f52d400cf2d84a3a973a78a592b4adc535739e0a5597a0da6f0c357adc75"
dependencies = [
"arbitrary",
"cc",
@ -1450,6 +1450,15 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "lru"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "227748d55f2f0ab4735d87fd623798cb6b664512fe979705f829c9f81c934465"
dependencies = [
"hashbrown",
]
[[package]]
name = "lua-src"
version = "547.0.0"
@ -1542,9 +1551,9 @@ dependencies = [
[[package]]
name = "mlua"
version = "0.10.2"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea43c3ffac2d0798bd7128815212dd78c98316b299b7a902dabef13dc7b6b8d"
checksum = "d3f763c1041eff92ffb5d7169968a327e1ed2ebfe425dac0ee5a35f29082534b"
dependencies = [
"anyhow",
"bstr",
@ -1562,9 +1571,9 @@ dependencies = [
[[package]]
name = "mlua-sys"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63a11d485edf0f3f04a508615d36c7d50d299cf61a7ee6d3e2530651e0a31771"
checksum = "1901c1a635a22fe9250ffcc4fcc937c16b47c2e9e71adba8784af8bca1f69594"
dependencies = [
"cc",
"cfg-if",
@ -2037,7 +2046,7 @@ dependencies = [
"indoc",
"instability",
"itertools 0.13.0",
"lru",
"lru 0.12.5",
"paste",
"strum",
"unicode-segmentation",
@ -2216,9 +2225,9 @@ checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
[[package]]
name = "ryu"
version = "1.0.18"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd"
[[package]]
name = "same-file"
@ -2273,9 +2282,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.137"
version = "1.0.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b"
checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949"
dependencies = [
"itoa",
"memchr",
@ -2834,9 +2843,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicode-ident"
version = "1.0.15"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243"
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
[[package]]
name = "unicode-linebreak"
@ -3285,9 +3294,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.6.24"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a"
checksum = "ad699df48212c6cc6eb4435f35500ac6fd3b9913324f938aea302022ce19d310"
dependencies = [
"memchr",
]
@ -3593,7 +3602,7 @@ dependencies = [
"async-priority-channel",
"futures",
"libc",
"lru",
"lru 0.13.0",
"parking_lot",
"scopeguard",
"tokio",

View file

@ -23,16 +23,16 @@ futures = "0.3.31"
globset = "0.4.15"
indexmap = { version = "2.7.1", features = [ "serde" ] }
libc = "0.2.169"
lru = "0.12.5"
lru = "0.13.0"
md-5 = "0.10.6"
mlua = { version = "0.10.2", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serialize" ] }
mlua = { version = "0.10.3", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serialize" ] }
objc = "0.2.7"
parking_lot = "0.12.3"
ratatui = { version = "0.29.0", features = [ "unstable-rendered-line-info" ] }
regex = "1.11.1"
scopeguard = "1.2.0"
serde = { version = "1.0.217", features = [ "derive" ] }
serde_json = "1.0.137"
serde_json = "1.0.138"
shell-words = "1.1.0"
tokio = { version = "1.43.0", features = [ "full" ] }
tokio-stream = "0.1.17"

View file

@ -1 +1 @@
{"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp"," Überzug"," Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","Sysinfo","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone"],"version":"0.2","language":"en","flagWords":[]}
{"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp"," Überzug"," Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","Sysinfo","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR"],"flagWords":[],"version":"0.2"}

View file

@ -22,7 +22,7 @@ serde = { workspace = true }
[build-dependencies]
clap = { workspace = true }
clap_complete = "4.5.42"
clap_complete = "4.5.44"
clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.5"
vergen-gitcl = { version = "1.0.5", features = [ "build", "rustc" ] }

View file

@ -31,7 +31,7 @@ yazi-shared = { path = "../yazi-shared", version = "0.4.3" }
# External build dependencies
anyhow = { workspace = true }
clap = { workspace = true }
clap_complete = "4.5.42"
clap_complete = "4.5.44"
clap_complete_fig = "4.5.2"
clap_complete_nushell = "4.5.5"
serde_json = { workspace = true }

View file

@ -54,12 +54,12 @@ pub(super) struct CommandEmitTo {
#[derive(clap::Args)]
#[command(arg_required_else_help = true)]
pub(super) struct CommandPack {
/// Add a package.
#[arg(short = 'a', long)]
pub(super) add: Option<String>,
/// Delete a package.
#[arg(short = 'd', long)]
pub(super) delete: Option<String>,
/// Add packages.
#[arg(short = 'a', long, num_args = 1..)]
pub(super) add: Option<Vec<String>>,
/// Delete packages.
#[arg(short = 'd', long, num_args = 1..)]
pub(super) delete: Option<Vec<String>>,
/// Install all packages.
#[arg(short = 'i', long)]
pub(super) install: bool,

View file

@ -71,10 +71,10 @@ async fn run() -> anyhow::Result<()> {
package::Package::load().await?.print()?;
} else if cmd.upgrade {
package::Package::load().await?.install(true).await?;
} else if let Some(repo) = cmd.add {
package::Package::load().await?.add(&repo).await?;
} else if let Some(repo) = cmd.delete {
package::Package::load().await?.delete(&repo).await?;
} else if let Some(uses) = cmd.add {
package::Package::load().await?.add_many(&uses).await?;
} else if let Some(uses) = cmd.delete {
package::Package::load().await?.delete_many(&uses).await?;
}
}

View file

@ -1,8 +1,8 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use anyhow::{Context, Result, bail};
use tokio::fs;
use yazi_fs::{copy_and_seal, maybe_exists};
use yazi_fs::{copy_and_seal, maybe_exists, remove_dir_clean};
use yazi_macro::outln;
use super::Dependency;
@ -26,7 +26,22 @@ Please manually delete it from `{}` and re-run the command.",
}
fs::create_dir_all(&to).await?;
let files = if self.is_flavor {
if let Err(e) = Self::deploy_sources(&from, &to, self.is_flavor).await {
remove_dir_clean(&to).await;
return Err(e);
}
self.delete_assets().await?;
Self::deploy_assets(from.join("assets"), to.join("assets")).await?;
self.hash = self.hash().await?;
outln!("Done!")?;
Ok(())
}
async fn deploy_sources(from: &Path, to: &Path, is_flavor: bool) -> Result<()> {
let files = if is_flavor {
&["flavor.toml", "tmtheme.xml", "README.md", "preview.png", "LICENSE", "LICENSE-tmtheme"][..]
} else {
&["main.lua", "README.md", "LICENSE"][..]
@ -48,13 +63,6 @@ Please manually delete it from `{}` and re-run the command.",
.await
.with_context(|| format!("failed to copy `{}` to `{}`", from.display(), to.display()))?;
}
self.delete_assets().await?;
Self::deploy_assets(from.join("assets"), to.join("assets")).await?;
self.hash = self.hash().await?;
outln!("Done!")?;
Ok(())
}

View file

@ -23,41 +23,24 @@ impl Package {
})
}
pub(crate) async fn add(&mut self, use_: &str) -> Result<()> {
let mut dep = Dependency::from_str(use_)?;
if let Some(d) = self.identical(&dep) {
bail!(
"{} `{}` already exists in package.toml",
if d.is_flavor { "Flavor" } else { "Plugin" },
dep.name
)
pub(crate) async fn add_many(&mut self, uses: &[String]) -> Result<()> {
for u in uses {
if let Err(e) = self.add(u).await {
self.save().await?;
return Err(e);
}
}
dep.add().await?;
if dep.is_flavor {
self.flavors.push(dep);
} else {
self.plugins.push(dep);
}
let s = toml::to_string_pretty(self)?;
fs::write(Self::toml(), s).await.context("Failed to write package.toml")
self.save().await
}
pub(crate) async fn delete(&mut self, use_: &str) -> Result<()> {
let Some(dep) = self.identical(&Dependency::from_str(use_)?).cloned() else {
bail!("`{}` was not found in package.toml", use_)
};
dep.delete().await?;
if dep.is_flavor {
self.flavors.retain(|d| !d.identical(&dep));
} else {
self.plugins.retain(|d| !d.identical(&dep));
pub(crate) async fn delete_many(&mut self, uses: &[String]) -> Result<()> {
for u in uses {
if let Err(e) = self.delete(u).await {
self.save().await?;
return Err(e);
}
}
let s = toml::to_string_pretty(self)?;
fs::write(Self::toml(), s).await.context("Failed to write package.toml")
self.save().await
}
pub(crate) async fn install(&mut self, upgrade: bool) -> Result<()> {
@ -76,8 +59,7 @@ impl Package {
}
}
let s = toml::to_string_pretty(self)?;
fs::write(Self::toml(), s).await.context("Failed to write package.toml")
self.save().await
}
pub(crate) fn print(&self) -> Result<()> {
@ -178,6 +160,43 @@ impl Package {
}
}
self.save().await
}
async fn add(&mut self, use_: &str) -> Result<()> {
let mut dep = Dependency::from_str(use_)?;
if let Some(d) = self.identical(&dep) {
bail!(
"{} `{}` already exists in package.toml",
if d.is_flavor { "Flavor" } else { "Plugin" },
dep.name
)
}
dep.add().await?;
if dep.is_flavor {
self.flavors.push(dep);
} else {
self.plugins.push(dep);
}
Ok(())
}
async fn delete(&mut self, use_: &str) -> Result<()> {
let Some(dep) = self.identical(&Dependency::from_str(use_)?).cloned() else {
bail!("`{}` was not found in package.toml", use_)
};
dep.delete().await?;
if dep.is_flavor {
self.flavors.retain(|d| !d.identical(&dep));
} else {
self.plugins.retain(|d| !d.identical(&dep));
}
Ok(())
}
async fn save(&self) -> Result<()> {
let s = toml::to_string_pretty(self)?;
fs::write(Self::toml(), s).await.context("Failed to write package.toml")
}

View file

@ -37,9 +37,9 @@ impl Manager {
let mut rx = ConfirmProxy::show_rx(ConfirmCfg::quit(left, left_names));
loop {
select! {
_ = time::sleep(Duration::from_millis(100)) => {
_ = time::sleep(Duration::from_millis(50)) => {
i += 1;
if i > 30 { break }
if i > 40 { break }
else if ongoing.lock().len() == 0 {
emit!(Quit(opt));
return;

View file

@ -33,7 +33,7 @@ impl Term {
execute!(
BufWriter::new(stderr()),
screen::SetScreen(true),
Print(Mux::csi("\x1bP$q q\x1b\\")), // Request cursor shape (DECRQM)
Print(Mux::csi("\x1bP$q q\x1b\\")), // Request cursor shape (DECRQSS query for DECSCUSR)
Print(Mux::csi("\x1b[?12$p")), // Request cursor blink status (DECSET)
Print("\x1b[?u"), // Request keyboard enhancement flags (CSI u)
Print(Mux::csi("\x1b[0c")), // Request device attributes