mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-19 06:41:35 +03:00
feat: cx.yanked
plugin API (#788)
This commit is contained in:
parent
1aed6e8b36
commit
33782f1224
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::BTreeMap, path::Path};
|
use std::{collections::HashMap, path::Path};
|
||||||
|
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
@ -10,7 +10,7 @@ use crate::{open::OpenRule, Preset, MERGED_YAZI};
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Open {
|
pub struct Open {
|
||||||
rules: Vec<OpenRule>,
|
rules: Vec<OpenRule>,
|
||||||
openers: BTreeMap<String, IndexSet<Opener>>,
|
openers: HashMap<String, IndexSet<Opener>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Open {
|
impl Default for Open {
|
||||||
@ -65,7 +65,7 @@ impl<'de> Deserialize<'de> for Open {
|
|||||||
{
|
{
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Outer {
|
struct Outer {
|
||||||
opener: BTreeMap<String, Vec<Opener>>,
|
opener: HashMap<String, Vec<Opener>>,
|
||||||
open: OuterOpen,
|
open: OuterOpen,
|
||||||
}
|
}
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Completion {
|
pub struct Completion {
|
||||||
pub(super) caches: BTreeMap<String, Vec<String>>,
|
pub(super) caches: HashMap<String, Vec<String>>,
|
||||||
pub(super) cands: Vec<String>,
|
pub(super) cands: Vec<String>,
|
||||||
pub(super) offset: usize,
|
pub(super) offset: usize,
|
||||||
pub cursor: usize,
|
pub cursor: usize,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::{BTreeMap, BTreeSet}, mem, ops::Deref, sync::atomic::Ordering};
|
use std::{collections::{HashMap, HashSet}, mem, ops::Deref, sync::atomic::Ordering};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tokio::{fs::{self, DirEntry}, select, sync::mpsc::{self, UnboundedReceiver}};
|
use tokio::{fs::{self, DirEntry}, select, sync::mpsc::{self, UnboundedReceiver}};
|
||||||
@ -14,7 +14,7 @@ pub struct Files {
|
|||||||
version: u64,
|
version: u64,
|
||||||
pub(crate) revision: u64,
|
pub(crate) revision: u64,
|
||||||
|
|
||||||
pub sizes: BTreeMap<Url, u64>,
|
pub sizes: HashMap<Url, u64>,
|
||||||
|
|
||||||
sorter: FilesSorter,
|
sorter: FilesSorter,
|
||||||
filter: Option<Filter>,
|
filter: Option<Filter>,
|
||||||
@ -128,7 +128,7 @@ impl Files {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_size(&mut self, sizes: BTreeMap<Url, u64>) {
|
pub fn update_size(&mut self, sizes: HashMap<Url, u64>) {
|
||||||
if sizes.is_empty() {
|
if sizes.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ impl Files {
|
|||||||
|
|
||||||
macro_rules! go {
|
macro_rules! go {
|
||||||
($dist:expr, $src:expr, $inc:literal) => {
|
($dist:expr, $src:expr, $inc:literal) => {
|
||||||
let mut todo: BTreeMap<_, _> = $src.into_iter().map(|f| (f.url(), f)).collect();
|
let mut todo: HashMap<_, _> = $src.into_iter().map(|f| (f.url(), f)).collect();
|
||||||
for f in &$dist {
|
for f in &$dist {
|
||||||
if todo.remove(&f.url).is_some() && todo.is_empty() {
|
if todo.remove(&f.url).is_some() && todo.is_empty() {
|
||||||
break;
|
break;
|
||||||
@ -176,7 +176,7 @@ impl Files {
|
|||||||
|
|
||||||
macro_rules! go {
|
macro_rules! go {
|
||||||
($dist:expr, $src:expr, $inc:literal) => {
|
($dist:expr, $src:expr, $inc:literal) => {
|
||||||
let mut todo: BTreeSet<_> = $src.into_iter().collect();
|
let mut todo: HashSet<_> = $src.into_iter().collect();
|
||||||
let len = $dist.len();
|
let len = $dist.len();
|
||||||
|
|
||||||
$dist.retain(|f| !todo.remove(&f.url));
|
$dist.retain(|f| !todo.remove(&f.url));
|
||||||
@ -217,7 +217,7 @@ impl Files {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut urls: BTreeSet<_> = urls.into_iter().collect();
|
let mut urls: HashSet<_> = urls.into_iter().collect();
|
||||||
if !urls.is_empty() {
|
if !urls.is_empty() {
|
||||||
go!(self.items, urls, 1);
|
go!(self.items, urls, 1);
|
||||||
}
|
}
|
||||||
@ -228,8 +228,8 @@ impl Files {
|
|||||||
|
|
||||||
pub fn update_updating(
|
pub fn update_updating(
|
||||||
&mut self,
|
&mut self,
|
||||||
files: BTreeMap<Url, File>,
|
files: HashMap<Url, File>,
|
||||||
) -> (BTreeMap<Url, File>, BTreeMap<Url, File>) {
|
) -> (HashMap<Url, File>, HashMap<Url, File>) {
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
return Default::default();
|
return Default::default();
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ impl Files {
|
|||||||
|| !f.url.file_name().is_some_and(|s| filter.matches(s))
|
|| !f.url.file_name().is_some_and(|s| filter.matches(s))
|
||||||
})
|
})
|
||||||
} else if self.show_hidden {
|
} else if self.show_hidden {
|
||||||
(BTreeMap::new(), files)
|
(HashMap::new(), files)
|
||||||
} else {
|
} else {
|
||||||
files.into_iter().partition(|(_, f)| f.is_hidden())
|
files.into_iter().partition(|(_, f)| f.is_hidden())
|
||||||
};
|
};
|
||||||
@ -271,7 +271,7 @@ impl Files {
|
|||||||
(hidden, items)
|
(hidden, items)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_upserting(&mut self, files: BTreeMap<Url, File>) {
|
pub fn update_upserting(&mut self, files: HashMap<Url, File>) {
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{cmp::Ordering, collections::BTreeMap, mem};
|
use std::{cmp::Ordering, collections::HashMap, mem};
|
||||||
|
|
||||||
use yazi_config::manager::SortBy;
|
use yazi_config::manager::SortBy;
|
||||||
use yazi_shared::{fs::{File, Url}, natsort};
|
use yazi_shared::{fs::{File, Url}, natsort};
|
||||||
@ -12,7 +12,7 @@ pub struct FilesSorter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FilesSorter {
|
impl FilesSorter {
|
||||||
pub(super) fn sort(&self, items: &mut Vec<File>, sizes: &BTreeMap<Url, u64>) {
|
pub(super) fn sort(&self, items: &mut Vec<File>, sizes: &HashMap<Url, u64>) {
|
||||||
if items.is_empty() {
|
if items.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use yazi_shared::{event::Cmd, fs::Url, render};
|
use yazi_shared::{event::Cmd, fs::Url, render};
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ impl Manager {
|
|||||||
self.peek(false);
|
self.peek(false);
|
||||||
|
|
||||||
// Refresh watcher
|
// Refresh watcher
|
||||||
let mut to_watch = BTreeSet::new();
|
let mut to_watch = HashSet::with_capacity(3 * self.tabs.len());
|
||||||
for tab in self.tabs.iter() {
|
for tab in self.tabs.iter() {
|
||||||
to_watch.insert(&tab.current.cwd);
|
to_watch.insert(&tab.current.cwd);
|
||||||
if let Some(ref p) = tab.parent {
|
if let Some(ref p) = tab.parent {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::BTreeMap, ffi::{OsStr, OsString}, io::{stdout, BufWriter, Write}, path::PathBuf};
|
use std::{collections::HashMap, ffi::{OsStr, OsString}, io::{stdout, BufWriter, Write}, path::PathBuf};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}};
|
use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}};
|
||||||
@ -49,7 +49,7 @@ impl Manager {
|
|||||||
|
|
||||||
let file = File::from(new.clone()).await?;
|
let file = File::from(new.clone()).await?;
|
||||||
FilesOp::Deleting(file.parent().unwrap(), vec![new.clone()]).emit();
|
FilesOp::Deleting(file.parent().unwrap(), vec![new.clone()]).emit();
|
||||||
FilesOp::Upserting(file.parent().unwrap(), BTreeMap::from_iter([(old, file)])).emit();
|
FilesOp::Upserting(file.parent().unwrap(), HashMap::from_iter([(old, file)])).emit();
|
||||||
Ok(ManagerProxy::hover(Some(new)))
|
Ok(ManagerProxy::hover(Some(new)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use std::{collections::BTreeMap, ops::{Deref, DerefMut}};
|
use std::{collections::HashMap, ops::{Deref, DerefMut}};
|
||||||
|
|
||||||
use yazi_shared::fs::Url;
|
use yazi_shared::fs::Url;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Linked(BTreeMap<Url, Url> /* from ==> to */);
|
pub struct Linked(HashMap<Url, Url> /* from ==> to */);
|
||||||
|
|
||||||
impl Deref for Linked {
|
impl Deref for Linked {
|
||||||
type Target = BTreeMap<Url, Url>;
|
type Target = HashMap<Url, Url>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target { &self.0 }
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::{BTreeMap, BTreeSet}, sync::Arc, time::{Duration, SystemTime}};
|
use std::{collections::{HashMap, HashSet}, sync::Arc, time::{Duration, SystemTime}};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use notify::{event::{MetadataKind, ModifyKind}, EventKind, RecommendedWatcher, RecursiveMode, Watcher as _Watcher};
|
use notify::{event::{MetadataKind, ModifyKind}, EventKind, RecommendedWatcher, RecursiveMode, Watcher as _Watcher};
|
||||||
@ -14,7 +14,7 @@ use crate::folder::{Files, Folder};
|
|||||||
|
|
||||||
pub struct Watcher {
|
pub struct Watcher {
|
||||||
watcher: RecommendedWatcher,
|
watcher: RecommendedWatcher,
|
||||||
watched: Arc<RwLock<BTreeSet<Url>>>,
|
watched: Arc<RwLock<HashSet<Url>>>,
|
||||||
pub linked: Arc<RwLock<Linked>>,
|
pub linked: Arc<RwLock<Linked>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +60,11 @@ impl Watcher {
|
|||||||
instance
|
instance
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn watch(&mut self, mut new: BTreeSet<&Url>) {
|
pub(super) fn watch(&mut self, mut new: HashSet<&Url>) {
|
||||||
new.retain(|&u| u.is_regular());
|
new.retain(|&u| u.is_regular());
|
||||||
let (to_unwatch, to_watch): (BTreeSet<_>, BTreeSet<_>) = {
|
let (to_unwatch, to_watch): (HashSet<_>, HashSet<_>) = {
|
||||||
let guard = self.watched.read();
|
let guard = self.watched.read();
|
||||||
let old: BTreeSet<_> = guard.iter().collect();
|
let old: HashSet<_> = guard.iter().collect();
|
||||||
(
|
(
|
||||||
old.difference(&new).map(|&x| x.clone()).collect(),
|
old.difference(&new).map(|&x| x.clone()).collect(),
|
||||||
new.difference(&old).map(|&x| x.clone()).collect(),
|
new.difference(&old).map(|&x| x.clone()).collect(),
|
||||||
@ -147,7 +147,7 @@ impl Watcher {
|
|||||||
pin!(rx);
|
pin!(rx);
|
||||||
|
|
||||||
while let Some(urls) = rx.next().await {
|
while let Some(urls) = rx.next().await {
|
||||||
let urls: BTreeSet<_> = urls.into_iter().collect();
|
let urls: HashSet<_> = urls.into_iter().collect();
|
||||||
let mut reload = Vec::with_capacity(urls.len());
|
let mut reload = Vec::with_capacity(urls.len());
|
||||||
|
|
||||||
for u in urls {
|
for u in urls {
|
||||||
@ -163,7 +163,7 @@ impl Watcher {
|
|||||||
if !file.is_dir() {
|
if !file.is_dir() {
|
||||||
reload.push(file.clone());
|
reload.push(file.clone());
|
||||||
}
|
}
|
||||||
FilesOp::Upserting(parent, BTreeMap::from_iter([(u, file)])).emit();
|
FilesOp::Upserting(parent, HashMap::from_iter([(u, file)])).emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if reload.is_empty() {
|
if reload.is_empty() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use yazi_shared::{event::Cmd, render};
|
use yazi_shared::{event::Cmd, render};
|
||||||
|
|
||||||
@ -18,9 +18,9 @@ impl Tab {
|
|||||||
let idx = self.current.cursor;
|
let idx = self.current.cursor;
|
||||||
|
|
||||||
if opt.unset {
|
if opt.unset {
|
||||||
self.mode = Mode::Unset(idx, BTreeSet::from([idx]));
|
self.mode = Mode::Unset(idx, HashSet::from([idx]));
|
||||||
} else {
|
} else {
|
||||||
self.mode = Mode::Select(idx, BTreeSet::from([idx]));
|
self.mode = Mode::Select(idx, HashSet::from([idx]));
|
||||||
};
|
};
|
||||||
render!();
|
render!();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use yazi_shared::fs::Url;
|
use yazi_shared::fs::Url;
|
||||||
@ -7,7 +7,7 @@ use crate::folder::{Files, Filter, FilterCase};
|
|||||||
|
|
||||||
pub struct Finder {
|
pub struct Finder {
|
||||||
pub filter: Filter,
|
pub filter: Filter,
|
||||||
matched: BTreeMap<Url, u8>,
|
matched: HashMap<Url, u8>,
|
||||||
revision: u64,
|
revision: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ impl Finder {
|
|||||||
|
|
||||||
impl Finder {
|
impl Finder {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn matched(&self) -> &BTreeMap<Url, u8> { &self.matched }
|
pub fn matched(&self) -> &HashMap<Url, u8> { &self.matched }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn matched_idx(&self, url: &Url) -> Option<u8> { self.matched.get(url).copied() }
|
pub fn matched_idx(&self, url: &Url) -> Option<u8> { self.matched.get(url).copied() }
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
use std::{collections::BTreeSet, fmt::Display, mem};
|
use std::{collections::HashSet, fmt::Display, mem};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
#[default]
|
#[default]
|
||||||
Normal,
|
Normal,
|
||||||
Select(usize, BTreeSet<usize>),
|
Select(usize, HashSet<usize>),
|
||||||
Unset(usize, BTreeSet<usize>),
|
Unset(usize, HashSet<usize>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mode {
|
impl Mode {
|
||||||
pub fn visual_mut(&mut self) -> Option<(usize, &mut BTreeSet<usize>)> {
|
pub fn visual_mut(&mut self) -> Option<(usize, &mut HashSet<usize>)> {
|
||||||
match self {
|
match self {
|
||||||
Mode::Normal => None,
|
Mode::Normal => None,
|
||||||
Mode::Select(start, indices) => Some((*start, indices)),
|
Mode::Select(start, indices) => Some((*start, indices)),
|
||||||
@ -17,7 +17,7 @@ impl Mode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_visual(&mut self) -> Option<(usize, BTreeSet<usize>)> {
|
pub fn take_visual(&mut self) -> Option<(usize, HashSet<usize>)> {
|
||||||
match mem::take(self) {
|
match mem::take(self) {
|
||||||
Mode::Normal => None,
|
Mode::Normal => None,
|
||||||
Mode::Select(start, indices) => Some((start, indices)),
|
Mode::Select(start, indices) => Some((start, indices)),
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
use std::{collections::{BTreeSet, HashMap}, ops::Deref};
|
use std::{collections::{HashMap, HashSet}, ops::Deref};
|
||||||
|
|
||||||
use yazi_shared::fs::Url;
|
use yazi_shared::fs::Url;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Selected {
|
pub struct Selected {
|
||||||
inner: BTreeSet<Url>,
|
inner: HashSet<Url>,
|
||||||
parents: HashMap<Url, usize>,
|
parents: HashMap<Url, usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Selected {
|
impl Deref for Selected {
|
||||||
type Target = BTreeSet<Url>;
|
type Target = HashSet<Url>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target { &self.inner }
|
fn deref(&self) -> &Self::Target { &self.inner }
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
@ -14,7 +14,7 @@ pub struct Tab {
|
|||||||
pub parent: Option<Folder>,
|
pub parent: Option<Folder>,
|
||||||
|
|
||||||
pub backstack: Backstack<Url>,
|
pub backstack: Backstack<Url>,
|
||||||
pub history: BTreeMap<Url, Folder>,
|
pub history: HashMap<Url, Folder>,
|
||||||
pub selected: Selected,
|
pub selected: Selected,
|
||||||
|
|
||||||
pub preview: Preview,
|
pub preview: Preview,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::{BTreeMap, HashMap, HashSet}, ffi::OsStr, mem, sync::Arc, time::Duration};
|
use std::{collections::{HashMap, HashSet}, ffi::OsStr, mem, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
@ -57,7 +57,7 @@ impl Tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_open(&self, hovered: &Url, targets: &[(Url, String)]) {
|
pub fn file_open(&self, hovered: &Url, targets: &[(Url, String)]) {
|
||||||
let mut openers = BTreeMap::new();
|
let mut openers = HashMap::new();
|
||||||
for (url, mime) in targets {
|
for (url, mime) in targets {
|
||||||
if let Some(opener) = OPEN.openers(url, mime).and_then(|o| o.first().copied()) {
|
if let Some(opener) = OPEN.openers(url, mime).and_then(|o| o.first().copied()) {
|
||||||
openers.entry(opener).or_insert_with(|| vec![hovered]).push(url);
|
openers.entry(opener).or_insert_with(|| vec![hovered]).push(url);
|
||||||
|
25
yazi-fm/src/lives/iter.rs
Normal file
25
yazi-fm/src/lives/iter.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use mlua::AnyUserData;
|
||||||
|
|
||||||
|
use super::SCOPE;
|
||||||
|
|
||||||
|
pub(super) struct Iter<I: Iterator<Item = T>, T> {
|
||||||
|
inner: I,
|
||||||
|
count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I: Iterator<Item = T> + 'static, T: 'static> Iter<I, T> {
|
||||||
|
#[inline]
|
||||||
|
pub(super) fn make(inner: I) -> mlua::Result<AnyUserData<'static>> {
|
||||||
|
SCOPE.create_any_userdata(Self { inner, count: 0 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I: Iterator<Item = T>, T> Iterator for Iter<I, T> {
|
||||||
|
type Item = (usize, T);
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
let next = self.inner.next()?;
|
||||||
|
self.count += 1;
|
||||||
|
Some((self.count, next))
|
||||||
|
}
|
||||||
|
}
|
@ -45,7 +45,7 @@ impl Lives {
|
|||||||
("active", super::Tab::make(cx.manager.active())?),
|
("active", super::Tab::make(cx.manager.active())?),
|
||||||
("tabs", super::Tabs::make(&cx.manager.tabs)?),
|
("tabs", super::Tabs::make(&cx.manager.tabs)?),
|
||||||
("tasks", super::Tasks::make(&cx.tasks)?),
|
("tasks", super::Tasks::make(&cx.tasks)?),
|
||||||
("yanked", scope.create_any_userdata_ref(&cx.manager.yanked)?),
|
("yanked", super::Yanked::make(&cx.manager.yanked)?),
|
||||||
])?,
|
])?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ mod config;
|
|||||||
mod file;
|
mod file;
|
||||||
mod files;
|
mod files;
|
||||||
mod folder;
|
mod folder;
|
||||||
|
mod iter;
|
||||||
mod lives;
|
mod lives;
|
||||||
mod mode;
|
mod mode;
|
||||||
mod preview;
|
mod preview;
|
||||||
@ -17,6 +18,7 @@ use config::*;
|
|||||||
use file::*;
|
use file::*;
|
||||||
use files::*;
|
use files::*;
|
||||||
use folder::*;
|
use folder::*;
|
||||||
|
use iter::*;
|
||||||
pub(super) use lives::*;
|
pub(super) use lives::*;
|
||||||
use mode::*;
|
use mode::*;
|
||||||
use preview::*;
|
use preview::*;
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
use std::{collections::{btree_set, BTreeSet}, ops::Deref};
|
use std::{collections::{hash_set, HashSet}, ops::Deref};
|
||||||
|
|
||||||
use mlua::{AnyUserData, IntoLuaMulti, Lua, MetaMethod, UserDataMethods, UserDataRefMut};
|
use mlua::{AnyUserData, IntoLuaMulti, Lua, MetaMethod, UserDataMethods, UserDataRefMut};
|
||||||
use yazi_plugin::{bindings::Cast, url::Url};
|
use yazi_plugin::{bindings::Cast, url::Url};
|
||||||
|
|
||||||
use super::SCOPE;
|
use super::{Iter, SCOPE};
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub(super) struct Selected {
|
pub(super) struct Selected {
|
||||||
inner: *const BTreeSet<yazi_shared::fs::Url>,
|
inner: *const HashSet<yazi_shared::fs::Url>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Selected {
|
impl Deref for Selected {
|
||||||
type Target = BTreeSet<yazi_shared::fs::Url>;
|
type Target = HashSet<yazi_shared::fs::Url>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target { self.inner() }
|
fn deref(&self) -> &Self::Target { self.inner() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Selected {
|
impl Selected {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn make(inner: &BTreeSet<yazi_shared::fs::Url>) -> mlua::Result<AnyUserData<'static>> {
|
pub(super) fn make(inner: &HashSet<yazi_shared::fs::Url>) -> mlua::Result<AnyUserData<'static>> {
|
||||||
SCOPE.create_any_userdata(Self { inner })
|
SCOPE.create_any_userdata(Self { inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,16 +27,17 @@ impl Selected {
|
|||||||
reg.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len()));
|
reg.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len()));
|
||||||
|
|
||||||
reg.add_meta_method(MetaMethod::Pairs, |lua, me, ()| {
|
reg.add_meta_method(MetaMethod::Pairs, |lua, me, ()| {
|
||||||
let iter = lua.create_function(|lua, mut iter: UserDataRefMut<SelectedIter>| {
|
let iter = lua.create_function(
|
||||||
if let Some(url) = iter.inner.next() {
|
|lua, mut iter: UserDataRefMut<Iter<hash_set::Iter<yazi_shared::fs::Url>, _>>| {
|
||||||
iter.next += 1;
|
if let Some(next) = iter.next() {
|
||||||
(iter.next, Url::cast(lua, url.clone())?).into_lua_multi(lua)
|
(next.0, Url::cast(lua, next.1.clone())?).into_lua_multi(lua)
|
||||||
} else {
|
} else {
|
||||||
().into_lua_multi(lua)
|
().into_lua_multi(lua)
|
||||||
}
|
}
|
||||||
})?;
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok((iter, SelectedIter::make(me.inner())))
|
Ok((iter, Iter::make(me.inner().iter())))
|
||||||
});
|
});
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@ -44,17 +45,5 @@ impl Selected {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inner(&self) -> &'static BTreeSet<yazi_shared::fs::Url> { unsafe { &*self.inner } }
|
fn inner(&self) -> &'static HashSet<yazi_shared::fs::Url> { unsafe { &*self.inner } }
|
||||||
}
|
|
||||||
|
|
||||||
struct SelectedIter {
|
|
||||||
next: usize,
|
|
||||||
inner: btree_set::Iter<'static, yazi_shared::fs::Url>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SelectedIter {
|
|
||||||
#[inline]
|
|
||||||
fn make(selected: &'static BTreeSet<yazi_shared::fs::Url>) -> mlua::Result<AnyUserData<'static>> {
|
|
||||||
SCOPE.create_any_userdata(Self { next: 0, inner: selected.iter() })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ impl Deref for Tasks {
|
|||||||
|
|
||||||
impl Tasks {
|
impl Tasks {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn make(inner: &yazi_core::tasks::Tasks) -> mlua::Result<AnyUserData<'static>> {
|
pub(super) fn make(inner: &yazi_core::tasks::Tasks) -> mlua::Result<AnyUserData<'static>> {
|
||||||
SCOPE.create_any_userdata(Self { inner })
|
SCOPE.create_any_userdata(Self { inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,48 @@
|
|||||||
use mlua::{Lua, MetaMethod, UserDataFields, UserDataMethods};
|
use std::{collections::hash_set, ops::Deref};
|
||||||
|
|
||||||
pub(super) struct Yanked;
|
use mlua::{AnyUserData, IntoLuaMulti, Lua, MetaMethod, UserDataFields, UserDataMethods, UserDataRefMut};
|
||||||
|
use yazi_plugin::{bindings::Cast, url::Url};
|
||||||
|
|
||||||
|
use super::{Iter, SCOPE};
|
||||||
|
|
||||||
|
pub(super) struct Yanked {
|
||||||
|
inner: *const yazi_core::manager::Yanked,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for Yanked {
|
||||||
|
type Target = yazi_core::manager::Yanked;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target { self.inner() }
|
||||||
|
}
|
||||||
|
|
||||||
impl Yanked {
|
impl Yanked {
|
||||||
|
#[inline]
|
||||||
|
pub(super) fn make(inner: &yazi_core::manager::Yanked) -> mlua::Result<AnyUserData<'static>> {
|
||||||
|
SCOPE.create_any_userdata(Self { inner })
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn register(lua: &Lua) -> mlua::Result<()> {
|
pub(super) fn register(lua: &Lua) -> mlua::Result<()> {
|
||||||
lua.register_userdata_type::<yazi_core::manager::Yanked>(|reg| {
|
lua.register_userdata_type::<Self>(|reg| {
|
||||||
reg.add_field_method_get("is_cut", |_, me| Ok(me.cut));
|
reg.add_field_method_get("is_cut", |_, me| Ok(me.cut));
|
||||||
|
|
||||||
reg.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len()));
|
reg.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len()));
|
||||||
|
|
||||||
|
reg.add_meta_method(MetaMethod::Pairs, |lua, me, ()| {
|
||||||
|
let iter = lua.create_function(
|
||||||
|
|lua, mut iter: UserDataRefMut<Iter<hash_set::Iter<yazi_shared::fs::Url>, _>>| {
|
||||||
|
if let Some(next) = iter.next() {
|
||||||
|
(next.0, Url::cast(lua, next.1.clone())?).into_lua_multi(lua)
|
||||||
|
} else {
|
||||||
|
().into_lua_multi(lua)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok((iter, Iter::make(me.inner().iter())))
|
||||||
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn inner(&self) -> &'static yazi_core::manager::Yanked { unsafe { &*self.inner } }
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{borrow::Cow, collections::BTreeMap, ops::Deref};
|
use std::{borrow::Cow, collections::HashMap, ops::Deref};
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use mlua::{ExternalError, Table};
|
use mlua::{ExternalError, Table};
|
||||||
@ -13,7 +13,7 @@ pub static LOADED: RoCell<Loader> = RoCell::new();
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Loader {
|
pub struct Loader {
|
||||||
loaded: RwLock<BTreeMap<String, Vec<u8>>>,
|
loaded: RwLock<HashMap<String, Vec<u8>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Loader {
|
impl Loader {
|
||||||
@ -67,7 +67,7 @@ impl Loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Loader {
|
impl Deref for Loader {
|
||||||
type Target = RwLock<BTreeMap<String, Vec<u8>>>;
|
type Target = RwLock<HashMap<String, Vec<u8>>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target { &self.loaded }
|
fn deref(&self) -> &Self::Target { &self.loaded }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use mlua::{ExternalError, Lua, Table, Value};
|
use mlua::{ExternalError, Lua, Table, Value};
|
||||||
use yazi_shared::{emit, event::Cmd, render, Layer};
|
use yazi_shared::{emit, event::Cmd, render, Layer};
|
||||||
@ -7,9 +7,9 @@ use super::Utils;
|
|||||||
use crate::ValueSendable;
|
use crate::ValueSendable;
|
||||||
|
|
||||||
impl Utils {
|
impl Utils {
|
||||||
fn parse_args(t: Table) -> mlua::Result<(Vec<String>, BTreeMap<String, String>)> {
|
fn parse_args(t: Table) -> mlua::Result<(Vec<String>, HashMap<String, String>)> {
|
||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
let mut named = BTreeMap::new();
|
let mut named = HashMap::new();
|
||||||
for result in t.pairs::<Value, Value>() {
|
for result in t.pairs::<Value, Value>() {
|
||||||
let (k, v) = result?;
|
let (k, v) = result?;
|
||||||
match k {
|
match k {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
@ -16,7 +16,7 @@ pub struct Preload {
|
|||||||
prog: mpsc::UnboundedSender<TaskProg>,
|
prog: mpsc::UnboundedSender<TaskProg>,
|
||||||
|
|
||||||
pub rule_loaded: RwLock<HashMap<Url, u32>>,
|
pub rule_loaded: RwLock<HashMap<Url, u32>>,
|
||||||
pub size_loading: RwLock<BTreeSet<Url>>,
|
pub size_loading: RwLock<HashSet<Url>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Preload {
|
impl Preload {
|
||||||
@ -60,7 +60,7 @@ impl Preload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let parent = buf[0].0.parent_url().unwrap();
|
let parent = buf[0].0.parent_url().unwrap();
|
||||||
FilesOp::Size(parent, BTreeMap::from_iter(buf)).emit();
|
FilesOp::Size(parent, HashMap::from_iter(buf)).emit();
|
||||||
});
|
});
|
||||||
self.prog.send(TaskProg::Adv(task.id, 1, 0))?;
|
self.prog.send(TaskProg::Adv(task.id, 1, 0))?;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use yazi_config::TASKS;
|
use yazi_config::TASKS;
|
||||||
@ -10,9 +10,8 @@ use crate::TaskKind;
|
|||||||
pub struct Running {
|
pub struct Running {
|
||||||
incr: usize,
|
incr: usize,
|
||||||
|
|
||||||
pub(super) hooks:
|
pub(super) hooks: HashMap<usize, Box<dyn (FnOnce(bool) -> BoxFuture<'static, ()>) + Send + Sync>>,
|
||||||
BTreeMap<usize, Box<dyn (FnOnce(bool) -> BoxFuture<'static, ()>) + Send + Sync>>,
|
pub(super) all: HashMap<usize, Task>,
|
||||||
pub(super) all: BTreeMap<usize, Task>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Running {
|
impl Running {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use std::{any::Any, collections::BTreeMap, fmt::{self, Display}, mem};
|
use std::{any::Any, collections::HashMap, fmt::{self, Display}, mem};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Cmd {
|
pub struct Cmd {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub args: Vec<String>,
|
pub args: Vec<String>,
|
||||||
pub named: BTreeMap<String, String>,
|
pub named: HashMap<String, String>,
|
||||||
pub data: Option<Box<dyn Any + Send>>,
|
pub data: Option<Box<dyn Any + Send>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::BTreeMap, sync::atomic::{AtomicU64, Ordering}, time::SystemTime};
|
use std::{collections::HashMap, sync::atomic::{AtomicU64, Ordering}, time::SystemTime};
|
||||||
|
|
||||||
use super::File;
|
use super::File;
|
||||||
use crate::{emit, event::Cmd, fs::Url, Layer};
|
use crate::{emit, event::Cmd, fs::Url, Layer};
|
||||||
@ -10,12 +10,12 @@ pub enum FilesOp {
|
|||||||
Full(Url, Vec<File>, Option<SystemTime>),
|
Full(Url, Vec<File>, Option<SystemTime>),
|
||||||
Part(Url, Vec<File>, u64),
|
Part(Url, Vec<File>, u64),
|
||||||
Done(Url, Option<SystemTime>, u64),
|
Done(Url, Option<SystemTime>, u64),
|
||||||
Size(Url, BTreeMap<Url, u64>),
|
Size(Url, HashMap<Url, u64>),
|
||||||
|
|
||||||
Creating(Url, Vec<File>),
|
Creating(Url, Vec<File>),
|
||||||
Deleting(Url, Vec<Url>),
|
Deleting(Url, Vec<Url>),
|
||||||
Updating(Url, BTreeMap<Url, File>),
|
Updating(Url, HashMap<Url, File>),
|
||||||
Upserting(Url, BTreeMap<Url, File>),
|
Upserting(Url, HashMap<Url, File>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FilesOp {
|
impl FilesOp {
|
||||||
|
Loading…
Reference in New Issue
Block a user