refactor!: rename the term select to toggle to reserve select for future use (#1773)

This commit is contained in:
三咲雅 · Misaki Masa 2024-10-13 18:47:12 +08:00 committed by GitHub
parent 13e307eab2
commit 35c3c9e0f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
90 changed files with 332 additions and 286 deletions

View file

@ -1,3 +1,7 @@
## The main branch is the upcoming v0.4 development version. Please see [the `shipped` tag](https://github.com/sxyazi/yazi/tree/shipped) for the stable version of Yazi.
For breaking changes, see [Migrating to Yazi v0.4.0](https://github.com/sxyazi/yazi/issues/1772).
<div align="center">
<img src="assets/logo.png" alt="Yazi logo" width="20%">
</div>
@ -16,7 +20,7 @@ Yazi (means "duck") is a terminal file manager written in Rust, based on non-blo
- 📡 **Data Distribution Service**: Built on a client-server architecture (no additional server process required), integrated with a Lua-based publish-subscribe model, achieving cross-instance communication and state persistence.
- 📦 **Package Manager**: Install plugins and themes with one command, keeping them up to date, or pin them to a specific version.
- 🧰 Integration with ripgrep, fd, fzf, zoxide
- 💫 Vim-like input/select/confirm/which/notify component, auto-completion for cd paths
- 💫 Vim-like input/pick/confirm/which/notify component, auto-completion for cd paths
- 🏷️ Multi-Tab Support, Cross-directory selection, Scrollable Preview (for videos, PDFs, archives, directories, code, etc.)
- 🔄 Bulk Renaming, Visual Mode, File Chooser
- 🎨 Theme System, Mouse Support, Trash Bin, Custom Layouts, CSI u

View file

@ -1,7 +1,7 @@
#![allow(clippy::unit_arg)]
yazi_macro::mod_flat!(
adapter, chafa, dimension, emulator, iip, image, kgp, kgp_old, mux, sixel, ueberzug
adapter chafa dimension emulator iip image kgp kgp_old mux sixel ueberzug
);
use yazi_shared::{RoCell, env_exists, in_wsl};

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(actions, clear_cache, debug, version);
yazi_macro::mod_flat!(actions clear_cache debug version);

View file

@ -1,6 +1,6 @@
yazi_macro::mod_pub!(actions);
yazi_macro::mod_flat!(args, boot);
yazi_macro::mod_flat!(args boot);
use clap::Parser;
use yazi_shared::RoCell;

View file

@ -1,6 +1,6 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(add, deploy, git, install, package, parser, upgrade);
yazi_macro::mod_flat!(add deploy git install package parser upgrade);
use anyhow::Context;

View file

@ -46,12 +46,14 @@ keymap = [
{ on = "K", run = "seek -5", desc = "Seek up 5 units in the preview" },
{ on = "J", run = "seek 5", desc = "Seek down 5 units in the preview" },
# Selection
{ on = "<Space>", run = [ "select --state=none", "arrow 1" ], desc = "Toggle the current selection state" },
{ on = "v", run = "visual_mode", desc = "Enter visual mode (selection mode)" },
{ on = "V", run = "visual_mode --unset", desc = "Enter visual mode (unset mode)" },
{ on = "<C-a>", run = "select_all --state=true", desc = "Select all files" },
{ on = "<C-r>", run = "select_all --state=none", desc = "Inverse selection of all files" },
# Toggle
{ on = "<Space>", run = [ "toggle", "arrow 1" ], desc = "Toggle the current selection state" },
{ on = "<C-a>", run = "toggle_all on", desc = "Select all files" },
{ on = "<C-r>", run = "toggle_all", desc = "Invert selection of all files" },
# Visual mode
{ on = "v", run = "visual_mode", desc = "Enter visual mode (selection mode)" },
{ on = "V", run = "visual_mode --unset", desc = "Enter visual mode (unset mode)" },
# Operation
{ on = "o", run = "open", desc = "Open selected files" },
@ -173,13 +175,13 @@ keymap = [
{ on = "<F1>", run = "help", desc = "Open help" },
]
[select]
[pick]
keymap = [
{ on = "<Esc>", run = "close", desc = "Cancel selection" },
{ on = "<C-[>", run = "close", desc = "Cancel selection" },
{ on = "<C-c>", run = "close", desc = "Cancel selection" },
{ on = "<Enter>", run = "close --submit", desc = "Submit the selection" },
{ on = "<Esc>", run = "close", desc = "Cancel pick" },
{ on = "<C-[>", run = "close", desc = "Cancel pick" },
{ on = "<C-c>", run = "close", desc = "Cancel pick" },
{ on = "<Enter>", run = "close --submit", desc = "Submit the pick" },
{ on = "k", run = "arrow -1", desc = "Move cursor up" },
{ on = "j", run = "arrow 1", desc = "Move cursor down" },

View file

@ -77,9 +77,9 @@ permissions_s = { fg = "darkgray" }
# : }}}
# : Select {{{
# : Pick {{{
[select]
[pick]
border = { fg = "blue" }
active = { fg = "magenta", bold = true }
inactive = {}

View file

@ -191,7 +191,7 @@ quit_content = "The following task is still running, are you sure you want to qu
quit_origin = "center"
quit_offset = [ 0, 0, 50, 15 ]
[select]
[pick]
open_title = "Open with:"
open_origin = "hovered"
open_offset = [ 0, 1, 50, 7 ]

View file

@ -11,7 +11,7 @@ use crate::Preset;
pub struct Keymap {
pub manager: Vec<Chord>,
pub tasks: Vec<Chord>,
pub select: Vec<Chord>,
pub pick: Vec<Chord>,
pub input: Vec<Chord>,
pub confirm: Vec<Chord>,
pub help: Vec<Chord>,
@ -25,7 +25,7 @@ impl Keymap {
Layer::App => unreachable!(),
Layer::Manager => &self.manager,
Layer::Tasks => &self.tasks,
Layer::Select => &self.select,
Layer::Pick => &self.pick,
Layer::Input => &self.input,
Layer::Confirm => &self.confirm,
Layer::Help => &self.help,
@ -50,7 +50,7 @@ impl<'de> Deserialize<'de> for Keymap {
struct Shadow {
manager: Inner,
tasks: Inner,
select: Inner,
pick: Inner,
input: Inner,
confirm: Inner,
help: Inner,
@ -81,7 +81,7 @@ impl<'de> Deserialize<'de> for Keymap {
#[rustfmt::skip]
tasks: mix(shadow.tasks.keymap, shadow.tasks.prepend_keymap, shadow.tasks.append_keymap),
#[rustfmt::skip]
select: mix(shadow.select.keymap, shadow.select.prepend_keymap, shadow.select.append_keymap),
pick: mix(shadow.pick.keymap, shadow.pick.prepend_keymap, shadow.pick.append_keymap),
#[rustfmt::skip]
input: mix(shadow.input.keymap, shadow.input.prepend_keymap, shadow.input.append_keymap),
#[rustfmt::skip]

View file

@ -1 +1 @@
yazi_macro::mod_flat!(chord, cow, deserializers, key, keymap);
yazi_macro::mod_flat!(chord cow deserializers key keymap);

View file

@ -1,8 +1,8 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_pub!(keymap, log, manager, open, plugin, popup, preview, tasks, theme, which);
yazi_macro::mod_pub!(keymap log manager open plugin popup preview tasks theme which);
yazi_macro::mod_flat!(layout, pattern, preset, priority);
yazi_macro::mod_flat!(layout pattern preset priority);
use std::str::FromStr;
@ -20,7 +20,7 @@ pub static TASKS: RoCell<tasks::Tasks> = RoCell::new();
pub static THEME: RoCell<theme::Theme> = RoCell::new();
pub static INPUT: RoCell<popup::Input> = RoCell::new();
pub static CONFIRM: RoCell<popup::Confirm> = RoCell::new();
pub static SELECT: RoCell<popup::Select> = RoCell::new();
pub static PICK: RoCell<popup::Pick> = RoCell::new();
pub static WHICH: RoCell<which::Which> = RoCell::new();
pub fn init() -> anyhow::Result<()> {
@ -41,7 +41,7 @@ pub fn init() -> anyhow::Result<()> {
THEME.init(<_>::from_str(theme_toml)?);
INPUT.init(<_>::from_str(yazi_toml)?);
CONFIRM.init(<_>::from_str(yazi_toml)?);
SELECT.init(<_>::from_str(yazi_toml)?);
PICK.init(<_>::from_str(yazi_toml)?);
WHICH.init(<_>::from_str(yazi_toml)?);
// TODO: Remove in v0.3.2

View file

@ -1 +1 @@
yazi_macro::mod_flat!(manager, mouse, ratio, sorting);
yazi_macro::mod_flat!(manager mouse ratio sorting);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(open, opener, rule);
yazi_macro::mod_flat!(open opener rule);

View file

@ -1,3 +1,3 @@
yazi_macro::mod_flat!(fetcher, plugin, preloader, previewer);
yazi_macro::mod_flat!(fetcher plugin preloader previewer);
pub const MAX_PREWORKERS: u8 = 32;

View file

@ -1 +1 @@
yazi_macro::mod_flat!(confirm, input, offset, options, origin, position, select);
yazi_macro::mod_flat!(confirm input offset options origin pick position);

View file

@ -2,7 +2,7 @@ use ratatui::{text::Text, widgets::{Paragraph, Wrap}};
use yazi_shared::fs::Url;
use super::{Offset, Origin, Position};
use crate::{CONFIRM, INPUT, SELECT};
use crate::{CONFIRM, INPUT, PICK};
#[derive(Default)]
pub struct InputCfg {
@ -16,7 +16,7 @@ pub struct InputCfg {
}
#[derive(Default)]
pub struct SelectCfg {
pub struct PickCfg {
pub title: String,
pub items: Vec<String>,
pub position: Position,
@ -176,21 +176,18 @@ impl ConfirmCfg {
}
}
impl SelectCfg {
impl PickCfg {
#[inline]
fn max_height(len: usize) -> u16 {
SELECT.open_offset.height.min(SELECT.border().saturating_add(len as u16))
PICK.open_offset.height.min(PICK.border().saturating_add(len as u16))
}
pub fn open(items: Vec<String>) -> Self {
let max_height = Self::max_height(items.len());
Self {
title: SELECT.open_title.to_owned(),
title: PICK.open_title.to_owned(),
items,
position: Position::new(SELECT.open_origin, Offset {
height: max_height,
..SELECT.open_offset
}),
position: Position::new(PICK.open_origin, Offset { height: max_height, ..PICK.open_offset }),
}
}
}

View file

@ -5,26 +5,26 @@ use serde::Deserialize;
use super::{Offset, Origin};
#[derive(Deserialize)]
pub struct Select {
pub struct Pick {
// open
pub open_title: String,
pub open_origin: Origin,
pub open_offset: Offset,
}
impl Select {
impl Pick {
pub const fn border(&self) -> u16 { 2 }
}
impl FromStr for Select {
impl FromStr for Pick {
type Err = toml::de::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
#[derive(Deserialize)]
struct Outer {
select: Select,
pick: Pick,
}
Ok(toml::from_str::<Outer>(s)?.select)
Ok(toml::from_str::<Outer>(s)?.pick)
}
}

View file

@ -1 +1 @@
yazi_macro::mod_flat!(preview, wrap);
yazi_macro::mod_flat!(preview wrap);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(filetype, flavor, icons, is, theme);
yazi_macro::mod_flat!(filetype flavor icons is theme);

View file

@ -12,7 +12,7 @@ pub struct Theme {
pub manager: Manager,
status: Status,
pub input: Input,
pub select: Select,
pub pick: Pick,
pub completion: Completion,
pub tasks: Tasks,
pub which: Which,
@ -115,7 +115,7 @@ pub struct Input {
}
#[derive(Deserialize, Serialize)]
pub struct Select {
pub struct Pick {
pub border: Style,
pub active: Style,
pub inactive: Style,

View file

@ -1 +1 @@
yazi_macro::mod_flat!(sorting, which);
yazi_macro::mod_flat!(sorting which);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(arrow, close, show, trigger);
yazi_macro::mod_flat!(arrow close show trigger);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(arrow, close, show);
yazi_macro::mod_flat!(arrow close show);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(arrow, escape, filter);
yazi_macro::mod_flat!(arrow escape filter);

View file

@ -1,4 +1,4 @@
yazi_macro::mod_flat!(
backspace, backward, close, complete, delete, escape, forward, insert, kill, move_, paste, redo,
show, type_, undo, visual, yank
backspace backward close complete delete escape forward insert kill move_ paste redo
show type_ undo visual yank
);

View file

@ -1,3 +1,3 @@
yazi_macro::mod_pub!(commands);
yazi_macro::mod_flat!(input, mode, op, snap, snaps);
yazi_macro::mod_flat!(input mode op snap snaps);

View file

@ -5,8 +5,7 @@ pub enum InputOp {
#[default]
None,
Select(usize),
// cut, insert, start
Delete(bool, bool, usize),
Delete(bool, bool, usize), // cut, insert, start
Yank(usize),
}

View file

@ -6,7 +6,7 @@
clippy::unit_arg
)]
yazi_macro::mod_pub!(completion, confirm, help, input, manager, notify, select, tab, tasks, which);
yazi_macro::mod_pub!(completion confirm help input manager notify pick tab tasks which);
pub fn init() {
manager::WATCHED.with(<_>::default);

View file

@ -1,28 +1,28 @@
yazi_macro::mod_flat!(
bulk_rename,
close,
create,
hardlink,
hover,
link,
open,
paste,
peek,
quit,
refresh,
remove,
rename,
seek,
suspend,
tab_close,
tab_create,
tab_swap,
tab_switch,
unyank,
update_files,
update_mimetype,
update_paged,
update_task,
update_yanked,
bulk_rename
close
create
hardlink
hover
link
open
paste
peek
quit
refresh
remove
rename
seek
suspend
tab_close
tab_create
tab_swap
tab_switch
unyank
update_files
update_mimetype
update_paged
update_task
update_yanked
yank
);

View file

@ -2,7 +2,7 @@ use std::{borrow::Cow, ffi::OsString};
use tracing::error;
use yazi_boot::ARGS;
use yazi_config::{OPEN, popup::SelectCfg};
use yazi_config::{OPEN, popup::PickCfg};
use yazi_fs::Folder;
use yazi_macro::emit;
use yazi_plugin::isolate;
@ -96,7 +96,7 @@ impl Manager {
let urls = [opt.hovered].into_iter().chain(targets.into_iter().map(|(u, _)| u)).collect();
tokio::spawn(async move {
let result = yazi_proxy::SelectProxy::show(SelectCfg::open(
let result = yazi_proxy::PickProxy::show(PickCfg::open(
openers.iter().map(|o| o.desc.clone()).collect(),
));
if let Ok(choice) = result.await {

View file

@ -1,3 +1,3 @@
yazi_macro::mod_pub!(commands);
yazi_macro::mod_flat!(linked, manager, mimetype, tabs, watcher, yanked);
yazi_macro::mod_flat!(linked manager mimetype tabs watcher yanked);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(push, tick);
yazi_macro::mod_flat!(push tick);

View file

@ -1,6 +1,6 @@
yazi_macro::mod_pub!(commands);
yazi_macro::mod_flat!(message, notify);
yazi_macro::mod_flat!(message notify);
pub const NOTIFY_BORDER: u16 = 2;
pub const NOTIFY_SPACING: u16 = 1;

View file

@ -1,7 +1,7 @@
use yazi_macro::render;
use yazi_shared::event::{Cmd, Data};
use crate::select::Select;
use crate::pick::Pick;
struct Opt {
step: isize,
@ -11,7 +11,7 @@ impl From<Cmd> for Opt {
fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } }
}
impl Select {
impl Pick {
#[yazi_codegen::command]
pub fn arrow(&mut self, opt: Opt) {
if opt.step > 0 { self.next(opt.step as usize) } else { self.prev(opt.step.unsigned_abs()) }

View file

@ -2,7 +2,7 @@ use anyhow::anyhow;
use yazi_macro::render;
use yazi_shared::event::Cmd;
use crate::select::Select;
use crate::pick::Pick;
struct Opt {
submit: bool,
@ -15,7 +15,7 @@ impl From<bool> for Opt {
fn from(submit: bool) -> Self { Self { submit } }
}
impl Select {
impl Pick {
#[yazi_codegen::command]
pub fn close(&mut self, opt: Opt) {
if let Some(cb) = self.callback.take() {

View file

@ -0,0 +1 @@
yazi_macro::mod_flat!(arrow close show);

View file

@ -1,12 +1,12 @@
use tokio::sync::oneshot;
use yazi_config::popup::SelectCfg;
use yazi_config::popup::PickCfg;
use yazi_macro::render;
use yazi_shared::event::Cmd;
use crate::select::Select;
use crate::pick::Pick;
pub struct Opt {
cfg: SelectCfg,
cfg: PickCfg,
tx: oneshot::Sender<anyhow::Result<usize>>,
}
@ -18,7 +18,7 @@ impl TryFrom<Cmd> for Opt {
}
}
impl Select {
impl Pick {
pub fn show(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else {
return;

View file

@ -1,3 +1,3 @@
yazi_macro::mod_pub!(commands);
yazi_macro::mod_flat!(select);
yazi_macro::mod_flat!(pick);

View file

@ -1,9 +1,9 @@
use anyhow::Result;
use tokio::sync::oneshot::Sender;
use yazi_config::{SELECT, popup::Position};
use yazi_config::{PICK, popup::Position};
#[derive(Default)]
pub struct Select {
pub struct Pick {
pub(super) title: String,
pub(super) items: Vec<String>,
pub position: Position,
@ -15,7 +15,7 @@ pub struct Select {
pub visible: bool,
}
impl Select {
impl Pick {
#[inline]
pub fn window(&self) -> &[String] {
let end = (self.offset + self.limit()).min(self.items.len());
@ -24,11 +24,11 @@ impl Select {
#[inline]
pub(super) fn limit(&self) -> usize {
self.position.offset.height.saturating_sub(SELECT.border()) as usize
self.position.offset.height.saturating_sub(PICK.border()) as usize
}
}
impl Select {
impl Pick {
#[inline]
pub fn title(&self) -> String { self.title.clone() }

View file

@ -1 +0,0 @@
yazi_macro::mod_flat!(arrow, close, show);

View file

@ -1,25 +1,27 @@
yazi_macro::mod_flat!(
arrow,
back,
cd,
copy,
enter,
escape,
filter,
filter_do,
find,
find_arrow,
find_do,
forward,
hidden,
leave,
linemode,
preview,
reveal,
search,
select,
select_all,
shell,
sort,
arrow
back
cd
copy
enter
escape
filter
filter_do
find
find_arrow
find_do
forward
hidden
leave
linemode
preview
reveal
search
select
select_all
shell
sort
toggle
toggle_all
visual_mode
);

View file

@ -1,48 +1,30 @@
use std::borrow::Cow;
use std::time::Duration;
use yazi_macro::render_and;
use yazi_proxy::AppProxy;
use yazi_shared::{event::{Cmd, Data}, fs::Url};
use yazi_shared::event::Cmd;
use crate::tab::Tab;
struct Opt<'a> {
url: Option<Cow<'a, Url>>,
state: Option<bool>,
struct Opt;
impl From<Cmd> for Opt {
fn from(_: Cmd) -> Self { Self }
}
impl<'a> From<Cmd> for Opt<'a> {
fn from(mut c: Cmd) -> Self {
Self {
url: c.take("url").and_then(Data::into_url).map(Cow::Owned),
state: match c.take_str("state").as_deref() {
Some("true") => Some(true),
Some("false") => Some(false),
_ => None,
},
}
}
impl From<()> for Opt {
fn from(_: ()) -> Self { Self }
}
impl<'a> Tab {
impl Tab {
// TODO: remove this in Yazi 0.4.1
#[yazi_codegen::command]
pub fn select(&mut self, opt: Opt<'a>) {
let Some(url) = opt.url.or_else(|| self.current.hovered().map(|h| Cow::Borrowed(&h.url)))
else {
return;
};
pub fn select(&mut self, _: Opt) {
yazi_proxy::AppProxy::notify(yazi_proxy::options::NotifyOpt {
title: "Deprecated command".to_owned(),
content: "`select` and `select_all` command has been renamed to `toggle` and `toggle_all` in Yazi v0.4
let b = match opt.state {
Some(true) => render_and!(self.selected.add(&url)),
Some(false) => render_and!(self.selected.remove(&url)) | true,
None => render_and!(self.selected.remove(&url) || self.selected.add(&url)),
};
if !b {
AppProxy::notify_warn(
"Select one",
"This file cannot be selected, due to path nesting conflict.",
);
}
Please change it in your keymap.toml, see #1773 for details: https://github.com/sxyazi/yazi/pull/1773".to_owned(),
level: yazi_proxy::options::NotifyLevel::Error,
timeout: Duration::from_secs(20),
});
}
}

View file

@ -1,49 +1,15 @@
use yazi_macro::render;
use yazi_proxy::AppProxy;
use yazi_shared::event::Cmd;
use crate::tab::Tab;
struct Opt {
state: Option<bool>,
}
struct Opt;
impl From<Cmd> for Opt {
fn from(mut c: Cmd) -> Self {
Self {
state: match c.take_str("state").as_deref() {
Some("true") => Some(true),
Some("false") => Some(false),
_ => None,
},
}
}
}
impl From<Option<bool>> for Opt {
fn from(state: Option<bool>) -> Self { Self { state } }
fn from(_: Cmd) -> Self { Self }
}
impl Tab {
// TODO: remove this in Yazi 0.4.1
#[yazi_codegen::command]
pub fn select_all(&mut self, opt: Opt) {
let iter = self.current.files.iter().map(|f| &f.url);
let (removal, addition): (Vec<_>, Vec<_>) = match opt.state {
Some(true) => (vec![], iter.collect()),
Some(false) => (iter.collect(), vec![]),
None => iter.partition(|&u| self.selected.contains_key(u)),
};
let same = !self.cwd().is_search();
render!(self.selected.remove_many(&removal, same) > 0);
let added = self.selected.add_many(&addition, same);
render!(added > 0);
if added != addition.len() {
AppProxy::notify_warn(
"Select all",
"Some files cannot be selected, due to path nesting conflict.",
);
}
}
pub fn select_all(&mut self, _: Opt) { self.select(()); }
}

View file

@ -0,0 +1,43 @@
use yazi_macro::render_and;
use yazi_proxy::AppProxy;
use yazi_shared::event::Cmd;
use crate::tab::Tab;
struct Opt {
state: Option<bool>,
}
impl From<Cmd> for Opt {
fn from(mut c: Cmd) -> Self {
Self {
state: match c.take_first_str().as_deref() {
Some("on") => Some(true),
Some("off") => Some(false),
_ => None,
},
}
}
}
impl Tab {
#[yazi_codegen::command]
pub fn toggle(&mut self, opt: Opt) {
let Some(url) = self.current.hovered().map(|h| &h.url) else {
return;
};
let b = match opt.state {
Some(true) => render_and!(self.selected.add(url)),
Some(false) => render_and!(self.selected.remove(url)) | true,
None => render_and!(self.selected.remove(url) || self.selected.add(url)),
};
if !b {
AppProxy::notify_warn(
"Toggle",
"This file cannot be selected, due to path nesting conflict.",
);
}
}
}

View file

@ -0,0 +1,49 @@
use yazi_macro::render;
use yazi_proxy::AppProxy;
use yazi_shared::event::Cmd;
use crate::tab::Tab;
struct Opt {
state: Option<bool>,
}
impl From<Cmd> for Opt {
fn from(mut c: Cmd) -> Self {
Self {
state: match c.take_first_str().as_deref() {
Some("on") => Some(true),
Some("off") => Some(false),
_ => None,
},
}
}
}
impl From<Option<bool>> for Opt {
fn from(state: Option<bool>) -> Self { Self { state } }
}
impl Tab {
#[yazi_codegen::command]
pub fn toggle_all(&mut self, opt: Opt) {
let iter = self.current.files.iter().map(|f| &f.url);
let (removal, addition): (Vec<_>, Vec<_>) = match opt.state {
Some(true) => (vec![], iter.collect()),
Some(false) => (iter.collect(), vec![]),
None => iter.partition(|&u| self.selected.contains_key(u)),
};
let same = !self.cwd().is_search();
render!(self.selected.remove_many(&removal, same) > 0);
let added = self.selected.add_many(&addition, same);
render!(added > 0);
if added != addition.len() {
AppProxy::notify_warn(
"Toggle all",
"Some files cannot be selected, due to path nesting conflict.",
);
}
}
}

View file

@ -1,3 +1,3 @@
yazi_macro::mod_pub!(commands);
yazi_macro::mod_flat!(backstack, config, finder, history, mode, preview, selected, tab);
yazi_macro::mod_flat!(backstack config finder history mode preview selected tab);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(arrow, cancel, inspect, open_with, process_exec, toggle);
yazi_macro::mod_flat!(arrow cancel inspect open_with process_exec toggle);

View file

@ -1,6 +1,6 @@
yazi_macro::mod_pub!(commands);
yazi_macro::mod_flat!(file, plugin, preload, process, progress, tasks);
yazi_macro::mod_flat!(file plugin preload process progress tasks);
pub const TASKS_BORDER: u16 = 2;
pub const TASKS_PADDING: u16 = 2;

View file

@ -1 +1 @@
yazi_macro::mod_flat!(callback, show);
yazi_macro::mod_flat!(callback show);

View file

@ -1,3 +1,3 @@
yazi_macro::mod_pub!(commands);
yazi_macro::mod_flat!(sorter, which);
yazi_macro::mod_flat!(sorter which);

View file

@ -1,5 +1,5 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(
body, bulk, bye, cd, custom, delete, hey, hi, hover, move_, rename, tab, trash, yank
body bulk bye cd custom delete hey hi hover move_ rename tab trash yank
);

View file

@ -2,7 +2,7 @@
yazi_macro::mod_pub!(body);
yazi_macro::mod_flat!(client, payload, pubsub, pump, sendable, server, state, stream);
yazi_macro::mod_flat!(client payload pubsub pump sendable server state stream);
pub fn init() {
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();

View file

@ -1,13 +1,13 @@
yazi_macro::mod_flat!(
accept_payload,
mouse,
notify,
plugin,
quit,
render,
resize,
resume,
stop,
update_notify,
accept_payload
mouse
notify
plugin
quit
render
resize
resume
stop
update_notify
update_progress
);

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(preview, progress);
yazi_macro::mod_flat!(preview progress);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(buttons, confirm, content, list);
yazi_macro::mod_flat!(buttons confirm content list);

View file

@ -1,10 +1,10 @@
use ratatui::layout::Rect;
use yazi_core::{completion::Completion, confirm::Confirm, help::Help, input::Input, manager::Manager, notify::Notify, select::Select, tasks::Tasks, which::Which};
use yazi_core::{completion::Completion, confirm::Confirm, help::Help, input::Input, manager::Manager, notify::Notify, pick::Pick, tasks::Tasks, which::Which};
pub struct Ctx {
pub manager: Manager,
pub tasks: Tasks,
pub select: Select,
pub pick: Pick,
pub input: Input,
pub confirm: Confirm,
pub help: Help,
@ -18,7 +18,7 @@ impl Ctx {
Self {
manager: Manager::make(),
tasks: Tasks::serve(),
select: Default::default(),
pick: Default::default(),
input: Default::default(),
confirm: Default::default(),
help: Default::default(),

View file

@ -17,7 +17,7 @@ impl<'a> Executor<'a> {
Layer::App => self.app(cmd),
Layer::Manager => self.manager(cmd),
Layer::Tasks => self.tasks(cmd),
Layer::Select => self.select(cmd),
Layer::Pick => self.pick(cmd),
Layer::Input => self.input(cmd),
Layer::Confirm => self.confirm(cmd),
Layer::Help => self.help(cmd),
@ -89,10 +89,12 @@ impl<'a> Executor<'a> {
on!(ACTIVE, cd);
on!(ACTIVE, reveal);
// Selection
// Toggle
on!(ACTIVE, toggle);
on!(ACTIVE, toggle_all);
on!(ACTIVE, visual_mode);
on!(ACTIVE, select);
on!(ACTIVE, select_all);
on!(ACTIVE, visual_mode);
// Operation
on!(MANAGER, open, &self.app.cx.tasks);
@ -172,11 +174,11 @@ impl<'a> Executor<'a> {
}
}
fn select(&mut self, cmd: Cmd) {
fn pick(&mut self, cmd: Cmd) {
macro_rules! on {
($name:ident) => {
if cmd.name == stringify!($name) {
return self.app.cx.select.$name(cmd);
return self.app.cx.pick.$name(cmd);
}
};
}
@ -187,7 +189,7 @@ impl<'a> Executor<'a> {
match cmd.name.as_str() {
// Help
"help" => self.app.cx.help.toggle(Layer::Select),
"help" => self.app.cx.help.toggle(Layer::Pick),
// Plugin
"plugin" => self.app.plugin(cmd),
_ => {}

View file

@ -1 +1 @@
yazi_macro::mod_flat!(bindings, layout);
yazi_macro::mod_flat!(bindings layout);

View file

@ -1,8 +1,8 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(
config, file, files, filter, finder, folder, iter, lives, mode, preview, selected, tab, tabs,
tasks, yanked
config file files filter finder folder iter lives mode preview selected tab tabs
tasks yanked
);
type CtxRef<'lua> = mlua::UserDataRef<'lua, crate::Ctx>;

View file

@ -6,10 +6,10 @@
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
yazi_macro::mod_pub!(
app, completion, components, confirm, help, input, lives, notify, select, tasks, which
app completion components confirm help input lives notify pick tasks which
);
yazi_macro::mod_flat!(context, executor, logs, panic, root, router, signals, term);
yazi_macro::mod_flat!(context executor logs panic root router signals term);
#[tokio::main]
async fn main() -> anyhow::Result<()> {

1
yazi-fm/src/pick/mod.rs Normal file
View file

@ -0,0 +1 @@
yazi_macro::mod_flat!(pick);

View file

@ -3,29 +3,29 @@ use yazi_config::THEME;
use crate::Ctx;
pub(crate) struct Select<'a> {
pub(crate) struct Pick<'a> {
cx: &'a Ctx,
}
impl<'a> Select<'a> {
impl<'a> Pick<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }
}
impl<'a> Widget for Select<'a> {
impl<'a> Widget for Pick<'a> {
fn render(self, _: Rect, buf: &mut Buffer) {
let select = &self.cx.select;
let area = self.cx.manager.area(select.position);
let pick = &self.cx.pick;
let area = self.cx.manager.area(pick.position);
let items: Vec<_> = select
let items: Vec<_> = pick
.window()
.iter()
.enumerate()
.map(|(i, v)| {
if i != select.rel_cursor() {
return ListItem::new(format!(" {v}")).style(THEME.select.inactive);
if i != pick.rel_cursor() {
return ListItem::new(format!(" {v}")).style(THEME.pick.inactive);
}
ListItem::new(format!("{v}")).style(THEME.select.active)
ListItem::new(format!("{v}")).style(THEME.pick.active)
})
.collect();
@ -33,9 +33,9 @@ impl<'a> Widget for Select<'a> {
List::new(items)
.block(
Block::bordered()
.title(select.title())
.title(pick.title())
.border_type(BorderType::Rounded)
.border_style(THEME.select.border),
.border_style(THEME.pick.border),
)
.render(area, buf);
}

View file

@ -3,7 +3,7 @@ use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
use tracing::error;
use yazi_plugin::{LUA, elements::render_widgets};
use super::{completion, confirm, input, select, tasks, which};
use super::{completion, confirm, input, pick, tasks, which};
use crate::{Ctx, components, help};
pub(super) struct Root<'a> {
@ -33,8 +33,8 @@ impl<'a> Widget for Root<'a> {
tasks::Layout::new(self.cx).render(area, buf);
}
if self.cx.select.visible {
select::Select::new(self.cx).render(area, buf);
if self.cx.pick.visible {
pick::Pick::new(self.cx).render(area, buf);
}
if self.cx.input.visible {

View file

@ -34,8 +34,8 @@ impl<'a> Router<'a> {
self.matches(Layer::Input, key)
} else if cx.confirm.visible {
self.matches(Layer::Confirm, key)
} else if cx.select.visible {
self.matches(Layer::Select, key)
} else if cx.pick.visible {
self.matches(Layer::Pick, key)
} else if cx.tasks.visible {
self.matches(Layer::Tasks, key)
} else {

View file

@ -1 +0,0 @@
yazi_macro::mod_flat!(select);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(cand, layout);
yazi_macro::mod_flat!(cand layout);

View file

@ -1,3 +1,3 @@
#![allow(clippy::if_same_then_else)]
yazi_macro::mod_flat!(files, filter, folder, sorter, stage, step);
yazi_macro::mod_flat!(files filter folder sorter stage step);

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(bindings, icon, input, mouse, permit, position, range, window);
yazi_macro::mod_flat!(bindings icon input mouse permit position range window);

View file

@ -1,6 +1,6 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(
bar, border, clear, constraint, elements, gauge, layout, line, list, padding, paragraph,
position, rect, span, style
bar border clear constraint elements gauge layout line list padding paragraph
position rect span style
);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(fd, highlighter, rg);
yazi_macro::mod_flat!(fd highlighter rg);

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(entry, fetch, isolate, peek, preload, seek);
yazi_macro::mod_flat!(entry fetch isolate peek preload seek);

View file

@ -6,7 +6,7 @@ yazi_macro::mod_pub!(
bindings, cha, elements, external, file, fs, isolate, loader, process, pubsub, url, utils
);
yazi_macro::mod_flat!(cast, clipboard, config, lua, opt, runtime);
yazi_macro::mod_flat!(cast clipboard config lua opt runtime);
pub fn init() -> anyhow::Result<()> {
CLIPBOARD.with(<_>::default);

View file

@ -1,6 +1,6 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(loader, require);
yazi_macro::mod_flat!(loader require);
pub(super) fn init() { LOADER.with(<_>::default); }

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(child, command, output, process, status);
yazi_macro::mod_flat!(child command output process status);

View file

@ -1,5 +1,5 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(
app, cache, call, image, layer, log, preview, sync, target, text, time, user, utils
app cache call image layer log preview sync target text time user utils
);

View file

@ -1,5 +1,5 @@
yazi_macro::mod_pub!(options);
yazi_macro::mod_flat!(app, completion, confirm, input, manager, select, semaphore, tab, tasks);
yazi_macro::mod_flat!(app completion confirm input manager pick semaphore tab tasks);
pub fn init() { crate::init_semaphore(); }

View file

@ -1 +1 @@
yazi_macro::mod_flat!(notify, open, process, search);
yazi_macro::mod_flat!(notify open process search);

View file

@ -1,15 +1,15 @@
use tokio::sync::oneshot;
use yazi_config::popup::SelectCfg;
use yazi_config::popup::PickCfg;
use yazi_macro::emit;
use yazi_shared::{Layer, event::Cmd};
pub struct SelectProxy;
pub struct PickProxy;
impl SelectProxy {
impl PickProxy {
#[inline]
pub async fn show(cfg: SelectCfg) -> anyhow::Result<usize> {
pub async fn show(cfg: PickCfg) -> anyhow::Result<usize> {
let (tx, rx) = oneshot::channel();
emit!(Call(Cmd::new("show").with_any("tx", tx).with_any("cfg", cfg), Layer::Select));
emit!(Call(Cmd::new("show").with_any("tx", tx).with_any("cfg", cfg), Layer::Pick));
rx.await?
}
}

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(file, op);
yazi_macro::mod_flat!(file op);

View file

@ -1,8 +1,8 @@
#![allow(clippy::option_map_unit_fn, clippy::unit_arg)]
yazi_macro::mod_pub!(file, plugin, prework, process);
yazi_macro::mod_pub!(file plugin prework process);
yazi_macro::mod_flat!(ongoing, op, scheduler, task);
yazi_macro::mod_flat!(ongoing op scheduler task);
const LOW: u8 = yazi_config::Priority::Low as u8;
const NORMAL: u8 = yazi_config::Priority::Normal as u8;

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(op, plugin);
yazi_macro::mod_flat!(op plugin);

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(op, prework);
yazi_macro::mod_flat!(op prework);

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(op, process, shell);
yazi_macro::mod_flat!(op process shell);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(input, peek);
yazi_macro::mod_flat!(input peek);

View file

@ -1,5 +1,5 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(cmd, data, event);
yazi_macro::mod_flat!(cmd data event);
pub static NEED_RENDER: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(cha, file, fns, loc, op, path, url, urn);
yazi_macro::mod_flat!(cha file fns loc op path url urn);

View file

@ -8,7 +8,7 @@ pub enum Layer {
App,
Manager,
Tasks,
Select,
Pick,
Input,
Confirm,
Help,
@ -22,7 +22,7 @@ impl Display for Layer {
Self::App => "app",
Self::Manager => "manager",
Self::Tasks => "tasks",
Self::Select => "select",
Self::Pick => "pick",
Self::Input => "input",
Self::Confirm => "confirm",
Self::Help => "help",
@ -40,7 +40,7 @@ impl FromStr for Layer {
"app" => Self::App,
"manager" => Self::Manager,
"tasks" => Self::Tasks,
"select" => Self::Select,
"pick" => Self::Pick,
"input" => Self::Input,
"confirm" => Self::Confirm,
"help" => Self::Help,

View file

@ -1,10 +1,10 @@
#![allow(clippy::option_map_unit_fn)]
yazi_macro::mod_pub!(errors, event, fs, shell, theme, translit);
yazi_macro::mod_pub!(errors event fs shell theme translit);
yazi_macro::mod_flat!(
chars, condition, debounce, env, layer, natsort, number, os, rand, ro_cell, terminal, throttle,
time, xdg
chars condition debounce env layer natsort number os rand ro_cell terminal throttle
time xdg
);
pub fn init() {

View file

@ -1 +1 @@
yazi_macro::mod_flat!(color, icon, style);
yazi_macro::mod_flat!(color icon style);

View file

@ -1 +1 @@
yazi_macro::mod_flat!(table, traits);
yazi_macro::mod_flat!(table traits);