mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
refactor: introduce LocBuf (#3062)
This commit is contained in:
parent
2ec3a6c645
commit
9810196565
114 changed files with 1156 additions and 1024 deletions
|
|
@ -5,7 +5,7 @@ use yazi_fs::{CWD, path::expand_url, provider};
|
|||
use yazi_macro::{act, render, succ};
|
||||
use yazi_parser::cmp::{CmpItem, ShowOpt, TriggerOpt};
|
||||
use yazi_proxy::CmpProxy;
|
||||
use yazi_shared::{OsStrSplit, event::Data, natsort, url::{Url, UrnBuf}};
|
||||
use yazi_shared::{OsStrSplit, event::Data, natsort, url::{UrlBuf, UrnBuf}};
|
||||
|
||||
use crate::{Actor, Ctx};
|
||||
|
||||
|
|
@ -66,8 +66,8 @@ impl Actor for Trigger {
|
|||
}
|
||||
|
||||
impl Trigger {
|
||||
fn split_url(s: &str) -> Option<(Url, UrnBuf)> {
|
||||
let (scheme, path, ..) = Url::parse(s.as_bytes()).ok()?;
|
||||
fn split_url(s: &str) -> Option<(UrlBuf, UrnBuf)> {
|
||||
let (scheme, path, ..) = UrlBuf::parse(s.as_bytes()).ok()?;
|
||||
|
||||
if !scheme.is_virtual() && path.as_os_str() == "~" {
|
||||
return None; // We don't autocomplete a `~`, but `~/`
|
||||
|
|
@ -79,8 +79,8 @@ impl Trigger {
|
|||
const SEP: char = std::path::MAIN_SEPARATOR;
|
||||
|
||||
Some(match path.as_os_str().rsplit_once(SEP) {
|
||||
Some((p, c)) if p.is_empty() => (Url { loc: MAIN_SEPARATOR_STR.into(), scheme }, c.into()),
|
||||
Some((p, c)) => (expand_url(Url { loc: p.into(), scheme }), c.into()),
|
||||
Some((p, c)) if p.is_empty() => (UrlBuf { loc: MAIN_SEPARATOR_STR.into(), scheme }, c.into()),
|
||||
Some((p, c)) => (expand_url(UrlBuf { loc: p.into(), scheme }), c.into()),
|
||||
None => (CWD.load().as_ref().clone(), path.into()),
|
||||
})
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ mod tests {
|
|||
fn compare(s: &str, parent: &str, child: &str) {
|
||||
let (mut p, c) = Trigger::split_url(s).unwrap();
|
||||
if let Some(u) = p.strip_prefix(yazi_fs::CWD.load().as_ref()) {
|
||||
p = Url::from(&**u);
|
||||
p = UrlBuf::from(&**u);
|
||||
}
|
||||
assert_eq!((p, c.as_urn()), (parent.parse().unwrap(), Urn::new(child)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::ops::{Deref, DerefMut};
|
|||
use anyhow::{Result, anyhow};
|
||||
use yazi_core::{Core, mgr::Tabs, tab::{Folder, Tab}, tasks::Tasks};
|
||||
use yazi_fs::File;
|
||||
use yazi_shared::{Source, event::Cmd, url::Url};
|
||||
use yazi_shared::{Source, event::Cmd, url::UrlBuf};
|
||||
|
||||
pub struct Ctx<'a> {
|
||||
pub core: &'a mut Core,
|
||||
|
|
@ -68,7 +68,7 @@ impl<'a> Ctx<'a> {
|
|||
pub fn tab_mut(&mut self) -> &mut Tab { &mut self.core.mgr.tabs[self.tab] }
|
||||
|
||||
#[inline]
|
||||
pub fn cwd(&self) -> &Url { self.tab().cwd() }
|
||||
pub fn cwd(&self) -> &UrlBuf { self.tab().cwd() }
|
||||
|
||||
#[inline]
|
||||
pub fn parent(&self) -> Option<&Folder> { self.tab().parent.as_ref() }
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use yazi_fs::{File, FilesOp, max_common_root, maybe_exists, path::skip_url, path
|
|||
use yazi_macro::{err, succ};
|
||||
use yazi_parser::VoidOpt;
|
||||
use yazi_proxy::{AppProxy, HIDER, TasksProxy, WATCHER};
|
||||
use yazi_shared::{OsStrJoin, event::Data, terminal_clear, url::{Component, Url}};
|
||||
use yazi_shared::{OsStrJoin, event::Data, terminal_clear, url::{Component, UrlBuf}};
|
||||
use yazi_term::tty::TTY;
|
||||
|
||||
use crate::{Actor, Ctx};
|
||||
|
|
@ -73,7 +73,12 @@ impl Actor for BulkRename {
|
|||
}
|
||||
|
||||
impl BulkRename {
|
||||
async fn r#do(root: usize, old: Vec<Tuple>, new: Vec<Tuple>, selected: Vec<Url>) -> Result<()> {
|
||||
async fn r#do(
|
||||
root: usize,
|
||||
old: Vec<Tuple>,
|
||||
new: Vec<Tuple>,
|
||||
selected: Vec<UrlBuf>,
|
||||
) -> Result<()> {
|
||||
terminal_clear(TTY.writer())?;
|
||||
if old.len() != new.len() {
|
||||
#[rustfmt::skip]
|
||||
|
|
@ -108,7 +113,7 @@ impl BulkRename {
|
|||
let permit = WATCHER.acquire().await.unwrap();
|
||||
let (mut failed, mut succeeded) = (Vec::new(), HashMap::with_capacity(todo.len()));
|
||||
for (o, n) in todo {
|
||||
let (old, new): (Url, Url) = (
|
||||
let (old, new): (UrlBuf, UrlBuf) = (
|
||||
selected[o.0].components().take(root).chain([Component::Normal(&o)]).collect(),
|
||||
selected[n.0].components().take(root).chain([Component::Normal(&n)]).collect(),
|
||||
);
|
||||
|
|
@ -138,7 +143,7 @@ impl BulkRename {
|
|||
}
|
||||
|
||||
fn opener() -> Option<&'static OpenerRule> {
|
||||
YAZI.opener.block(YAZI.open.all(Url::from(Path::new("bulk-rename.txt")), "text/plain"))
|
||||
YAZI.opener.block(YAZI.open.all(UrlBuf::from(Path::new("bulk-rename.txt")), "text/plain"))
|
||||
}
|
||||
|
||||
async fn output_failed(failed: Vec<(Tuple, Tuple, anyhow::Error)>) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use yazi_fs::{File, FilesOp, path::expand_url};
|
|||
use yazi_macro::{act, err, render, succ};
|
||||
use yazi_parser::mgr::CdOpt;
|
||||
use yazi_proxy::{CmpProxy, InputProxy, MgrProxy};
|
||||
use yazi_shared::{Debounce, errors::InputError, event::Data, url::Url};
|
||||
use yazi_shared::{Debounce, errors::InputError, event::Data, url::UrlBuf};
|
||||
|
||||
use crate::{Actor, Ctx};
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ impl Cd {
|
|||
while let Some(result) = rx.next().await {
|
||||
match result {
|
||||
Ok(s) => {
|
||||
let Ok(url) = Url::try_from(s).map(expand_url) else { return };
|
||||
let Ok(url) = UrlBuf::try_from(s).map(expand_url) else { return };
|
||||
|
||||
let Ok(file) = File::new(url.clone()).await else { return };
|
||||
if file.is_dir() {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use yazi_fs::{File, FilesOp, maybe_exists, ok_or_not_found, provider, realname};
|
|||
use yazi_macro::succ;
|
||||
use yazi_parser::mgr::CreateOpt;
|
||||
use yazi_proxy::{ConfirmProxy, InputProxy, MgrProxy, WATCHER};
|
||||
use yazi_shared::{event::Data, url::{Url, UrnBuf}};
|
||||
use yazi_shared::{event::Data, url::{UrlBuf, UrnBuf}};
|
||||
|
||||
use crate::{Actor, Ctx};
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ impl Actor for Create {
|
|||
}
|
||||
|
||||
impl Create {
|
||||
async fn r#do(new: Url, dir: bool) -> Result<()> {
|
||||
async fn r#do(new: UrlBuf, dir: bool) -> Result<()> {
|
||||
let Some(parent) = new.parent_url() else { return Ok(()) };
|
||||
let _permit = WATCHER.acquire().await.unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use yazi_macro::{act, succ};
|
|||
use yazi_parser::mgr::{OpenDoOpt, OpenOpt};
|
||||
use yazi_plugin::isolate;
|
||||
use yazi_proxy::{MgrProxy, PickProxy, TasksProxy};
|
||||
use yazi_shared::{MIME_DIR, event::{CmdCow, Data}, url::Url};
|
||||
use yazi_shared::{MIME_DIR, event::{CmdCow, Data}, url::UrlBuf};
|
||||
|
||||
use crate::{Actor, Ctx, mgr::Quit};
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ impl Actor for OpenDo {
|
|||
}
|
||||
|
||||
impl Open {
|
||||
fn guess_folder(cx: &Ctx, url: &Url) -> bool {
|
||||
fn guess_folder(cx: &Ctx, url: &UrlBuf) -> bool {
|
||||
let Some(p) = url.parent_url() else {
|
||||
return true;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use yazi_dds::spark::SparkKind;
|
|||
use yazi_macro::{emit, succ};
|
||||
use yazi_parser::mgr::{OpenOpt, QuitOpt};
|
||||
use yazi_proxy::ConfirmProxy;
|
||||
use yazi_shared::{event::{Data, EventQuit}, url::Url};
|
||||
use yazi_shared::{event::{Data, EventQuit}, url::UrlBuf};
|
||||
|
||||
use crate::{Actor, Ctx};
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ impl Actor for Quit {
|
|||
impl Quit {
|
||||
pub(super) fn quit_with_selected<'a, I>(opt: OpenOpt, selected: I) -> bool
|
||||
where
|
||||
I: Iterator<Item = &'a Url>,
|
||||
I: Iterator<Item = &'a UrlBuf>,
|
||||
{
|
||||
if opt.interactive || ARGS.chooser_file.is_none() {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use yazi_fs::{File, FilesOp, maybe_exists, ok_or_not_found, paths_to_same_file,
|
|||
use yazi_macro::{act, err, succ};
|
||||
use yazi_parser::mgr::RenameOpt;
|
||||
use yazi_proxy::{ConfirmProxy, InputProxy, MgrProxy, WATCHER};
|
||||
use yazi_shared::{Id, event::Data, url::{Url, UrnBuf}};
|
||||
use yazi_shared::{Id, event::Data, url::{UrlBuf, UrnBuf}};
|
||||
|
||||
use crate::{Actor, Ctx};
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ impl Actor for Rename {
|
|||
return;
|
||||
}
|
||||
|
||||
let new = Url::from(old.parent().unwrap().join(name));
|
||||
let new = UrlBuf::from(old.parent().unwrap().join(name));
|
||||
if opt.force || !maybe_exists(&new).await || paths_to_same_file(&old, &new).await {
|
||||
Self::r#do(tab, old, new).await.ok();
|
||||
} else if ConfirmProxy::show(ConfirmCfg::overwrite(&new)).await {
|
||||
|
|
@ -59,7 +59,7 @@ impl Actor for Rename {
|
|||
}
|
||||
|
||||
impl Rename {
|
||||
async fn r#do(tab: Id, old: Url, new: Url) -> Result<()> {
|
||||
async fn r#do(tab: Id, old: UrlBuf, new: UrlBuf) -> Result<()> {
|
||||
let Some((p_old, n_old)) = old.pair() else { return Ok(()) };
|
||||
let Some((p_new, n_new)) = new.pair() else { return Ok(()) };
|
||||
let _permit = WATCHER.acquire().await.unwrap();
|
||||
|
|
@ -85,7 +85,7 @@ impl Rename {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn empty_url_part(url: &Url, by: &str) -> String {
|
||||
fn empty_url_part(url: &UrlBuf, by: &str) -> String {
|
||||
if by == "all" {
|
||||
return String::new();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use anyhow::Result;
|
|||
use yazi_core::mgr::Yanked;
|
||||
use yazi_macro::{act, render};
|
||||
use yazi_parser::mgr::YankOpt;
|
||||
use yazi_shared::{event::Data, url::CovUrl};
|
||||
use yazi_shared::{event::Data, url::UrlCov};
|
||||
|
||||
use crate::{Actor, Ctx};
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ impl Actor for Yank {
|
|||
act!(mgr:escape_visual, cx)?;
|
||||
|
||||
cx.mgr.yanked =
|
||||
Yanked::new(opt.cut, cx.tab().selected_or_hovered().cloned().map(CovUrl).collect());
|
||||
Yanked::new(opt.cut, cx.tab().selected_or_hovered().cloned().map(UrlCov).collect());
|
||||
render!(cx.mgr.yanked.catchup_revision(true));
|
||||
|
||||
act!(mgr:escape_select, cx)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{env, fmt::Display};
|
|||
use anyhow::Result;
|
||||
use ratatui::layout::Rect;
|
||||
use tracing::warn;
|
||||
use yazi_shared::{env_exists, url::Url};
|
||||
use yazi_shared::{env_exists, url::UrlBuf};
|
||||
|
||||
use crate::{Emulator, SHOWN, TMUX, drivers};
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ impl Display for Adapter {
|
|||
}
|
||||
|
||||
impl Adapter {
|
||||
pub async fn image_show(self, url: &Url, max: Rect) -> Result<Rect> {
|
||||
pub async fn image_show(self, url: &UrlBuf, max: Rect) -> Result<Rect> {
|
||||
if max.is_empty() {
|
||||
return Ok(Rect::default());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ use crossterm::{cursor::MoveTo, queue};
|
|||
use image::{DynamicImage, ExtendedColorType, ImageEncoder, codecs::{jpeg::JpegEncoder, png::PngEncoder}};
|
||||
use ratatui::layout::Rect;
|
||||
use yazi_config::YAZI;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use crate::{CLOSE, Emulator, Image, START, adapter::Adapter};
|
||||
|
||||
pub(crate) struct Iip;
|
||||
|
||||
impl Iip {
|
||||
pub(crate) async fn image_show(url: &Url, max: Rect) -> Result<Rect> {
|
||||
pub(crate) async fn image_show(url: &UrlBuf, max: Rect) -> Result<Rect> {
|
||||
let img = Image::downscale(url, max).await?;
|
||||
let area = Image::pixel_area((img.width(), img.height()), max);
|
||||
let b = Self::encode(img).await?;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use base64::{Engine, engine::general_purpose};
|
|||
use crossterm::{cursor::MoveTo, queue};
|
||||
use image::DynamicImage;
|
||||
use ratatui::layout::Rect;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use crate::{CLOSE, ESCAPE, Emulator, START, adapter::Adapter, image::Image};
|
||||
|
||||
|
|
@ -313,7 +313,7 @@ static DIACRITICS: [char; 297] = [
|
|||
pub(crate) struct Kgp;
|
||||
|
||||
impl Kgp {
|
||||
pub(crate) async fn image_show(url: &Url, max: Rect) -> Result<Rect> {
|
||||
pub(crate) async fn image_show(url: &UrlBuf, max: Rect) -> Result<Rect> {
|
||||
let img = Image::downscale(url, max).await?;
|
||||
let area = Image::pixel_area((img.width(), img.height()), max);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use anyhow::Result;
|
|||
use base64::{Engine, engine::general_purpose};
|
||||
use image::DynamicImage;
|
||||
use ratatui::layout::Rect;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
use yazi_term::tty::TTY;
|
||||
|
||||
use crate::{CLOSE, ESCAPE, Emulator, Image, START, adapter::Adapter};
|
||||
|
|
@ -13,7 +13,7 @@ use crate::{CLOSE, ESCAPE, Emulator, Image, START, adapter::Adapter};
|
|||
pub(crate) struct KgpOld;
|
||||
|
||||
impl KgpOld {
|
||||
pub(crate) async fn image_show(url: &Url, max: Rect) -> Result<Rect> {
|
||||
pub(crate) async fn image_show(url: &UrlBuf, max: Rect) -> Result<Rect> {
|
||||
let img = Image::downscale(url, max).await?;
|
||||
let area = Image::pixel_area((img.width(), img.height()), max);
|
||||
let b = Self::encode(img).await?;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ use image::{DynamicImage, GenericImageView, RgbImage};
|
|||
use palette::{Srgb, cast::ComponentsAs};
|
||||
use quantette::{ColorSlice, PaletteSize, QuantizeOutput, wu::UIntBinner};
|
||||
use ratatui::layout::Rect;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use crate::{CLOSE, ESCAPE, Emulator, Image, START, adapter::Adapter};
|
||||
|
||||
pub(crate) struct Sixel;
|
||||
|
||||
impl Sixel {
|
||||
pub(crate) async fn image_show(url: &Url, max: Rect) -> Result<Rect> {
|
||||
pub(crate) async fn image_show(url: &UrlBuf, max: Rect) -> Result<Rect> {
|
||||
let img = Image::downscale(url, max).await?;
|
||||
let area = Image::pixel_area((img.width(), img.height()), max);
|
||||
let b = Self::encode(img).await?;
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ use image::{DynamicImage, ExtendedColorType, ImageDecoder, ImageEncoder, ImageEr
|
|||
use ratatui::layout::Rect;
|
||||
use yazi_config::YAZI;
|
||||
use yazi_fs::provider;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use crate::Dimension;
|
||||
|
||||
pub struct Image;
|
||||
|
||||
impl Image {
|
||||
pub async fn precache(src: &Url, cache: &Url) -> Result<()> {
|
||||
pub async fn precache(src: &UrlBuf, cache: &UrlBuf) -> Result<()> {
|
||||
let (mut img, orientation, icc) = Self::decode_from(src).await?;
|
||||
let (w, h) = Self::flip_size(orientation, (YAZI.preview.max_width, YAZI.preview.max_height));
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ impl Image {
|
|||
Ok(provider::write(cache, buf).await?)
|
||||
}
|
||||
|
||||
pub(super) async fn downscale(url: &Url, rect: Rect) -> Result<DynamicImage> {
|
||||
pub(super) async fn downscale(url: &UrlBuf, rect: Rect) -> Result<DynamicImage> {
|
||||
let (mut img, orientation, _) = Self::decode_from(url).await?;
|
||||
let (w, h) = Self::flip_size(orientation, Self::max_pixel(rect));
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ impl Image {
|
|||
}
|
||||
}
|
||||
|
||||
async fn decode_from(url: &Url) -> ImageResult<(DynamicImage, Orientation, Option<Vec<u8>>)> {
|
||||
async fn decode_from(url: &UrlBuf) -> ImageResult<(DynamicImage, Orientation, Option<Vec<u8>>)> {
|
||||
let mut limits = Limits::no_limits();
|
||||
if YAZI.tasks.image_alloc > 0 {
|
||||
limits.max_alloc = Some(YAZI.tasks.image_alloc as u64);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use std::{borrow::Cow, ops::Deref};
|
||||
|
||||
use mlua::{AnyUserData, ExternalError, FromLua, Lua, MetaMethod, UserData, UserDataFields, UserDataMethods, UserDataRef, Value};
|
||||
use yazi_shared::url::CovUrl;
|
||||
use yazi_shared::url::UrlCov;
|
||||
|
||||
use crate::{Urn, cached_field, deprecate};
|
||||
|
||||
pub type UrlRef = UserDataRef<Url>;
|
||||
|
||||
pub struct Url {
|
||||
inner: yazi_shared::url::Url,
|
||||
inner: yazi_shared::url::UrlBuf,
|
||||
|
||||
v_name: Option<Value>,
|
||||
v_stem: Option<Value>,
|
||||
|
|
@ -20,41 +20,41 @@ pub struct Url {
|
|||
}
|
||||
|
||||
impl Deref for Url {
|
||||
type Target = yazi_shared::url::Url;
|
||||
type Target = yazi_shared::url::UrlBuf;
|
||||
|
||||
fn deref(&self) -> &Self::Target { &self.inner }
|
||||
}
|
||||
|
||||
impl AsRef<yazi_shared::url::Url> for Url {
|
||||
fn as_ref(&self) -> &yazi_shared::url::Url { &self.inner }
|
||||
impl AsRef<yazi_shared::url::UrlBuf> for Url {
|
||||
fn as_ref(&self) -> &yazi_shared::url::UrlBuf { &self.inner }
|
||||
}
|
||||
|
||||
impl From<Url> for yazi_shared::url::Url {
|
||||
impl From<Url> for yazi_shared::url::UrlBuf {
|
||||
fn from(value: Url) -> Self { value.inner }
|
||||
}
|
||||
|
||||
impl From<Url> for Cow<'_, yazi_shared::url::Url> {
|
||||
impl From<Url> for Cow<'_, yazi_shared::url::UrlBuf> {
|
||||
fn from(value: Url) -> Self { Cow::Owned(value.inner) }
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Url> for Cow<'a, yazi_shared::url::Url> {
|
||||
impl<'a> From<&'a Url> for Cow<'a, yazi_shared::url::UrlBuf> {
|
||||
fn from(value: &'a Url) -> Self { Cow::Borrowed(&value.inner) }
|
||||
}
|
||||
|
||||
impl From<Url> for yazi_shared::url::CovUrl {
|
||||
fn from(value: Url) -> Self { CovUrl(value.inner) }
|
||||
impl From<Url> for yazi_shared::url::UrlCov {
|
||||
fn from(value: Url) -> Self { UrlCov(value.inner) }
|
||||
}
|
||||
|
||||
impl TryFrom<&[u8]> for Url {
|
||||
type Error = mlua::Error;
|
||||
|
||||
fn try_from(value: &[u8]) -> mlua::Result<Self> {
|
||||
Ok(Self::new(yazi_shared::url::Url::try_from(value)?))
|
||||
Ok(Self::new(yazi_shared::url::UrlBuf::try_from(value)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl Url {
|
||||
pub fn new(url: impl Into<yazi_shared::url::Url>) -> Self {
|
||||
pub fn new(url: impl Into<yazi_shared::url::UrlBuf>) -> Self {
|
||||
Self {
|
||||
inner: url.into(),
|
||||
|
||||
|
|
@ -104,9 +104,7 @@ impl UserData for Url {
|
|||
});
|
||||
cached_field!(fields, parent, |_, me| Ok(me.parent_url().map(Self::new)));
|
||||
cached_field!(fields, urn, |_, me| Ok(Urn::new(me.urn_owned())));
|
||||
cached_field!(fields, base, |_, me| {
|
||||
Ok(if me.base().as_os_str().is_empty() { None } else { Some(Self::new(me.base())) })
|
||||
});
|
||||
cached_field!(fields, base, |_, me| Ok(me.base().map(Self::new)));
|
||||
cached_field!(fields, domain, |lua, me| {
|
||||
me.scheme.domain().map(|s| lua.create_string(s)).transpose()
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{env, ffi::OsStr, fmt::Write, path::Path};
|
|||
use regex::Regex;
|
||||
use yazi_adapter::Mux;
|
||||
use yazi_config::YAZI;
|
||||
use yazi_shared::{timestamp_us, url::Url};
|
||||
use yazi_shared::{timestamp_us, url::UrlBuf};
|
||||
|
||||
use super::Actions;
|
||||
|
||||
|
|
@ -58,17 +58,17 @@ impl Actions {
|
|||
writeln!(
|
||||
s,
|
||||
" default : {:?}",
|
||||
YAZI.opener.first(YAZI.open.all(Url::from(Path::new("f75a.txt")), "text/plain"))
|
||||
YAZI.opener.first(YAZI.open.all(UrlBuf::from(Path::new("f75a.txt")), "text/plain"))
|
||||
)?;
|
||||
writeln!(
|
||||
s,
|
||||
" block-create: {:?}",
|
||||
YAZI.opener.block(YAZI.open.all(Url::from(Path::new("bulk-create.txt")), "text/plain"))
|
||||
YAZI.opener.block(YAZI.open.all(UrlBuf::from(Path::new("bulk-create.txt")), "text/plain"))
|
||||
)?;
|
||||
writeln!(
|
||||
s,
|
||||
" block-rename: {:?}",
|
||||
YAZI.opener.block(YAZI.open.all(Url::from(Path::new("bulk-rename.txt")), "text/plain"))
|
||||
YAZI.opener.block(YAZI.open.all(UrlBuf::from(Path::new("bulk-rename.txt")), "text/plain"))
|
||||
)?;
|
||||
|
||||
writeln!(s, "\nMultiplexers")?;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Parser, command};
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
|
||||
#[derive(Debug, Default, Parser)]
|
||||
#[command(name = "yazi")]
|
||||
pub struct Args {
|
||||
/// Set the current working entry
|
||||
#[arg(index = 1, num_args = 1..=9)]
|
||||
pub entries: Vec<Url>,
|
||||
pub entries: Vec<UrlBuf>,
|
||||
|
||||
/// Write the cwd on exit to this file
|
||||
#[arg(long)]
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ use std::{collections::HashSet, path::PathBuf};
|
|||
use futures::executor::block_on;
|
||||
use serde::Serialize;
|
||||
use yazi_fs::{CWD, Xdg, path::expand_url, provider};
|
||||
use yazi_shared::url::{Url, UrnBuf};
|
||||
use yazi_shared::url::{UrlBuf, UrnBuf};
|
||||
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
pub struct Boot {
|
||||
pub cwds: Vec<Url>,
|
||||
pub cwds: Vec<UrlBuf>,
|
||||
pub files: Vec<UrnBuf>,
|
||||
|
||||
pub local_events: HashSet<String>,
|
||||
|
|
@ -20,12 +20,12 @@ pub struct Boot {
|
|||
}
|
||||
|
||||
impl Boot {
|
||||
async fn parse_entries(entries: &[Url]) -> (Vec<Url>, Vec<UrnBuf>) {
|
||||
async fn parse_entries(entries: &[UrlBuf]) -> (Vec<UrlBuf>, Vec<UrnBuf>) {
|
||||
if entries.is_empty() {
|
||||
return (vec![CWD.load().as_ref().clone()], vec![UrnBuf::default()]);
|
||||
}
|
||||
|
||||
async fn go<'a>(entry: Url) -> (Url, UrnBuf) {
|
||||
async fn go<'a>(entry: UrlBuf) -> (UrlBuf, UrnBuf) {
|
||||
let Some((parent, child)) = entry.pair() else {
|
||||
return (entry, UrnBuf::default());
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use anyhow::{Result, bail};
|
|||
use serde::Deserialize;
|
||||
use yazi_codegen::DeserializeOver2;
|
||||
use yazi_fs::{CWD, SortBy};
|
||||
use yazi_shared::{SyncCell, url::Url};
|
||||
use yazi_shared::{SyncCell, url::UrlBuf};
|
||||
|
||||
use super::{MgrRatio, MouseEvents};
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ impl Mgr {
|
|||
return None;
|
||||
}
|
||||
|
||||
let home = Url::from(dirs::home_dir().unwrap_or_default());
|
||||
let home = UrlBuf::from(dirs::home_dir().unwrap_or_default());
|
||||
let cwd = if let Some(u) = CWD.load().strip_prefix(home) {
|
||||
format!("~{}{}", std::path::MAIN_SEPARATOR, u.display())
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use anyhow::Result;
|
|||
use indexmap::IndexSet;
|
||||
use serde::Deserialize;
|
||||
use yazi_codegen::DeserializeOver2;
|
||||
use yazi_shared::{MIME_DIR, url::Url};
|
||||
use yazi_shared::{MIME_DIR, url::UrlBuf};
|
||||
|
||||
use crate::{Preset, open::OpenRule};
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ impl Open {
|
|||
pub fn all<'a, 'b, P, M>(&'a self, url: P, mime: M) -> impl Iterator<Item = &'a str> + 'b
|
||||
where
|
||||
'a: 'b,
|
||||
P: AsRef<Url> + 'b,
|
||||
P: AsRef<UrlBuf> + 'b,
|
||||
M: AsRef<str> + 'b,
|
||||
{
|
||||
let is_dir = mime.as_ref() == MIME_DIR;
|
||||
|
|
@ -42,7 +42,10 @@ impl Open {
|
|||
.map(String::as_str)
|
||||
}
|
||||
|
||||
pub fn common<'a>(&'a self, targets: &[(impl AsRef<Url>, impl AsRef<str>)]) -> IndexSet<&'a str> {
|
||||
pub fn common<'a>(
|
||||
&'a self,
|
||||
targets: &[(impl AsRef<UrlBuf>, impl AsRef<str>)],
|
||||
) -> IndexSet<&'a str> {
|
||||
let each: Vec<IndexSet<&str>> = targets
|
||||
.iter()
|
||||
.map(|(u, m)| self.all(u, m).collect::<IndexSet<_>>())
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::str::FromStr;
|
|||
use anyhow::Result;
|
||||
use globset::GlobBuilder;
|
||||
use serde::Deserialize;
|
||||
use yazi_shared::url::{Scheme, Url};
|
||||
use yazi_shared::url::{Scheme, UrlBuf};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(try_from = "String")]
|
||||
|
|
@ -18,7 +18,7 @@ pub struct Pattern {
|
|||
|
||||
impl Pattern {
|
||||
#[inline]
|
||||
pub fn match_url(&self, url: impl AsRef<Url>, is_dir: bool) -> bool {
|
||||
pub fn match_url(&self, url: impl AsRef<UrlBuf>, is_dir: bool) -> bool {
|
||||
let url = url.as_ref();
|
||||
|
||||
if is_dir != self.is_dir {
|
||||
|
|
@ -124,7 +124,7 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
fn matches(glob: &str, url: &str) -> bool {
|
||||
Pattern::from_str(glob).unwrap().match_url(Url::from_str(url).unwrap(), false)
|
||||
Pattern::from_str(glob).unwrap().match_url(UrlBuf::from_str(url).unwrap(), false)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use yazi_shared::{MIME_DIR, event::Cmd, url::Url};
|
||||
use yazi_shared::{MIME_DIR, event::Cmd, url::UrlBuf};
|
||||
|
||||
use crate::{Pattern, Priority};
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ pub struct Fetcher {
|
|||
|
||||
impl Fetcher {
|
||||
#[inline]
|
||||
pub fn matches(&self, url: &Url, mime: &str) -> bool {
|
||||
pub fn matches(&self, url: &UrlBuf, mime: &str) -> bool {
|
||||
self.mime.as_ref().is_some_and(|p| p.match_mime(mime))
|
||||
|| self.url.as_ref().is_some_and(|p| p.match_url(url, mime == MIME_DIR))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use serde::Deserialize;
|
|||
use tracing::warn;
|
||||
use yazi_codegen::DeserializeOver2;
|
||||
use yazi_fs::File;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::{Fetcher, Preloader, Previewer, Spotter};
|
||||
use crate::{Preset, plugin::MAX_PREWORKERS};
|
||||
|
|
@ -40,7 +40,7 @@ pub struct Plugin {
|
|||
impl Plugin {
|
||||
pub fn fetchers<'a, 'b: 'a>(
|
||||
&'b self,
|
||||
url: &'a Url,
|
||||
url: &'a UrlBuf,
|
||||
mime: &'a str,
|
||||
) -> impl Iterator<Item = &'b Fetcher> + 'a {
|
||||
let mut seen = HashSet::new();
|
||||
|
|
@ -69,13 +69,13 @@ impl Plugin {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn spotter(&self, url: &Url, mime: &str) -> Option<&Spotter> {
|
||||
pub fn spotter(&self, url: &UrlBuf, mime: &str) -> Option<&Spotter> {
|
||||
self.spotters.iter().find(|&p| p.matches(url, mime))
|
||||
}
|
||||
|
||||
pub fn preloaders<'a, 'b: 'a>(
|
||||
&'b self,
|
||||
url: &'a Url,
|
||||
url: &'a UrlBuf,
|
||||
mime: &'a str,
|
||||
) -> impl Iterator<Item = &'b Preloader> + 'a {
|
||||
let mut next = true;
|
||||
|
|
@ -88,7 +88,7 @@ impl Plugin {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn previewer(&self, url: &Url, mime: &str) -> Option<&Previewer> {
|
||||
pub fn previewer(&self, url: &UrlBuf, mime: &str) -> Option<&Previewer> {
|
||||
self.previewers.iter().find(|&p| p.matches(url, mime))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use yazi_shared::{MIME_DIR, event::Cmd, url::Url};
|
||||
use yazi_shared::{MIME_DIR, event::Cmd, url::UrlBuf};
|
||||
|
||||
use crate::{Pattern, Priority};
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ pub struct Preloader {
|
|||
|
||||
impl Preloader {
|
||||
#[inline]
|
||||
pub fn matches(&self, url: &Url, mime: &str) -> bool {
|
||||
pub fn matches(&self, url: &UrlBuf, mime: &str) -> bool {
|
||||
self.mime.as_ref().is_some_and(|p| p.match_mime(mime))
|
||||
|| self.url.as_ref().is_some_and(|p| p.match_url(url, mime == MIME_DIR))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use yazi_shared::{MIME_DIR, event::Cmd, url::Url};
|
||||
use yazi_shared::{MIME_DIR, event::Cmd, url::UrlBuf};
|
||||
|
||||
use crate::Pattern;
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ pub struct Previewer {
|
|||
|
||||
impl Previewer {
|
||||
#[inline]
|
||||
pub fn matches(&self, url: &Url, mime: &str) -> bool {
|
||||
pub fn matches(&self, url: &UrlBuf, mime: &str) -> bool {
|
||||
self.mime.as_ref().is_some_and(|p| p.match_mime(mime))
|
||||
|| self.url.as_ref().is_some_and(|p| p.match_url(url, mime == MIME_DIR))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use yazi_shared::{MIME_DIR, event::Cmd, url::Url};
|
||||
use yazi_shared::{MIME_DIR, event::Cmd, url::UrlBuf};
|
||||
|
||||
use crate::Pattern;
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ pub struct Spotter {
|
|||
|
||||
impl Spotter {
|
||||
#[inline]
|
||||
pub fn matches(&self, url: &Url, mime: &str) -> bool {
|
||||
pub fn matches(&self, url: &UrlBuf, mime: &str) -> bool {
|
||||
self.mime.as_ref().is_some_and(|p| p.match_mime(mime))
|
||||
|| self.url.as_ref().is_some_and(|p| p.match_url(url, mime == MIME_DIR))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use ratatui::{text::{Line, Text}, widgets::{Paragraph, Wrap}};
|
||||
use yazi_shared::{IntoStringLossy, url::Url};
|
||||
use yazi_shared::{IntoStringLossy, url::UrlBuf};
|
||||
|
||||
use super::{Offset, Position};
|
||||
use crate::YAZI;
|
||||
|
|
@ -118,7 +118,7 @@ impl ConfirmCfg {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn trash(urls: &[yazi_shared::url::Url]) -> Self {
|
||||
pub fn trash(urls: &[yazi_shared::url::UrlBuf]) -> Self {
|
||||
Self::new(
|
||||
Self::replace_number(&YAZI.confirm.trash_title, urls.len()),
|
||||
YAZI.confirm.trash_position(),
|
||||
|
|
@ -127,7 +127,7 @@ impl ConfirmCfg {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn delete(urls: &[yazi_shared::url::Url]) -> Self {
|
||||
pub fn delete(urls: &[yazi_shared::url::UrlBuf]) -> Self {
|
||||
Self::new(
|
||||
Self::replace_number(&YAZI.confirm.delete_title, urls.len()),
|
||||
YAZI.confirm.delete_position(),
|
||||
|
|
@ -136,7 +136,7 @@ impl ConfirmCfg {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn overwrite(url: &Url) -> Self {
|
||||
pub fn overwrite(url: &UrlBuf) -> Self {
|
||||
Self::new(
|
||||
YAZI.confirm.overwrite_title.to_owned(),
|
||||
YAZI.confirm.overwrite_position(),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use anyhow::{Context, Result, bail};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use yazi_codegen::DeserializeOver2;
|
||||
use yazi_fs::{Xdg, path::expand_url};
|
||||
use yazi_shared::{SStr, timestamp_us, url::Url};
|
||||
use yazi_shared::{SStr, timestamp_us, url::UrlBuf};
|
||||
|
||||
use super::PreviewWrap;
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ impl Preview {
|
|||
|
||||
self.cache_dir = if self.cache_dir.as_os_str().is_empty() {
|
||||
Xdg::cache_dir()
|
||||
} else if let Some(p) = expand_url(Url::from(&self.cache_dir)).into_path() {
|
||||
} else if let Some(p) = expand_url(UrlBuf::from(&self.cache_dir)).into_path() {
|
||||
p
|
||||
} else {
|
||||
bail!("[preview].cache_dir must be a path within local filesystem.");
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use anyhow::{Context, Result, anyhow, bail};
|
|||
use serde::Deserialize;
|
||||
use yazi_codegen::{DeserializeOver1, DeserializeOver2};
|
||||
use yazi_fs::{Xdg, ok_or_not_found, path::expand_url};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::{Filetype, Flavor, Icon};
|
||||
use crate::Style;
|
||||
|
|
@ -223,7 +223,7 @@ impl Theme {
|
|||
self.mgr.syntect_theme = self
|
||||
.flavor
|
||||
.syntect_path(light)
|
||||
.or_else(|| expand_url(Url::from(&self.mgr.syntect_theme)).into_path())
|
||||
.or_else(|| expand_url(UrlBuf::from(&self.mgr.syntect_theme)).into_path())
|
||||
.ok_or(anyhow!("[mgr].syntect_theme must be a path within local filesystem"))?;
|
||||
|
||||
Ok(self)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use yazi_parser::cmp::CmpItem;
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
use yazi_widgets::Scrollable;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Cmp {
|
||||
pub caches: HashMap<Url, Vec<CmpItem>>,
|
||||
pub caches: HashMap<UrlBuf, Vec<CmpItem>>,
|
||||
pub cands: Vec<CmpItem>,
|
||||
pub offset: usize,
|
||||
pub cursor: usize,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use std::{collections::HashMap, iter, ops::{Deref, DerefMut}};
|
||||
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Linked(HashMap<Url, Url> /* from ==> to */);
|
||||
pub struct Linked(HashMap<UrlBuf, UrlBuf> /* from ==> to */);
|
||||
|
||||
impl Deref for Linked {
|
||||
type Target = HashMap<Url, Url>;
|
||||
type Target = HashMap<UrlBuf, UrlBuf>;
|
||||
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ impl DerefMut for Linked {
|
|||
}
|
||||
|
||||
impl Linked {
|
||||
pub fn from_dir<'a, 'b>(&'a self, url: &'b Url) -> Box<dyn Iterator<Item = &'a Url> + 'b>
|
||||
pub fn from_dir<'a, 'b>(&'a self, url: &'b UrlBuf) -> Box<dyn Iterator<Item = &'a UrlBuf> + 'b>
|
||||
where
|
||||
'a: 'b,
|
||||
{
|
||||
|
|
@ -29,7 +29,7 @@ impl Linked {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_file(&self, url: &Url) -> Vec<Url> {
|
||||
pub fn from_file(&self, url: &UrlBuf) -> Vec<UrlBuf> {
|
||||
if url.scheme.is_virtual() {
|
||||
vec![]
|
||||
} else if let Some((parent, urn)) = url.pair() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use ratatui::layout::Rect;
|
||||
use yazi_adapter::Dimension;
|
||||
use yazi_config::popup::{Origin, Position};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::{Mimetype, Tabs, Watcher, Yanked};
|
||||
use crate::tab::{Folder, Tab};
|
||||
|
|
@ -38,7 +38,7 @@ impl Mgr {
|
|||
|
||||
impl Mgr {
|
||||
#[inline]
|
||||
pub fn cwd(&self) -> &Url { self.active().cwd() }
|
||||
pub fn cwd(&self) -> &UrlBuf { self.active().cwd() }
|
||||
|
||||
#[inline]
|
||||
pub fn active(&self) -> &Tab { self.tabs.active() }
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
use std::{borrow::Cow, collections::HashMap};
|
||||
|
||||
use yazi_fs::File;
|
||||
use yazi_shared::{MIME_DIR, SStr, url::{CovUrl, Url}};
|
||||
use yazi_shared::{MIME_DIR, SStr, url::{UrlBuf, UrlCov}};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Mimetype(HashMap<CovUrl, String>);
|
||||
pub struct Mimetype(HashMap<UrlCov, String>);
|
||||
|
||||
impl Mimetype {
|
||||
#[inline]
|
||||
pub fn by_url(&self, url: &Url) -> Option<&str> {
|
||||
self.0.get(CovUrl::new(url)).map(|s| s.as_str())
|
||||
pub fn by_url(&self, url: &UrlBuf) -> Option<&str> {
|
||||
self.0.get(UrlCov::new(url)).map(|s| s.as_str())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn by_url_owned(&self, url: &Url) -> Option<SStr> {
|
||||
pub fn by_url_owned(&self, url: &UrlBuf) -> Option<SStr> {
|
||||
self.by_url(url).map(|s| Cow::Owned(s.to_owned()))
|
||||
}
|
||||
|
||||
|
|
@ -28,10 +28,10 @@ impl Mimetype {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn contains(&self, url: &Url) -> bool { self.0.contains_key(CovUrl::new(url)) }
|
||||
pub fn contains(&self, url: &UrlBuf) -> bool { self.0.contains_key(UrlCov::new(url)) }
|
||||
|
||||
#[inline]
|
||||
pub fn extend(&mut self, iter: impl IntoIterator<Item = (Url, String)>) {
|
||||
self.0.extend(iter.into_iter().map(|(u, m)| (CovUrl(u), m)));
|
||||
pub fn extend(&mut self, iter: impl IntoIterator<Item = (UrlBuf, String)>) {
|
||||
self.0.extend(iter.into_iter().map(|(u, m)| (UrlCov(u), m)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,17 +8,17 @@ use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream};
|
|||
use tracing::error;
|
||||
use yazi_fs::{File, Files, FilesOp, cha::Cha, provider, realname_unchecked};
|
||||
use yazi_proxy::WATCHER;
|
||||
use yazi_shared::{RoCell, url::Url};
|
||||
use yazi_shared::{RoCell, url::UrlBuf};
|
||||
|
||||
use super::Linked;
|
||||
use crate::tab::Folder;
|
||||
|
||||
pub(crate) static WATCHED: RoCell<RwLock<HashSet<Url>>> = RoCell::new();
|
||||
pub(crate) static WATCHED: RoCell<RwLock<HashSet<UrlBuf>>> = RoCell::new();
|
||||
pub static LINKED: RoCell<RwLock<Linked>> = RoCell::new();
|
||||
|
||||
pub struct Watcher {
|
||||
in_tx: watch::Sender<HashSet<Url>>,
|
||||
out_tx: mpsc::UnboundedSender<Url>,
|
||||
in_tx: watch::Sender<HashSet<UrlBuf>>,
|
||||
out_tx: mpsc::UnboundedSender<UrlBuf>,
|
||||
}
|
||||
|
||||
// FIXME: VFS
|
||||
|
|
@ -33,7 +33,7 @@ impl Watcher {
|
|||
if event.kind.is_access() {
|
||||
return;
|
||||
}
|
||||
Self::push_files_impl(&out_tx_, event.paths.into_iter().map(Url::from));
|
||||
Self::push_files_impl(&out_tx_, event.paths.into_iter().map(UrlBuf::from));
|
||||
};
|
||||
|
||||
let config = notify::Config::default().with_poll_interval(Duration::from_millis(500));
|
||||
|
|
@ -52,15 +52,15 @@ impl Watcher {
|
|||
Self { in_tx, out_tx }
|
||||
}
|
||||
|
||||
pub fn watch<'a>(&mut self, it: impl Iterator<Item = &'a Url>) {
|
||||
pub fn watch<'a>(&mut self, it: impl Iterator<Item = &'a UrlBuf>) {
|
||||
self.in_tx.send(it.filter(|u| u.is_regular()).cloned().collect()).ok();
|
||||
}
|
||||
|
||||
pub fn push_files(&self, urls: Vec<Url>) {
|
||||
pub fn push_files(&self, urls: Vec<UrlBuf>) {
|
||||
Self::push_files_impl(&self.out_tx, urls.into_iter());
|
||||
}
|
||||
|
||||
fn push_files_impl(out_tx: &mpsc::UnboundedSender<Url>, urls: impl Iterator<Item = Url>) {
|
||||
fn push_files_impl(out_tx: &mpsc::UnboundedSender<UrlBuf>, urls: impl Iterator<Item = UrlBuf>) {
|
||||
let (mut parents, watched) = (HashSet::new(), WATCHED.read());
|
||||
for u in urls {
|
||||
let Some(p) = u.parent_url() else { continue };
|
||||
|
|
@ -77,7 +77,7 @@ impl Watcher {
|
|||
|
||||
// TODO: performance improvement
|
||||
pub fn trigger_dirs(&self, folders: &[&Folder]) {
|
||||
async fn go(cwd: Url, cha: Cha) {
|
||||
async fn go(cwd: UrlBuf, cha: Cha) {
|
||||
let Some(cha) = Files::assert_stale(&cwd, cha).await else { return };
|
||||
|
||||
match Files::from_dir_bulk(&cwd).await {
|
||||
|
|
@ -98,7 +98,7 @@ impl Watcher {
|
|||
}
|
||||
|
||||
async fn fan_in(
|
||||
mut rx: watch::Receiver<HashSet<Url>>,
|
||||
mut rx: watch::Receiver<HashSet<UrlBuf>>,
|
||||
mut watcher: impl notify::Watcher + Send + 'static,
|
||||
) {
|
||||
loop {
|
||||
|
|
@ -119,7 +119,7 @@ impl Watcher {
|
|||
}
|
||||
}
|
||||
|
||||
async fn fan_out(rx: UnboundedReceiver<Url>) {
|
||||
async fn fan_out(rx: UnboundedReceiver<UrlBuf>) {
|
||||
// TODO: revert this once a new notification is implemented
|
||||
let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(250));
|
||||
pin!(rx);
|
||||
|
|
@ -154,7 +154,11 @@ impl Watcher {
|
|||
}
|
||||
}
|
||||
|
||||
async fn sync_watched<W>(mut watcher: W, to_unwatch: HashSet<Url>, to_watch: HashSet<Url>) -> W
|
||||
async fn sync_watched<W>(
|
||||
mut watcher: W,
|
||||
to_unwatch: HashSet<UrlBuf>,
|
||||
to_watch: HashSet<UrlBuf>,
|
||||
) -> W
|
||||
where
|
||||
W: notify::Watcher + Send + 'static,
|
||||
{
|
||||
|
|
@ -192,7 +196,7 @@ impl Watcher {
|
|||
linked.keys().cloned().collect()
|
||||
};
|
||||
|
||||
async fn go(todo: HashSet<Url>) {
|
||||
async fn go(todo: HashSet<UrlBuf>) {
|
||||
for from in todo {
|
||||
let Ok(to) = provider::canonicalize(&from).await else { continue };
|
||||
|
||||
|
|
|
|||
|
|
@ -3,28 +3,28 @@ use std::{collections::HashSet, ops::Deref};
|
|||
use yazi_dds::Pubsub;
|
||||
use yazi_fs::FilesOp;
|
||||
use yazi_macro::err;
|
||||
use yazi_shared::url::{CovUrl, Url};
|
||||
use yazi_shared::url::{UrlBuf, UrlCov};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Yanked {
|
||||
pub cut: bool,
|
||||
urls: HashSet<CovUrl>,
|
||||
urls: HashSet<UrlCov>,
|
||||
|
||||
version: u64,
|
||||
revision: u64,
|
||||
}
|
||||
|
||||
impl Deref for Yanked {
|
||||
type Target = HashSet<CovUrl>;
|
||||
type Target = HashSet<UrlCov>;
|
||||
|
||||
fn deref(&self) -> &Self::Target { &self.urls }
|
||||
}
|
||||
|
||||
impl Yanked {
|
||||
pub fn new(cut: bool, urls: HashSet<CovUrl>) -> Self { Self { cut, urls, ..Default::default() } }
|
||||
pub fn new(cut: bool, urls: HashSet<UrlCov>) -> Self { Self { cut, urls, ..Default::default() } }
|
||||
|
||||
pub fn remove(&mut self, url: &Url) {
|
||||
if self.urls.remove(CovUrl::new(url)) {
|
||||
pub fn remove(&mut self, url: &UrlBuf) {
|
||||
if self.urls.remove(UrlCov::new(url)) {
|
||||
self.revision += 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -39,9 +39,9 @@ impl Yanked {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn contains(&self, url: impl AsRef<Url>) -> bool { self.urls.contains(CovUrl::new(&url)) }
|
||||
pub fn contains(&self, url: impl AsRef<UrlBuf>) -> bool { self.urls.contains(UrlCov::new(&url)) }
|
||||
|
||||
pub fn contains_in(&self, dir: &Url) -> bool {
|
||||
pub fn contains_in(&self, dir: &UrlBuf) -> bool {
|
||||
self.urls.iter().any(|u| {
|
||||
let mut it = u.components();
|
||||
it.next_back().is_some()
|
||||
|
|
@ -60,7 +60,7 @@ impl Yanked {
|
|||
|
||||
if !addition.is_empty() {
|
||||
let old = self.urls.len();
|
||||
self.urls.extend(addition.into_iter().map(CovUrl));
|
||||
self.urls.extend(addition.into_iter().map(UrlCov));
|
||||
self.revision += (old != self.urls.len()) as u64;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use yazi_fs::File;
|
|||
use yazi_macro::render;
|
||||
use yazi_parser::mgr::SpotLock;
|
||||
use yazi_plugin::isolate;
|
||||
use yazi_shared::{SStr, url::Url};
|
||||
use yazi_shared::{SStr, url::UrlBuf};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Spot {
|
||||
|
|
@ -43,7 +43,7 @@ impl Spot {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn same_url(&self, url: &Url) -> bool { self.lock.as_ref().is_some_and(|l| *url == l.url) }
|
||||
pub fn same_url(&self, url: &UrlBuf) -> bool { self.lock.as_ref().is_some_and(|l| *url == l.url) }
|
||||
|
||||
#[inline]
|
||||
pub fn same_file(&self, file: &File, mime: &str) -> bool {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||
|
||||
use anyhow::Result;
|
||||
use yazi_fs::{Files, Filter, FilterCase};
|
||||
use yazi_shared::url::{Url, Urn, UrnBuf};
|
||||
use yazi_shared::url::{UrlBuf, Urn, UrnBuf};
|
||||
|
||||
use crate::tab::Folder;
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ pub struct Finder {
|
|||
|
||||
#[derive(Default)]
|
||||
struct FinderLock {
|
||||
cwd: Url,
|
||||
cwd: UrlBuf,
|
||||
revision: u64,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ use yazi_fs::{File, Files, FilesOp, FolderStage, cha::Cha};
|
|||
use yazi_macro::err;
|
||||
use yazi_parser::Step;
|
||||
use yazi_proxy::MgrProxy;
|
||||
use yazi_shared::{Id, url::{Url, Urn, UrnBuf}};
|
||||
use yazi_shared::{Id, url::{UrlBuf, Urn, UrnBuf}};
|
||||
use yazi_widgets::Scrollable;
|
||||
|
||||
pub struct Folder {
|
||||
pub url: Url,
|
||||
pub url: UrlBuf,
|
||||
pub cha: Cha,
|
||||
pub files: Files,
|
||||
pub stage: FolderStage,
|
||||
|
|
@ -37,8 +37,8 @@ impl Default for Folder {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&Url> for Folder {
|
||||
fn from(url: &Url) -> Self { Self { url: url.clone(), ..Default::default() } }
|
||||
impl From<&UrlBuf> for Folder {
|
||||
fn from(url: &UrlBuf) -> Self { Self { url: url.clone(), ..Default::default() } }
|
||||
}
|
||||
|
||||
impl Folder {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use std::{collections::HashMap, ops::{Deref, DerefMut}};
|
||||
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::Folder;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct History(HashMap<Url, Folder>);
|
||||
pub struct History(HashMap<UrlBuf, Folder>);
|
||||
|
||||
impl Deref for History {
|
||||
type Target = HashMap<Url, Folder>;
|
||||
type Target = HashMap<UrlBuf, Folder>;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
|
|
@ -21,7 +21,7 @@ impl DerefMut for History {
|
|||
|
||||
impl History {
|
||||
#[inline]
|
||||
pub fn remove_or(&mut self, url: &Url) -> Folder {
|
||||
pub fn remove_or(&mut self, url: &UrlBuf) -> Folder {
|
||||
self.0.remove(url).unwrap_or_else(|| Folder::from(url))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use yazi_fs::{File, Files, FilesOp, cha::Cha};
|
|||
use yazi_macro::render;
|
||||
use yazi_parser::mgr::PreviewLock;
|
||||
use yazi_plugin::{external::Highlighter, isolate};
|
||||
use yazi_shared::{MIME_DIR, SStr, url::Url};
|
||||
use yazi_shared::{MIME_DIR, SStr, url::UrlBuf};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Preview {
|
||||
|
|
@ -88,7 +88,7 @@ impl Preview {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn same_url(&self, url: &Url) -> bool { matches!(&self.lock, Some(l) if l.url == *url) }
|
||||
pub fn same_url(&self, url: &UrlBuf) -> bool { matches!(&self.lock, Some(l) if l.url == *url) }
|
||||
|
||||
#[inline]
|
||||
pub fn same_file(&self, file: &File, mime: &str) -> bool {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ use std::{collections::HashMap, ops::Deref};
|
|||
|
||||
use indexmap::IndexMap;
|
||||
use yazi_fs::FilesOp;
|
||||
use yazi_shared::{timestamp_us, url::{CovUrl, Url}};
|
||||
use yazi_shared::{timestamp_us, url::{UrlBuf, UrlCov}};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Selected {
|
||||
inner: IndexMap<CovUrl, u64>,
|
||||
parents: HashMap<CovUrl, usize>,
|
||||
inner: IndexMap<UrlCov, u64>,
|
||||
parents: HashMap<UrlCov, usize>,
|
||||
}
|
||||
|
||||
impl Selected {
|
||||
|
|
@ -18,17 +18,17 @@ impl Selected {
|
|||
pub fn is_empty(&self) -> bool { self.inner.is_empty() }
|
||||
|
||||
#[inline]
|
||||
pub fn values(&self) -> impl Iterator<Item = &Url> { self.inner.keys().map(Deref::deref) }
|
||||
pub fn values(&self) -> impl Iterator<Item = &UrlBuf> { self.inner.keys().map(Deref::deref) }
|
||||
|
||||
#[inline]
|
||||
pub fn contains(&self, url: impl AsRef<Url>) -> bool {
|
||||
self.inner.contains_key(CovUrl::new(&url))
|
||||
pub fn contains(&self, url: impl AsRef<UrlBuf>) -> bool {
|
||||
self.inner.contains_key(UrlCov::new(&url))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn add(&mut self, url: &Url) -> bool { self.add_same(&[url]) == 1 }
|
||||
pub fn add(&mut self, url: &UrlBuf) -> bool { self.add_same(&[url]) == 1 }
|
||||
|
||||
pub fn add_many(&mut self, urls: &[impl AsRef<Url>]) -> usize {
|
||||
pub fn add_many(&mut self, urls: &[impl AsRef<UrlBuf>]) -> usize {
|
||||
let mut grouped: HashMap<_, Vec<_>> = Default::default();
|
||||
for u in urls {
|
||||
if let Some(p) = u.as_ref().parent_url() {
|
||||
|
|
@ -38,10 +38,10 @@ impl Selected {
|
|||
grouped.into_values().map(|v| self.add_same(&v)).sum()
|
||||
}
|
||||
|
||||
fn add_same(&mut self, urls: &[impl AsRef<Url>]) -> usize {
|
||||
fn add_same(&mut self, urls: &[impl AsRef<UrlBuf>]) -> usize {
|
||||
// If it has appeared as a parent
|
||||
let urls: Vec<_> =
|
||||
urls.iter().map(CovUrl::new).filter(|&u| !self.parents.contains_key(u)).collect();
|
||||
urls.iter().map(UrlCov::new).filter(|&u| !self.parents.contains_key(u)).collect();
|
||||
if urls.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -68,9 +68,9 @@ impl Selected {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn remove(&mut self, url: &Url) -> bool { self.remove_same(&[url]) == 1 }
|
||||
pub fn remove(&mut self, url: &UrlBuf) -> bool { self.remove_same(&[url]) == 1 }
|
||||
|
||||
pub fn remove_many(&mut self, urls: &[impl AsRef<Url>]) -> usize {
|
||||
pub fn remove_many(&mut self, urls: &[impl AsRef<UrlBuf>]) -> usize {
|
||||
let mut grouped: HashMap<_, Vec<_>> = Default::default();
|
||||
for u in urls {
|
||||
if let Some(p) = u.as_ref().parent_url() {
|
||||
|
|
@ -86,13 +86,13 @@ impl Selected {
|
|||
affected
|
||||
}
|
||||
|
||||
fn remove_same(&mut self, urls: &[impl AsRef<Url>]) -> usize {
|
||||
let count = urls.iter().filter_map(|u| self.inner.swap_remove(CovUrl::new(u))).count();
|
||||
fn remove_same(&mut self, urls: &[impl AsRef<UrlBuf>]) -> usize {
|
||||
let count = urls.iter().filter_map(|u| self.inner.swap_remove(UrlCov::new(u))).count();
|
||||
if count == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut parent = CovUrl::new(&urls[0]).parent_url();
|
||||
let mut parent = UrlCov::new(&urls[0]).parent_url();
|
||||
while let Some(u) = parent {
|
||||
let n = self.parents.get_mut(&u).unwrap();
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ impl Selected {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn url(s: &str) -> Url { s.parse().unwrap() }
|
||||
fn url(s: &str) -> UrlBuf { s.parse().unwrap() }
|
||||
|
||||
#[test]
|
||||
fn test_insert_non_conflicting() {
|
||||
|
|
@ -196,7 +196,7 @@ mod tests {
|
|||
fn insert_many_empty_urls_list() {
|
||||
let mut s = Selected::default();
|
||||
|
||||
assert_eq!(0, s.add_same(&[] as &[&Url]));
|
||||
assert_eq!(0, s.add_same(&[] as &[&UrlBuf]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use tokio::task::JoinHandle;
|
|||
use yazi_adapter::Dimension;
|
||||
use yazi_config::{LAYOUT, popup::{Origin, Position}};
|
||||
use yazi_fs::File;
|
||||
use yazi_shared::{Id, Ids, url::Url};
|
||||
use yazi_shared::{Id, Ids, url::UrlBuf};
|
||||
|
||||
use super::{Backstack, Finder, Folder, History, Mode, Preference, Preview};
|
||||
use crate::{spot::Spot, tab::Selected};
|
||||
|
|
@ -18,7 +18,7 @@ pub struct Tab {
|
|||
pub current: Folder,
|
||||
pub parent: Option<Folder>,
|
||||
|
||||
pub backstack: Backstack<Url>,
|
||||
pub backstack: Backstack<UrlBuf>,
|
||||
pub history: History,
|
||||
pub selected: Selected,
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ impl Tab {
|
|||
impl Tab {
|
||||
// --- Current
|
||||
#[inline]
|
||||
pub fn cwd(&self) -> &Url { &self.current.url }
|
||||
pub fn cwd(&self) -> &UrlBuf { &self.current.url }
|
||||
|
||||
#[inline]
|
||||
pub fn hovered(&self) -> Option<&File> { self.current.hovered() }
|
||||
|
|
@ -87,7 +87,7 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn selected_or_hovered(&self) -> Box<dyn Iterator<Item = &Url> + '_> {
|
||||
pub fn selected_or_hovered(&self) -> Box<dyn Iterator<Item = &UrlBuf> + '_> {
|
||||
if self.selected.is_empty() {
|
||||
Box::new(self.hovered().map(|h| &h.url).into_iter())
|
||||
} else {
|
||||
|
|
@ -95,7 +95,7 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn hovered_and_selected(&self) -> Box<dyn Iterator<Item = &Url> + '_> {
|
||||
pub fn hovered_and_selected(&self) -> Box<dyn Iterator<Item = &UrlBuf> + '_> {
|
||||
let Some(h) = self.hovered() else { return Box::new(iter::empty()) };
|
||||
if self.selected.is_empty() {
|
||||
Box::new([&h.url, &h.url].into_iter())
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use tracing::debug;
|
||||
use yazi_shared::url::{CovUrl, Url};
|
||||
use yazi_shared::url::{UrlBuf, UrlCov};
|
||||
|
||||
use super::Tasks;
|
||||
|
||||
impl Tasks {
|
||||
pub fn file_cut(&self, src: &[&CovUrl], dest: &Url, force: bool) {
|
||||
pub fn file_cut(&self, src: &[&UrlCov], dest: &UrlBuf, force: bool) {
|
||||
for &u in src {
|
||||
let to = dest.join(u.file_name().unwrap());
|
||||
if force && *u == to {
|
||||
|
|
@ -17,7 +17,7 @@ impl Tasks {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn file_copy(&self, src: &[&CovUrl], dest: &Url, force: bool, follow: bool) {
|
||||
pub fn file_copy(&self, src: &[&UrlCov], dest: &UrlBuf, force: bool, follow: bool) {
|
||||
for &u in src {
|
||||
let to = dest.join(u.file_name().unwrap());
|
||||
if force && *u == to {
|
||||
|
|
@ -28,7 +28,7 @@ impl Tasks {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn file_link(&self, src: &HashSet<CovUrl>, dest: &Url, relative: bool, force: bool) {
|
||||
pub fn file_link(&self, src: &HashSet<UrlCov>, dest: &UrlBuf, relative: bool, force: bool) {
|
||||
for u in src {
|
||||
let to = dest.join(u.file_name().unwrap());
|
||||
if force && *u == to {
|
||||
|
|
@ -39,7 +39,7 @@ impl Tasks {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn file_hardlink(&self, src: &HashSet<CovUrl>, dest: &Url, force: bool, follow: bool) {
|
||||
pub fn file_hardlink(&self, src: &HashSet<UrlCov>, dest: &UrlBuf, force: bool, follow: bool) {
|
||||
for u in src {
|
||||
let to = dest.join(u.file_name().unwrap());
|
||||
if force && *u == to {
|
||||
|
|
@ -50,7 +50,7 @@ impl Tasks {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn file_remove(&self, targets: Vec<Url>, permanently: bool) {
|
||||
pub fn file_remove(&self, targets: Vec<UrlBuf>, permanently: bool) {
|
||||
for u in targets {
|
||||
if permanently {
|
||||
self.scheduler.file_delete(u);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ use std::{borrow::Cow, collections::HashMap, ffi::OsString, mem};
|
|||
|
||||
use yazi_config::{YAZI, opener::OpenerRule};
|
||||
use yazi_parser::tasks::ProcessExecOpt;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::Tasks;
|
||||
|
||||
impl Tasks {
|
||||
pub fn process_from_files(&self, cwd: Url, hovered: Url, targets: Vec<(Url, &str)>) {
|
||||
pub fn process_from_files(&self, cwd: UrlBuf, hovered: UrlBuf, targets: Vec<(UrlBuf, &str)>) {
|
||||
let mut openers = HashMap::new();
|
||||
for (url, mime) in targets {
|
||||
if let Some(opener) = YAZI.opener.first(YAZI.open.all(&url, mime)) {
|
||||
|
|
@ -25,7 +25,7 @@ impl Tasks {
|
|||
|
||||
pub fn process_from_opener(
|
||||
&self,
|
||||
cwd: Url,
|
||||
cwd: UrlBuf,
|
||||
opener: Cow<'static, OpenerRule>,
|
||||
mut args: Vec<OsString>,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@ use std::{borrow::Cow, collections::HashMap};
|
|||
|
||||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::Ember;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EmberBulk<'a> {
|
||||
pub changes: HashMap<Cow<'a, Url>, Cow<'a, Url>>,
|
||||
pub changes: HashMap<Cow<'a, UrlBuf>, Cow<'a, UrlBuf>>,
|
||||
}
|
||||
|
||||
impl<'a> EmberBulk<'a> {
|
||||
pub fn borrowed<I>(changes: I) -> Ember<'a>
|
||||
where
|
||||
I: Iterator<Item = (&'a Url, &'a Url)>,
|
||||
I: Iterator<Item = (&'a UrlBuf, &'a UrlBuf)>,
|
||||
{
|
||||
Self { changes: changes.map(|(from, to)| (from.into(), to.into())).collect() }.into()
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ impl<'a> EmberBulk<'a> {
|
|||
impl EmberBulk<'static> {
|
||||
pub fn owned<'a, I>(changes: I) -> Ember<'static>
|
||||
where
|
||||
I: Iterator<Item = (&'a Url, &'a Url)>,
|
||||
I: Iterator<Item = (&'a UrlBuf, &'a UrlBuf)>,
|
||||
{
|
||||
Self { changes: changes.map(|(from, to)| (from.clone().into(), to.clone().into())).collect() }
|
||||
.into()
|
||||
|
|
|
|||
|
|
@ -2,26 +2,26 @@ use std::borrow::Cow;
|
|||
|
||||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
|
||||
use super::Ember;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EmberCd<'a> {
|
||||
pub tab: Id,
|
||||
pub url: Cow<'a, Url>,
|
||||
pub url: Cow<'a, UrlBuf>,
|
||||
#[serde(skip)]
|
||||
dummy: bool,
|
||||
}
|
||||
|
||||
impl<'a> EmberCd<'a> {
|
||||
pub fn borrowed(tab: Id, url: &'a Url) -> Ember<'a> {
|
||||
pub fn borrowed(tab: Id, url: &'a UrlBuf) -> Ember<'a> {
|
||||
Self { tab, url: url.into(), dummy: false }.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmberCd<'static> {
|
||||
pub fn owned(tab: Id, _: &Url) -> Ember<'static> {
|
||||
pub fn owned(tab: Id, _: &UrlBuf) -> Ember<'static> {
|
||||
Self { tab, url: Default::default(), dummy: true }.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@ use std::borrow::Cow;
|
|||
|
||||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::Ember;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EmberDelete<'a> {
|
||||
pub urls: Cow<'a, Vec<Url>>,
|
||||
pub urls: Cow<'a, Vec<UrlBuf>>,
|
||||
}
|
||||
|
||||
impl<'a> EmberDelete<'a> {
|
||||
pub fn borrowed(urls: &'a Vec<Url>) -> Ember<'a> { Self { urls: Cow::Borrowed(urls) }.into() }
|
||||
pub fn borrowed(urls: &'a Vec<UrlBuf>) -> Ember<'a> { Self { urls: Cow::Borrowed(urls) }.into() }
|
||||
}
|
||||
|
||||
impl EmberDelete<'static> {
|
||||
pub fn owned(urls: Vec<Url>) -> Ember<'static> { Self { urls: Cow::Owned(urls) }.into() }
|
||||
pub fn owned(urls: Vec<UrlBuf>) -> Ember<'static> { Self { urls: Cow::Owned(urls) }.into() }
|
||||
}
|
||||
|
||||
impl<'a> From<EmberDelete<'a>> for Ember<'a> {
|
||||
|
|
|
|||
|
|
@ -2,24 +2,24 @@ use std::borrow::Cow;
|
|||
|
||||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
|
||||
use super::Ember;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EmberHover<'a> {
|
||||
pub tab: Id,
|
||||
pub url: Option<Cow<'a, Url>>,
|
||||
pub url: Option<Cow<'a, UrlBuf>>,
|
||||
}
|
||||
|
||||
impl<'a> EmberHover<'a> {
|
||||
pub fn borrowed(tab: Id, url: Option<&'a Url>) -> Ember<'a> {
|
||||
pub fn borrowed(tab: Id, url: Option<&'a UrlBuf>) -> Ember<'a> {
|
||||
Self { tab, url: url.map(Into::into) }.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmberHover<'static> {
|
||||
pub fn owned(tab: Id, _: Option<&Url>) -> Ember<'static> { Self { tab, url: None }.into() }
|
||||
pub fn owned(tab: Id, _: Option<&UrlBuf>) -> Ember<'static> { Self { tab, url: None }.into() }
|
||||
}
|
||||
|
||||
impl<'a> From<EmberHover<'a>> for Ember<'a> {
|
||||
|
|
|
|||
|
|
@ -3,25 +3,25 @@ use std::borrow::Cow;
|
|||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_fs::FolderStage;
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
|
||||
use super::Ember;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EmberLoad<'a> {
|
||||
pub tab: Id,
|
||||
pub url: Cow<'a, Url>,
|
||||
pub url: Cow<'a, UrlBuf>,
|
||||
pub stage: FolderStage,
|
||||
}
|
||||
|
||||
impl<'a> EmberLoad<'a> {
|
||||
pub fn borrowed(tab: Id, url: &'a Url, stage: FolderStage) -> Ember<'a> {
|
||||
pub fn borrowed(tab: Id, url: &'a UrlBuf, stage: FolderStage) -> Ember<'a> {
|
||||
Self { tab, url: url.into(), stage }.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmberLoad<'static> {
|
||||
pub fn owned(tab: Id, url: &Url, stage: FolderStage) -> Ember<'static> {
|
||||
pub fn owned(tab: Id, url: &UrlBuf, stage: FolderStage) -> Ember<'static> {
|
||||
Self { tab, url: url.clone().into(), stage }.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::borrow::Cow;
|
|||
|
||||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::Ember;
|
||||
|
||||
|
|
@ -36,8 +36,8 @@ impl IntoLua for EmberMove<'_> {
|
|||
// --- Item
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct BodyMoveItem {
|
||||
pub from: Url,
|
||||
pub to: Url,
|
||||
pub from: UrlBuf,
|
||||
pub to: UrlBuf,
|
||||
}
|
||||
|
||||
impl IntoLua for BodyMoveItem {
|
||||
|
|
|
|||
|
|
@ -2,25 +2,25 @@ use std::borrow::Cow;
|
|||
|
||||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
|
||||
use super::Ember;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EmberRename<'a> {
|
||||
pub tab: Id,
|
||||
pub from: Cow<'a, Url>,
|
||||
pub to: Cow<'a, Url>,
|
||||
pub from: Cow<'a, UrlBuf>,
|
||||
pub to: Cow<'a, UrlBuf>,
|
||||
}
|
||||
|
||||
impl<'a> EmberRename<'a> {
|
||||
pub fn borrowed(tab: Id, from: &'a Url, to: &'a Url) -> Ember<'a> {
|
||||
pub fn borrowed(tab: Id, from: &'a UrlBuf, to: &'a UrlBuf) -> Ember<'a> {
|
||||
Self { tab, from: from.into(), to: to.into() }.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmberRename<'static> {
|
||||
pub fn owned(tab: Id, from: &Url, to: &Url) -> Ember<'static> {
|
||||
pub fn owned(tab: Id, from: &UrlBuf, to: &UrlBuf) -> Ember<'static> {
|
||||
Self { tab, from: from.clone().into(), to: to.clone().into() }.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@ use std::borrow::Cow;
|
|||
|
||||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::Ember;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EmberTrash<'a> {
|
||||
pub urls: Cow<'a, Vec<Url>>,
|
||||
pub urls: Cow<'a, Vec<UrlBuf>>,
|
||||
}
|
||||
|
||||
impl<'a> EmberTrash<'a> {
|
||||
pub fn borrowed(urls: &'a Vec<Url>) -> Ember<'a> { Self { urls: Cow::Borrowed(urls) }.into() }
|
||||
pub fn borrowed(urls: &'a Vec<UrlBuf>) -> Ember<'a> { Self { urls: Cow::Borrowed(urls) }.into() }
|
||||
}
|
||||
|
||||
impl EmberTrash<'static> {
|
||||
pub fn owned(urls: Vec<Url>) -> Ember<'static> { Self { urls: Cow::Owned(urls) }.into() }
|
||||
pub fn owned(urls: Vec<UrlBuf>) -> Ember<'static> { Self { urls: Cow::Owned(urls) }.into() }
|
||||
}
|
||||
|
||||
impl<'a> From<EmberTrash<'a>> for Ember<'a> {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{borrow::Cow, collections::HashSet};
|
|||
use mlua::{IntoLua, Lua, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_parser::mgr::UpdateYankedOpt;
|
||||
use yazi_shared::url::CovUrl;
|
||||
use yazi_shared::url::UrlCov;
|
||||
|
||||
use super::Ember;
|
||||
|
||||
|
|
@ -11,13 +11,13 @@ use super::Ember;
|
|||
pub struct EmberYank<'a>(UpdateYankedOpt<'a>);
|
||||
|
||||
impl<'a> EmberYank<'a> {
|
||||
pub fn borrowed(cut: bool, urls: &'a HashSet<CovUrl>) -> Ember<'a> {
|
||||
pub fn borrowed(cut: bool, urls: &'a HashSet<UrlCov>) -> Ember<'a> {
|
||||
Self(UpdateYankedOpt { cut, urls: Cow::Borrowed(urls) }).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmberYank<'static> {
|
||||
pub fn owned(cut: bool, _: &HashSet<CovUrl>) -> Ember<'static> {
|
||||
pub fn owned(cut: bool, _: &HashSet<UrlCov>) -> Ember<'static> {
|
||||
Self(UpdateYankedOpt { cut, urls: Default::default() }).into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use mlua::Function;
|
|||
use parking_lot::RwLock;
|
||||
use yazi_boot::BOOT;
|
||||
use yazi_fs::FolderStage;
|
||||
use yazi_shared::{Id, RoCell, url::{CovUrl, Url}};
|
||||
use yazi_shared::{Id, RoCell, url::{UrlBuf, UrlCov}};
|
||||
|
||||
use crate::{Client, ID, PEERS, ember::{BodyMoveItem, Ember, EmberBulk, EmberHi}};
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ impl Pubsub {
|
|||
|
||||
pub fn pub_after_bulk<'a, I>(changes: I) -> Result<()>
|
||||
where
|
||||
I: Iterator<Item = (&'a Url, &'a Url)> + Clone,
|
||||
I: Iterator<Item = (&'a UrlBuf, &'a UrlBuf)> + Clone,
|
||||
{
|
||||
if BOOT.local_events.contains("bulk") {
|
||||
EmberBulk::borrowed(changes.clone()).with_receiver(*ID).flush()?;
|
||||
|
|
@ -149,21 +149,21 @@ impl Pubsub {
|
|||
impl Pubsub {
|
||||
pub_after!(tab(idx: Id), (idx));
|
||||
|
||||
pub_after!(cd(tab: Id, url: &Url), (tab, url));
|
||||
pub_after!(cd(tab: Id, url: &UrlBuf), (tab, url));
|
||||
|
||||
pub_after!(load(tab: Id, url: &Url, stage: FolderStage), (tab, url, stage));
|
||||
pub_after!(load(tab: Id, url: &UrlBuf, stage: FolderStage), (tab, url, stage));
|
||||
|
||||
pub_after!(hover(tab: Id, url: Option<&Url>), (tab, url));
|
||||
pub_after!(hover(tab: Id, url: Option<&UrlBuf>), (tab, url));
|
||||
|
||||
pub_after!(rename(tab: Id, from: &Url, to: &Url), (tab, from, to));
|
||||
pub_after!(rename(tab: Id, from: &UrlBuf, to: &UrlBuf), (tab, from, to));
|
||||
|
||||
pub_after!(@yank(cut: bool, urls: &HashSet<CovUrl>), (cut, urls));
|
||||
pub_after!(@yank(cut: bool, urls: &HashSet<UrlCov>), (cut, urls));
|
||||
|
||||
pub_after!(move(items: Vec<BodyMoveItem>), (&items), (items));
|
||||
|
||||
pub_after!(trash(urls: Vec<Url>), (&urls), (urls));
|
||||
pub_after!(trash(urls: Vec<UrlBuf>), (&urls), (urls));
|
||||
|
||||
pub_after!(delete(urls: Vec<Url>), (&urls), (urls));
|
||||
pub_after!(delete(urls: Vec<UrlBuf>), (&urls), (urls));
|
||||
|
||||
pub_after!(mount(), ());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,34 +5,34 @@ use tokio::{pin, select, sync::mpsc};
|
|||
use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use yazi_macro::err;
|
||||
use yazi_shared::{RoCell, url::Url};
|
||||
use yazi_shared::{RoCell, url::UrlBuf};
|
||||
|
||||
use crate::{Pubsub, ember::BodyMoveItem};
|
||||
|
||||
static CT: RoCell<CancellationToken> = RoCell::new();
|
||||
static MOVE_TX: Mutex<Option<mpsc::UnboundedSender<BodyMoveItem>>> = Mutex::new(None);
|
||||
static TRASH_TX: Mutex<Option<mpsc::UnboundedSender<Url>>> = Mutex::new(None);
|
||||
static DELETE_TX: Mutex<Option<mpsc::UnboundedSender<Url>>> = Mutex::new(None);
|
||||
static TRASH_TX: Mutex<Option<mpsc::UnboundedSender<UrlBuf>>> = Mutex::new(None);
|
||||
static DELETE_TX: Mutex<Option<mpsc::UnboundedSender<UrlBuf>>> = Mutex::new(None);
|
||||
|
||||
pub struct Pump;
|
||||
|
||||
impl Pump {
|
||||
#[inline]
|
||||
pub fn push_move(from: Url, to: Url) {
|
||||
pub fn push_move(from: UrlBuf, to: UrlBuf) {
|
||||
if let Some(tx) = &*MOVE_TX.lock() {
|
||||
tx.send(BodyMoveItem { from, to }).ok();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn push_trash(target: Url) {
|
||||
pub fn push_trash(target: UrlBuf) {
|
||||
if let Some(tx) = &*TRASH_TX.lock() {
|
||||
tx.send(target).ok();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn push_delete(target: Url) {
|
||||
pub fn push_delete(target: UrlBuf) {
|
||||
if let Some(tx) = &*DELETE_TX.lock() {
|
||||
tx.send(target).ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::{collections::VecDeque, future::poll_fn, io, mem, pin::Pin, task::{Poll, ready}, time::{Duration, Instant}};
|
||||
|
||||
use tokio::task::JoinHandle;
|
||||
use yazi_shared::{Either, url::Url};
|
||||
use yazi_shared::{Either, url::UrlBuf};
|
||||
|
||||
use crate::provider::{self, ReadDirSync};
|
||||
|
||||
type Task = Either<Url, ReadDirSync>;
|
||||
type Task = Either<UrlBuf, ReadDirSync>;
|
||||
|
||||
pub enum SizeCalculator {
|
||||
Idle((VecDeque<Task>, Option<u64>)),
|
||||
|
|
@ -13,7 +13,7 @@ pub enum SizeCalculator {
|
|||
}
|
||||
|
||||
impl SizeCalculator {
|
||||
pub async fn new(url: &Url) -> io::Result<Self> {
|
||||
pub async fn new(url: &UrlBuf) -> io::Result<Self> {
|
||||
let u = url.to_owned();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let meta = provider::symlink_metadata_sync(&u)?;
|
||||
|
|
@ -28,7 +28,7 @@ impl SizeCalculator {
|
|||
.await?
|
||||
}
|
||||
|
||||
pub async fn total(url: &Url) -> io::Result<u64> {
|
||||
pub async fn total(url: &UrlBuf) -> io::Result<u64> {
|
||||
let mut it = Self::new(url).await?;
|
||||
let mut total = 0;
|
||||
while let Some(n) = it.next().await? {
|
||||
|
|
@ -63,7 +63,7 @@ impl SizeCalculator {
|
|||
.await
|
||||
}
|
||||
|
||||
fn next_chunk(buf: &mut VecDeque<Either<Url, ReadDirSync>>) -> Option<u64> {
|
||||
fn next_chunk(buf: &mut VecDeque<Either<UrlBuf, ReadDirSync>>) -> Option<u64> {
|
||||
let (mut i, mut size, now) = (0, 0, Instant::now());
|
||||
macro_rules! pop_and_continue {
|
||||
() => {{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::{fs::{FileType, Metadata}, time::SystemTime};
|
||||
|
||||
use yazi_macro::{unix_either, win_either};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use super::ChaKind;
|
||||
use crate::provider;
|
||||
|
|
@ -53,16 +53,16 @@ impl Default for Cha {
|
|||
|
||||
impl Cha {
|
||||
#[inline]
|
||||
pub fn new(url: &Url, meta: Metadata) -> Self {
|
||||
pub fn new(url: &UrlBuf, meta: Metadata) -> Self {
|
||||
Self::from_just_meta(&meta).attach(ChaKind::hidden(url, &meta))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn from_url(url: &Url) -> std::io::Result<Self> {
|
||||
pub async fn from_url(url: &UrlBuf) -> std::io::Result<Self> {
|
||||
Ok(Self::from_follow(url, provider::symlink_metadata(url).await?).await)
|
||||
}
|
||||
|
||||
pub async fn from_follow(url: &Url, mut meta: Metadata) -> Self {
|
||||
pub async fn from_follow(url: &UrlBuf, mut meta: Metadata) -> Self {
|
||||
let mut attached = ChaKind::hidden(url, &meta);
|
||||
if meta.is_symlink() {
|
||||
attached |= ChaKind::LINK;
|
||||
|
|
@ -76,7 +76,7 @@ impl Cha {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_dummy(_url: &Url, ft: Option<FileType>) -> Self {
|
||||
pub fn from_dummy(_url: &UrlBuf, ft: Option<FileType>) -> Self {
|
||||
let mut me = ft.map(Self::from_half_ft).unwrap_or_default();
|
||||
#[cfg(unix)]
|
||||
if _url.urn().is_hidden() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::fs::Metadata;
|
||||
|
||||
use bitflags::bitflags;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
bitflags! {
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
|
|
@ -20,7 +20,7 @@ bitflags! {
|
|||
|
||||
impl ChaKind {
|
||||
#[inline]
|
||||
pub(super) fn hidden(_url: &Url, _meta: &Metadata) -> Self {
|
||||
pub(super) fn hidden(_url: &UrlBuf, _meta: &Metadata) -> Self {
|
||||
let mut me = Self::empty();
|
||||
|
||||
#[cfg(unix)]
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use std::{env::{current_dir, set_current_dir}, ops::Deref, path::PathBuf, sync::{Arc, atomic::{AtomicBool, Ordering}}};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use yazi_shared::{RoCell, url::Url};
|
||||
use yazi_shared::{RoCell, url::UrlBuf};
|
||||
|
||||
pub static CWD: RoCell<Cwd> = RoCell::new();
|
||||
|
||||
pub struct Cwd(ArcSwap<Url>);
|
||||
pub struct Cwd(ArcSwap<UrlBuf>);
|
||||
|
||||
impl Deref for Cwd {
|
||||
type Target = ArcSwap<Url>;
|
||||
type Target = ArcSwap<UrlBuf>;
|
||||
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
}
|
||||
|
|
@ -21,12 +21,12 @@ impl Default for Cwd {
|
|||
.or_else(|| current_dir().ok())
|
||||
.expect("failed to get current working directory");
|
||||
|
||||
Self(ArcSwap::new(Arc::new(Url::from(p))))
|
||||
Self(ArcSwap::new(Arc::new(UrlBuf::from(p))))
|
||||
}
|
||||
}
|
||||
|
||||
impl Cwd {
|
||||
pub fn set(&self, url: &Url) -> bool {
|
||||
pub fn set(&self, url: &UrlBuf) -> bool {
|
||||
if self.load().as_ref() == url {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use std::{ffi::OsStr, fs::{FileType, Metadata}, hash::{BuildHasher, Hash, Hasher}, ops::Deref};
|
||||
|
||||
use anyhow::Result;
|
||||
use yazi_shared::url::{Uri, Url, Urn, UrnBuf};
|
||||
use yazi_shared::url::{Uri, UrlBuf, Urn, UrnBuf};
|
||||
|
||||
use crate::{cha::Cha, provider};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct File {
|
||||
pub url: Url,
|
||||
pub url: UrlBuf,
|
||||
pub cha: Cha,
|
||||
pub link_to: Option<Url>,
|
||||
pub link_to: Option<UrlBuf>,
|
||||
}
|
||||
|
||||
impl Deref for File {
|
||||
|
|
@ -21,13 +21,13 @@ impl Deref for File {
|
|||
|
||||
impl File {
|
||||
#[inline]
|
||||
pub async fn new(url: Url) -> Result<Self> {
|
||||
pub async fn new(url: UrlBuf) -> Result<Self> {
|
||||
let meta = provider::symlink_metadata(&url).await?;
|
||||
Ok(Self::from_follow(url, meta).await)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn from_follow(url: Url, meta: Metadata) -> Self {
|
||||
pub async fn from_follow(url: UrlBuf, meta: Metadata) -> Self {
|
||||
let link_to = if meta.is_symlink() { provider::read_link(&url).await.ok() } else { None };
|
||||
|
||||
let cha = Cha::from_follow(&url, meta).await;
|
||||
|
|
@ -36,7 +36,7 @@ impl File {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_dummy(url: Url, ft: Option<FileType>) -> Self {
|
||||
pub fn from_dummy(url: UrlBuf, ft: Option<FileType>) -> Self {
|
||||
let cha = Cha::from_dummy(&url, ft);
|
||||
Self { url, cha, link_to: None }
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ impl File {
|
|||
pub fn hash_u64(&self) -> u64 { foldhash::fast::FixedState::default().hash_one(self) }
|
||||
|
||||
#[inline]
|
||||
pub fn chdir(&self, wd: &Url) -> Self {
|
||||
pub fn chdir(&self, wd: &UrlBuf) -> Self {
|
||||
Self { url: self.url.rebase(wd), cha: self.cha, link_to: self.link_to.clone() }
|
||||
}
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ impl File {
|
|||
impl File {
|
||||
// --- Url
|
||||
#[inline]
|
||||
pub fn url_owned(&self) -> Url { self.url.to_owned() }
|
||||
pub fn url_owned(&self) -> UrlBuf { self.url.to_owned() }
|
||||
|
||||
#[inline]
|
||||
pub fn uri(&self) -> &Uri { self.url.uri() }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::{collections::{HashMap, HashSet}, mem, ops::{Deref, DerefMut, Not}};
|
||||
|
||||
use tokio::{select, sync::mpsc::{self, UnboundedReceiver}};
|
||||
use yazi_shared::{Id, url::{Url, Urn, UrnBuf}};
|
||||
use yazi_shared::{Id, url::{UrlBuf, Urn, UrnBuf}};
|
||||
|
||||
use super::{FilesSorter, Filter};
|
||||
use crate::{FILES_TICKET, File, FilesOp, SortBy, cha::Cha, mounts::PARTITIONS, provider::{self, DirEntry}};
|
||||
|
|
@ -34,7 +34,7 @@ impl DerefMut for Files {
|
|||
impl Files {
|
||||
pub fn new(show_hidden: bool) -> Self { Self { show_hidden, ..Default::default() } }
|
||||
|
||||
pub async fn from_dir(dir: &Url) -> std::io::Result<UnboundedReceiver<File>> {
|
||||
pub async fn from_dir(dir: &UrlBuf) -> std::io::Result<UnboundedReceiver<File>> {
|
||||
let mut it = provider::read_dir(dir).await?;
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ impl Files {
|
|||
Ok(rx)
|
||||
}
|
||||
|
||||
pub async fn from_dir_bulk(dir: &Url) -> std::io::Result<Vec<File>> {
|
||||
pub async fn from_dir_bulk(dir: &UrlBuf) -> std::io::Result<Vec<File>> {
|
||||
let mut it = provider::read_dir(dir).await?;
|
||||
let mut entries = Vec::with_capacity(5000);
|
||||
while let Ok(Some(entry)) = it.next_entry().await {
|
||||
|
|
@ -85,7 +85,7 @@ impl Files {
|
|||
)
|
||||
}
|
||||
|
||||
pub async fn assert_stale(dir: &Url, cha: Cha) -> Option<Cha> {
|
||||
pub async fn assert_stale(dir: &UrlBuf, cha: Cha) -> Option<Cha> {
|
||||
use std::io::ErrorKind;
|
||||
match Cha::from_url(dir).await {
|
||||
Ok(c) if !c.is_dir() => FilesOp::issue_error(dir, ErrorKind::NotADirectory).await,
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString},
|
|||
|
||||
use anyhow::{Result, bail};
|
||||
use tokio::{fs, io, select, sync::{mpsc, oneshot}, time};
|
||||
use yazi_shared::url::{Component, Url};
|
||||
use yazi_shared::url::{Component, UrlBuf};
|
||||
|
||||
use crate::{cha::Cha, provider};
|
||||
|
||||
#[inline]
|
||||
pub async fn maybe_exists(u: impl AsRef<Url>) -> bool {
|
||||
pub async fn maybe_exists(u: impl AsRef<UrlBuf>) -> bool {
|
||||
match provider::symlink_metadata(u).await {
|
||||
Ok(_) => true,
|
||||
Err(e) => e.kind() != io::ErrorKind::NotFound,
|
||||
|
|
@ -17,7 +17,7 @@ pub async fn maybe_exists(u: impl AsRef<Url>) -> bool {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn must_be_dir(u: impl AsRef<Url>) -> bool {
|
||||
pub async fn must_be_dir(u: impl AsRef<UrlBuf>) -> bool {
|
||||
provider::metadata(u).await.is_ok_and(|m| m.is_dir())
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ async fn _paths_to_same_file(a: &Path, b: &Path) -> std::io::Result<bool> {
|
|||
Ok(final_name(a).await? == final_name(b).await?)
|
||||
}
|
||||
|
||||
pub async fn realname(u: &Url) -> Option<OsString> {
|
||||
pub async fn realname(u: &UrlBuf) -> Option<OsString> {
|
||||
let name = u.file_name()?;
|
||||
if *u == provider::canonicalize(u).await.ok()? {
|
||||
return None;
|
||||
|
|
@ -159,8 +159,8 @@ pub async fn realname_unchecked<'a>(
|
|||
}
|
||||
|
||||
pub fn copy_with_progress(
|
||||
from: &Url,
|
||||
to: &Url,
|
||||
from: &UrlBuf,
|
||||
to: &UrlBuf,
|
||||
cha: Cha,
|
||||
) -> mpsc::Receiver<Result<u64, io::Error>> {
|
||||
let (tx, rx) = mpsc::channel(1);
|
||||
|
|
@ -212,7 +212,7 @@ pub fn copy_with_progress(
|
|||
rx
|
||||
}
|
||||
|
||||
async fn _copy_with_progress(from: Url, to: Url, cha: Cha) -> io::Result<u64> {
|
||||
async fn _copy_with_progress(from: UrlBuf, to: UrlBuf, cha: Cha) -> io::Result<u64> {
|
||||
let mut ft = std::fs::FileTimes::new();
|
||||
cha.atime.map(|t| ft = ft.set_accessed(t));
|
||||
cha.mtime.map(|t| ft = ft.set_modified(t));
|
||||
|
|
@ -260,7 +260,7 @@ async fn _copy_with_progress(from: Url, to: Url, cha: Cha) -> io::Result<u64> {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn remove_dir_clean(dir: &Url) {
|
||||
pub async fn remove_dir_clean(dir: &UrlBuf) {
|
||||
let Ok(mut it) = provider::read_dir(dir).await else { return };
|
||||
|
||||
while let Ok(Some(entry)) = it.next_entry().await {
|
||||
|
|
@ -330,7 +330,7 @@ pub fn permissions(m: libc::mode_t, dummy: bool) -> String {
|
|||
// Find the max common root in a list of urls
|
||||
// e.g. /a/b/c, /a/b/d -> /a/b
|
||||
// /aa/bb/cc, /aa/dd/ee -> /aa
|
||||
pub fn max_common_root(urls: &[Url]) -> usize {
|
||||
pub fn max_common_root(urls: &[UrlBuf]) -> usize {
|
||||
if urls.is_empty() {
|
||||
return 0;
|
||||
} else if urls.len() == 1 {
|
||||
|
|
@ -371,7 +371,7 @@ pub fn max_common_root(urls: &[Url]) -> usize {
|
|||
fn test_max_common_root() {
|
||||
fn assert(input: &[&str], expected: &str) {
|
||||
use std::str::FromStr;
|
||||
let urls: Vec<_> = input.iter().copied().map(Url::from_str).collect::<Result<_>>().unwrap();
|
||||
let urls: Vec<_> = input.iter().copied().map(UrlBuf::from_str).collect::<Result<_>>().unwrap();
|
||||
|
||||
let mut comp = urls[0].components();
|
||||
for _ in 0..comp.clone().count() - max_common_root(&urls) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use yazi_macro::relay;
|
||||
use yazi_shared::{Id, Ids, url::{Url, UrnBuf}};
|
||||
use yazi_shared::{Id, Ids, url::{UrlBuf, UrnBuf}};
|
||||
|
||||
use super::File;
|
||||
use crate::{cha::Cha, maybe_exists};
|
||||
|
|
@ -10,21 +10,21 @@ pub static FILES_TICKET: Ids = Ids::new();
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum FilesOp {
|
||||
Full(Url, Vec<File>, Cha),
|
||||
Part(Url, Vec<File>, Id),
|
||||
Done(Url, Cha, Id),
|
||||
Size(Url, HashMap<UrnBuf, u64>),
|
||||
IOErr(Url, std::io::ErrorKind),
|
||||
Full(UrlBuf, Vec<File>, Cha),
|
||||
Part(UrlBuf, Vec<File>, Id),
|
||||
Done(UrlBuf, Cha, Id),
|
||||
Size(UrlBuf, HashMap<UrnBuf, u64>),
|
||||
IOErr(UrlBuf, std::io::ErrorKind),
|
||||
|
||||
Creating(Url, Vec<File>),
|
||||
Deleting(Url, HashSet<UrnBuf>),
|
||||
Updating(Url, HashMap<UrnBuf, File>),
|
||||
Upserting(Url, HashMap<UrnBuf, File>),
|
||||
Creating(UrlBuf, Vec<File>),
|
||||
Deleting(UrlBuf, HashSet<UrnBuf>),
|
||||
Updating(UrlBuf, HashMap<UrnBuf, File>),
|
||||
Upserting(UrlBuf, HashMap<UrnBuf, File>),
|
||||
}
|
||||
|
||||
impl FilesOp {
|
||||
#[inline]
|
||||
pub fn cwd(&self) -> &Url {
|
||||
pub fn cwd(&self) -> &UrlBuf {
|
||||
match self {
|
||||
Self::Full(u, ..) => u,
|
||||
Self::Part(u, ..) => u,
|
||||
|
|
@ -44,13 +44,13 @@ impl FilesOp {
|
|||
yazi_shared::event::Event::Call(relay!(mgr:update_files).with_any("op", self).into()).emit();
|
||||
}
|
||||
|
||||
pub fn prepare(cwd: &Url) -> Id {
|
||||
pub fn prepare(cwd: &UrlBuf) -> Id {
|
||||
let ticket = FILES_TICKET.next();
|
||||
Self::Part(cwd.clone(), vec![], ticket).emit();
|
||||
ticket
|
||||
}
|
||||
|
||||
pub fn rename(map: HashMap<Url, File>) {
|
||||
pub fn rename(map: HashMap<UrlBuf, File>) {
|
||||
let mut parents: HashMap<_, (HashSet<_>, HashMap<_, _>)> = Default::default();
|
||||
for (o, n) in map {
|
||||
let Some(o_p) = o.parent_url() else { continue };
|
||||
|
|
@ -95,7 +95,7 @@ impl FilesOp {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn chdir(&self, wd: &Url) -> Self {
|
||||
pub fn chdir(&self, wd: &UrlBuf) -> Self {
|
||||
macro_rules! files {
|
||||
($files:expr) => {{ $files.iter().map(|file| file.chdir(wd)).collect() }};
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ impl FilesOp {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn issue_error(cwd: &Url, kind: std::io::ErrorKind) {
|
||||
pub async fn issue_error(cwd: &UrlBuf, kind: std::io::ErrorKind) {
|
||||
use std::io::ErrorKind;
|
||||
if kind != ErrorKind::NotFound {
|
||||
Self::IOErr(cwd.clone(), kind).emit();
|
||||
|
|
@ -129,7 +129,7 @@ impl FilesOp {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn diff_recoverable(&self, contains: impl Fn(&Url) -> bool) -> (Vec<Url>, Vec<Url>) {
|
||||
pub fn diff_recoverable(&self, contains: impl Fn(&UrlBuf) -> bool) -> (Vec<UrlBuf>, Vec<UrlBuf>) {
|
||||
match self {
|
||||
Self::Deleting(cwd, urns) => (urns.iter().map(|u| cwd.join(u)).collect(), vec![]),
|
||||
Self::Updating(cwd, urns) | Self::Upserting(cwd, urns) => urns
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use std::{borrow::Cow, path::{Path, PathBuf}};
|
||||
|
||||
use yazi_shared::url::{Loc, Url};
|
||||
use yazi_shared::{loc::LocBuf, url::UrlBuf};
|
||||
|
||||
pub fn clean_url<'a>(url: impl Into<Cow<'a, Url>>) -> Url {
|
||||
pub fn clean_url<'a>(url: impl Into<Cow<'a, UrlBuf>>) -> UrlBuf {
|
||||
let cow = url.into();
|
||||
let (path, uri, urn) = clean_path_impl(&cow.loc, cow.loc.base().count(), cow.loc.trail().count());
|
||||
|
||||
let loc = Loc::with(path, uri, urn).expect("Failed to create Loc from cleaned path");
|
||||
let loc = LocBuf::with(path, uri, urn).expect("Failed to create Loc from cleaned path");
|
||||
match cow {
|
||||
Cow::Borrowed(u) => Url { loc, scheme: u.scheme.clone() },
|
||||
Cow::Owned(u) => Url { loc, scheme: u.scheme },
|
||||
Cow::Borrowed(u) => UrlBuf { loc, scheme: u.scheme.clone() },
|
||||
Cow::Owned(u) => UrlBuf { loc, scheme: u.scheme },
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ mod tests {
|
|||
];
|
||||
|
||||
for (input, expected) in cases {
|
||||
let input: Url = input.parse()?;
|
||||
let input: UrlBuf = input.parse()?;
|
||||
#[cfg(unix)]
|
||||
assert_eq!(format!("{:?}", clean_url(input)), expected);
|
||||
#[cfg(windows)]
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
use std::{borrow::Cow, ffi::{OsStr, OsString}, path::{Path, PathBuf}};
|
||||
|
||||
use yazi_shared::url::{Loc, Url};
|
||||
use yazi_shared::{loc::LocBuf, url::UrlBuf};
|
||||
|
||||
use crate::{CWD, path::clean_url};
|
||||
|
||||
#[inline]
|
||||
pub fn expand_url<'a>(url: impl AsRef<Url>) -> Url { clean_url(expand_url_impl(url.as_ref())) }
|
||||
pub fn expand_url<'a>(url: impl AsRef<UrlBuf>) -> UrlBuf {
|
||||
clean_url(expand_url_impl(url.as_ref()))
|
||||
}
|
||||
|
||||
fn expand_url_impl(url: &Url) -> Cow<'_, Url> {
|
||||
fn expand_url_impl(url: &UrlBuf) -> Cow<'_, UrlBuf> {
|
||||
let (o_base, o_rest, o_urn) = url.loc.triple();
|
||||
|
||||
let n_base = expand_variables(o_base);
|
||||
|
|
@ -20,14 +22,14 @@ fn expand_url_impl(url: &Url) -> Cow<'_, Url> {
|
|||
let uri_count = url.uri().count() as isize;
|
||||
let urn_count = url.urn().count() as isize;
|
||||
|
||||
let loc = Loc::with(
|
||||
let loc = LocBuf::with(
|
||||
PathBuf::from_iter([n_base, n_rest, n_urn]),
|
||||
(uri_count + rest_diff + urn_diff) as usize,
|
||||
(urn_count + urn_diff) as usize,
|
||||
)
|
||||
.expect("Failed to create Loc from expanded path");
|
||||
|
||||
let url = Url { loc, scheme: url.scheme.clone() };
|
||||
let url = UrlBuf { loc, scheme: url.scheme.clone() };
|
||||
match absolute_url(&url) {
|
||||
Cow::Borrowed(_) => url.into(),
|
||||
Cow::Owned(u) => u.into(),
|
||||
|
|
@ -60,36 +62,36 @@ fn expand_variables(p: &Path) -> Cow<'_, Path> {
|
|||
}
|
||||
}
|
||||
|
||||
fn absolute_url(url: &Url) -> Cow<'_, Url> {
|
||||
fn absolute_url(url: &UrlBuf) -> Cow<'_, UrlBuf> {
|
||||
let b = url.loc.as_os_str().as_encoded_bytes();
|
||||
let local = !url.scheme.is_virtual();
|
||||
|
||||
if cfg!(windows) && local && b.len() == 2 && b[1] == b':' && b[0].is_ascii_alphabetic() {
|
||||
let loc = Loc::with(
|
||||
let loc = LocBuf::with(
|
||||
format!(r"{}:\", b[0].to_ascii_uppercase() as char).into(),
|
||||
if url.has_base() { 0 } else { 2 },
|
||||
if url.has_trail() { 0 } else { 2 },
|
||||
)
|
||||
.expect("Failed to create Loc from drive letter");
|
||||
Url { loc, scheme: url.scheme.clone() }.into()
|
||||
UrlBuf { loc, scheme: url.scheme.clone() }.into()
|
||||
} else if local
|
||||
&& let Ok(rest) = url.loc.strip_prefix("~/")
|
||||
&& let Some(home) = dirs::home_dir()
|
||||
&& home.is_absolute()
|
||||
{
|
||||
let add = home.components().count() - 1; // Home root ("~") has offset by the absolute root ("/")
|
||||
let loc = Loc::with(
|
||||
let loc = LocBuf::with(
|
||||
home.join(rest),
|
||||
url.uri().count() + if url.has_base() { 0 } else { add },
|
||||
url.urn().count() + if url.has_trail() { 0 } else { add },
|
||||
)
|
||||
.expect("Failed to create Loc from home directory");
|
||||
Url { loc, scheme: url.scheme.clone() }.into()
|
||||
UrlBuf { loc, scheme: url.scheme.clone() }.into()
|
||||
} else if !url.is_absolute() {
|
||||
let cwd = CWD.load();
|
||||
let loc = Loc::with(cwd.loc.join(&url.loc), url.uri().count(), url.urn().count())
|
||||
let loc = LocBuf::with(cwd.loc.join(&url.loc), url.uri().count(), url.urn().count())
|
||||
.expect("Failed to create Loc from relative path");
|
||||
Url { loc, scheme: cwd.scheme.clone() }.into()
|
||||
UrlBuf { loc, scheme: cwd.scheme.clone() }.into()
|
||||
} else {
|
||||
url.into()
|
||||
}
|
||||
|
|
@ -149,7 +151,7 @@ mod tests {
|
|||
];
|
||||
|
||||
for (input, expected) in cases {
|
||||
let u: Url = input.parse()?;
|
||||
let u: UrlBuf = input.parse()?;
|
||||
assert_eq!(format!("{:?}", expand_url(u)), expected);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::{borrow::Cow, ffi::{OsStr, OsString}, future::Future, io, path::PathBuf};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use yazi_shared::url::{Loc, Url};
|
||||
use yazi_shared::{loc::LocBuf, url::UrlBuf};
|
||||
|
||||
use crate::provider;
|
||||
|
||||
pub fn skip_url(url: &Url, n: usize) -> Cow<'_, OsStr> {
|
||||
pub fn skip_url(url: &UrlBuf, n: usize) -> Cow<'_, OsStr> {
|
||||
let mut it = url.components();
|
||||
for _ in 0..n {
|
||||
if it.next().is_none() {
|
||||
|
|
@ -15,7 +15,7 @@ pub fn skip_url(url: &Url, n: usize) -> Cow<'_, OsStr> {
|
|||
it.os_str()
|
||||
}
|
||||
|
||||
pub async fn unique_name<F>(u: Url, append: F) -> io::Result<Url>
|
||||
pub async fn unique_name<F>(u: UrlBuf, append: F) -> io::Result<UrlBuf>
|
||||
where
|
||||
F: Future<Output = bool>,
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
async fn _unique_name(mut url: Url, append: bool) -> io::Result<Url> {
|
||||
async fn _unique_name(mut url: UrlBuf, append: bool) -> io::Result<UrlBuf> {
|
||||
let Some(stem) = url.file_stem().map(|s| s.to_owned()) else {
|
||||
return Err(io::Error::new(io::ErrorKind::InvalidInput, "empty file stem"));
|
||||
};
|
||||
|
|
@ -63,7 +63,7 @@ async fn _unique_name(mut url: Url, append: bool) -> io::Result<Url> {
|
|||
Ok(url)
|
||||
}
|
||||
|
||||
pub fn url_relative_to<'a>(from: &Url, to: &'a Url) -> Result<Cow<'a, Url>> {
|
||||
pub fn url_relative_to<'a>(from: &UrlBuf, to: &'a UrlBuf) -> Result<Cow<'a, UrlBuf>> {
|
||||
use yazi_shared::url::Component::*;
|
||||
|
||||
if from.is_absolute() != to.is_absolute() {
|
||||
|
|
@ -75,7 +75,7 @@ pub fn url_relative_to<'a>(from: &Url, to: &'a Url) -> Result<Cow<'a, Url>> {
|
|||
}
|
||||
|
||||
if from.covariant(to) {
|
||||
return Ok(Url { loc: Loc::zeroed("."), scheme: to.scheme.clone() }.into());
|
||||
return Ok(UrlBuf { loc: LocBuf::zeroed("."), scheme: to.scheme.clone() }.into());
|
||||
}
|
||||
|
||||
let (mut f_it, mut t_it) = (from.components(), to.components());
|
||||
|
|
@ -97,7 +97,7 @@ pub fn url_relative_to<'a>(from: &Url, to: &'a Url) -> Result<Cow<'a, Url>> {
|
|||
let rest = t_head.into_iter().chain(t_it);
|
||||
|
||||
let buf: PathBuf = dots.chain(rest).collect();
|
||||
Ok(Url { loc: Loc::zeroed(buf), scheme: to.scheme.clone() }.into())
|
||||
Ok(UrlBuf { loc: LocBuf::zeroed(buf), scheme: to.scheme.clone() }.into())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::{ffi::OsString, io};
|
||||
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
pub enum DirEntry {
|
||||
Local(super::local::DirEntry),
|
||||
|
|
@ -8,7 +8,7 @@ pub enum DirEntry {
|
|||
|
||||
impl DirEntry {
|
||||
#[must_use]
|
||||
pub fn url(&self) -> Url {
|
||||
pub fn url(&self) -> UrlBuf {
|
||||
match self {
|
||||
DirEntry::Local(local) => local.url(),
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ pub enum DirEntrySync {
|
|||
|
||||
impl DirEntrySync {
|
||||
#[must_use]
|
||||
pub fn url(&self) -> Url {
|
||||
pub fn url(&self) -> UrlBuf {
|
||||
match self {
|
||||
DirEntrySync::Local(local) => local.url(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
pub struct DirEntry(tokio::fs::DirEntry);
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ impl From<DirEntry> for crate::provider::DirEntry {
|
|||
|
||||
impl DirEntry {
|
||||
#[must_use]
|
||||
pub fn url(&self) -> Url { self.0.path().into() }
|
||||
pub fn url(&self) -> UrlBuf { self.0.path().into() }
|
||||
}
|
||||
|
||||
// --- DirEntrySync
|
||||
|
|
@ -42,5 +42,5 @@ impl From<DirEntrySync> for crate::provider::DirEntrySync {
|
|||
|
||||
impl DirEntrySync {
|
||||
#[must_use]
|
||||
pub fn url(&self) -> Url { self.0.path().into() }
|
||||
pub fn url(&self) -> UrlBuf { self.0.path().into() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use std::io;
|
||||
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
use crate::provider::{ReadDir, ReadDirSync, RwFile, local::Local};
|
||||
|
||||
#[inline]
|
||||
pub async fn canonicalize(url: impl AsRef<Url>) -> io::Result<Url> {
|
||||
pub async fn canonicalize(url: impl AsRef<UrlBuf>) -> io::Result<UrlBuf> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::canonicalize(path).await.map(Into::into)
|
||||
} else {
|
||||
|
|
@ -14,7 +14,7 @@ pub async fn canonicalize(url: impl AsRef<Url>) -> io::Result<Url> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn create(url: impl AsRef<Url>) -> io::Result<RwFile> {
|
||||
pub async fn create(url: impl AsRef<UrlBuf>) -> io::Result<RwFile> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::create(path).await.map(Into::into)
|
||||
} else {
|
||||
|
|
@ -23,7 +23,7 @@ pub async fn create(url: impl AsRef<Url>) -> io::Result<RwFile> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn create_dir(url: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn create_dir(url: impl AsRef<UrlBuf>) -> io::Result<()> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::create_dir(path).await
|
||||
} else {
|
||||
|
|
@ -32,7 +32,7 @@ pub async fn create_dir(url: impl AsRef<Url>) -> io::Result<()> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn create_dir_all(url: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn create_dir_all(url: impl AsRef<UrlBuf>) -> io::Result<()> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::create_dir_all(path).await
|
||||
} else {
|
||||
|
|
@ -41,7 +41,7 @@ pub async fn create_dir_all(url: impl AsRef<Url>) -> io::Result<()> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn hard_link(original: impl AsRef<Url>, link: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn hard_link(original: impl AsRef<UrlBuf>, link: impl AsRef<UrlBuf>) -> io::Result<()> {
|
||||
if let (Some(original), Some(link)) = (original.as_ref().as_path(), link.as_ref().as_path()) {
|
||||
Local::hard_link(original, link).await
|
||||
} else {
|
||||
|
|
@ -50,7 +50,7 @@ pub async fn hard_link(original: impl AsRef<Url>, link: impl AsRef<Url>) -> io::
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn metadata(url: impl AsRef<Url>) -> io::Result<std::fs::Metadata> {
|
||||
pub async fn metadata(url: impl AsRef<UrlBuf>) -> io::Result<std::fs::Metadata> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::metadata(path).await
|
||||
} else {
|
||||
|
|
@ -59,7 +59,7 @@ pub async fn metadata(url: impl AsRef<Url>) -> io::Result<std::fs::Metadata> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn open(url: impl AsRef<Url>) -> io::Result<RwFile> {
|
||||
pub async fn open(url: impl AsRef<UrlBuf>) -> io::Result<RwFile> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::open(path).await.map(Into::into)
|
||||
} else {
|
||||
|
|
@ -68,7 +68,7 @@ pub async fn open(url: impl AsRef<Url>) -> io::Result<RwFile> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn read_dir(url: impl AsRef<Url>) -> io::Result<ReadDir> {
|
||||
pub async fn read_dir(url: impl AsRef<UrlBuf>) -> io::Result<ReadDir> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::read_dir(path).await.map(Into::into)
|
||||
} else {
|
||||
|
|
@ -77,7 +77,7 @@ pub async fn read_dir(url: impl AsRef<Url>) -> io::Result<ReadDir> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn read_dir_sync(url: impl AsRef<Url>) -> io::Result<ReadDirSync> {
|
||||
pub fn read_dir_sync(url: impl AsRef<UrlBuf>) -> io::Result<ReadDirSync> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::read_dir_sync(path).map(Into::into)
|
||||
} else {
|
||||
|
|
@ -86,7 +86,7 @@ pub fn read_dir_sync(url: impl AsRef<Url>) -> io::Result<ReadDirSync> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn read_link(url: impl AsRef<Url>) -> io::Result<Url> {
|
||||
pub async fn read_link(url: impl AsRef<UrlBuf>) -> io::Result<UrlBuf> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::read_link(path).await.map(Into::into)
|
||||
} else {
|
||||
|
|
@ -95,7 +95,7 @@ pub async fn read_link(url: impl AsRef<Url>) -> io::Result<Url> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn remove_dir(url: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn remove_dir(url: impl AsRef<UrlBuf>) -> io::Result<()> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::remove_dir(path).await
|
||||
} else {
|
||||
|
|
@ -104,7 +104,7 @@ pub async fn remove_dir(url: impl AsRef<Url>) -> io::Result<()> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn remove_dir_all(url: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn remove_dir_all(url: impl AsRef<UrlBuf>) -> io::Result<()> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::remove_dir_all(path).await
|
||||
} else {
|
||||
|
|
@ -113,7 +113,7 @@ pub async fn remove_dir_all(url: impl AsRef<Url>) -> io::Result<()> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn remove_file(url: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn remove_file(url: impl AsRef<UrlBuf>) -> io::Result<()> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::remove_file(path).await
|
||||
} else {
|
||||
|
|
@ -122,7 +122,7 @@ pub async fn remove_file(url: impl AsRef<Url>) -> io::Result<()> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn rename(from: impl AsRef<Url>, to: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn rename(from: impl AsRef<UrlBuf>, to: impl AsRef<UrlBuf>) -> io::Result<()> {
|
||||
if let (Some(from), Some(to)) = (from.as_ref().as_path(), to.as_ref().as_path()) {
|
||||
Local::rename(from, to).await
|
||||
} else {
|
||||
|
|
@ -131,7 +131,7 @@ pub async fn rename(from: impl AsRef<Url>, to: impl AsRef<Url>) -> io::Result<()
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn symlink_dir(original: impl AsRef<Url>, link: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn symlink_dir(original: impl AsRef<UrlBuf>, link: impl AsRef<UrlBuf>) -> io::Result<()> {
|
||||
if let (Some(original), Some(link)) = (original.as_ref().as_path(), link.as_ref().as_path()) {
|
||||
Local::symlink_dir(original, link).await
|
||||
} else {
|
||||
|
|
@ -140,7 +140,10 @@ pub async fn symlink_dir(original: impl AsRef<Url>, link: impl AsRef<Url>) -> io
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn symlink_file(original: impl AsRef<Url>, link: impl AsRef<Url>) -> io::Result<()> {
|
||||
pub async fn symlink_file(
|
||||
original: impl AsRef<UrlBuf>,
|
||||
link: impl AsRef<UrlBuf>,
|
||||
) -> io::Result<()> {
|
||||
if let (Some(original), Some(link)) = (original.as_ref().as_path(), link.as_ref().as_path()) {
|
||||
Local::symlink_file(original, link).await
|
||||
} else {
|
||||
|
|
@ -149,7 +152,7 @@ pub async fn symlink_file(original: impl AsRef<Url>, link: impl AsRef<Url>) -> i
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn symlink_metadata(url: impl AsRef<Url>) -> io::Result<std::fs::Metadata> {
|
||||
pub async fn symlink_metadata(url: impl AsRef<UrlBuf>) -> io::Result<std::fs::Metadata> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::symlink_metadata(path).await
|
||||
} else {
|
||||
|
|
@ -157,7 +160,7 @@ pub async fn symlink_metadata(url: impl AsRef<Url>) -> io::Result<std::fs::Metad
|
|||
}
|
||||
}
|
||||
|
||||
pub fn symlink_metadata_sync(url: impl AsRef<Url>) -> io::Result<std::fs::Metadata> {
|
||||
pub fn symlink_metadata_sync(url: impl AsRef<UrlBuf>) -> io::Result<std::fs::Metadata> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::symlink_metadata_sync(path)
|
||||
} else {
|
||||
|
|
@ -166,7 +169,7 @@ pub fn symlink_metadata_sync(url: impl AsRef<Url>) -> io::Result<std::fs::Metada
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn write(url: impl AsRef<Url>, contents: impl AsRef<[u8]>) -> io::Result<()> {
|
||||
pub async fn write(url: impl AsRef<UrlBuf>, contents: impl AsRef<[u8]>) -> io::Result<()> {
|
||||
if let Some(path) = url.as_ref().as_path() {
|
||||
Local::write(path, contents).await
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ use std::{ffi::OsString, path::MAIN_SEPARATOR_STR};
|
|||
|
||||
use anyhow::bail;
|
||||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{Id, event::CmdCow, url::{Url, UrnBuf}};
|
||||
use yazi_shared::{Id, event::CmdCow, url::{UrlBuf, UrnBuf}};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ShowOpt {
|
||||
pub cache: Vec<CmpItem>,
|
||||
pub cache_name: Url,
|
||||
pub cache_name: UrlBuf,
|
||||
pub word: UrnBuf,
|
||||
pub ticket: Id,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_fs::path::expand_url;
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CdOpt {
|
||||
pub target: Url,
|
||||
pub target: UrlBuf,
|
||||
pub interactive: bool,
|
||||
pub source: CdSource,
|
||||
}
|
||||
|
|
@ -21,8 +21,10 @@ impl From<CmdCow> for CdOpt {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<(Url, CdSource)> for CdOpt {
|
||||
fn from((target, source): (Url, CdSource)) -> Self { Self { target, interactive: false, source } }
|
||||
impl From<(UrlBuf, CdSource)> for CdOpt {
|
||||
fn from((target, source): (UrlBuf, CdSource)) -> Self {
|
||||
Self { target, interactive: false, source }
|
||||
}
|
||||
}
|
||||
|
||||
impl FromLua for CdOpt {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct OpenDoOpt {
|
||||
pub cwd: Url,
|
||||
pub hovered: Url,
|
||||
pub targets: Vec<(Url, &'static str)>,
|
||||
pub cwd: UrlBuf,
|
||||
pub hovered: UrlBuf,
|
||||
pub targets: Vec<(UrlBuf, &'static str)>,
|
||||
pub interactive: bool,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ use std::borrow::Cow;
|
|||
use anyhow::anyhow;
|
||||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_config::opener::OpenerRule;
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OpenWithOpt {
|
||||
pub opener: Cow<'static, OpenerRule>,
|
||||
pub cwd: Url,
|
||||
pub targets: Vec<Url>,
|
||||
pub cwd: UrlBuf,
|
||||
pub targets: Vec<UrlBuf>,
|
||||
}
|
||||
|
||||
impl TryFrom<CmdCow> for OpenWithOpt {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{event::{CmdCow, Data}, url::Url};
|
||||
use yazi_shared::{event::{CmdCow, Data}, url::UrlBuf};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PeekOpt {
|
||||
pub skip: Option<usize>,
|
||||
pub force: bool,
|
||||
pub only_if: Option<Url>,
|
||||
pub only_if: Option<UrlBuf>,
|
||||
pub upper_bound: bool,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RemoveOpt {
|
||||
pub force: bool,
|
||||
pub permanently: bool,
|
||||
pub hovered: bool,
|
||||
pub targets: Vec<Url>,
|
||||
pub targets: Vec<UrlBuf>,
|
||||
}
|
||||
|
||||
impl From<CmdCow> for RemoveOpt {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_fs::path::expand_url;
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
use crate::mgr::CdSource;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RevealOpt {
|
||||
pub target: Url,
|
||||
pub target: UrlBuf,
|
||||
pub source: CdSource,
|
||||
pub no_dummy: bool,
|
||||
}
|
||||
|
|
@ -23,12 +23,12 @@ impl From<CmdCow> for RevealOpt {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Url> for RevealOpt {
|
||||
fn from(target: Url) -> Self { Self { target, source: CdSource::Reveal, no_dummy: false } }
|
||||
impl From<UrlBuf> for RevealOpt {
|
||||
fn from(target: UrlBuf) -> Self { Self { target, source: CdSource::Reveal, no_dummy: false } }
|
||||
}
|
||||
|
||||
impl From<(Url, CdSource)> for RevealOpt {
|
||||
fn from((target, source): (Url, CdSource)) -> Self { Self { target, source, no_dummy: false } }
|
||||
impl From<(UrlBuf, CdSource)> for RevealOpt {
|
||||
fn from((target, source): (UrlBuf, CdSource)) -> Self { Self { target, source, no_dummy: false } }
|
||||
}
|
||||
|
||||
impl FromLua for RevealOpt {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use anyhow::bail;
|
||||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{SStr, event::{CmdCow, Data}, url::Url};
|
||||
use yazi_shared::{SStr, event::{CmdCow, Data}, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ShellOpt {
|
||||
pub run: SStr,
|
||||
pub cwd: Option<Url>,
|
||||
pub cwd: Option<UrlBuf>,
|
||||
|
||||
pub block: bool,
|
||||
pub orphan: bool,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_boot::BOOT;
|
||||
use yazi_fs::path::expand_url;
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TabCreateOpt {
|
||||
pub wd: Option<Url>,
|
||||
pub wd: Option<UrlBuf>,
|
||||
}
|
||||
|
||||
impl From<CmdCow> for TabCreateOpt {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ToggleOpt {
|
||||
pub url: Option<Url>,
|
||||
pub url: Option<UrlBuf>,
|
||||
pub state: Option<bool>,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ToggleAllOpt {
|
||||
pub urls: Vec<Url>,
|
||||
pub urls: Vec<UrlBuf>,
|
||||
pub state: Option<bool>,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{event::{CmdCow, Data}, url::Url};
|
||||
use yazi_shared::{event::{CmdCow, Data}, url::UrlBuf};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct UpdatePagedOpt {
|
||||
pub page: Option<usize>,
|
||||
pub only_if: Option<Url>,
|
||||
pub only_if: Option<UrlBuf>,
|
||||
}
|
||||
|
||||
impl From<CmdCow> for UpdatePagedOpt {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ impl IntoLua for UpdatePeekedOpt {
|
|||
// --- Lock
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PreviewLock {
|
||||
pub url: yazi_shared::url::Url,
|
||||
pub url: yazi_shared::url::UrlBuf,
|
||||
pub cha: yazi_fs::cha::Cha,
|
||||
pub mime: String,
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ impl IntoLua for UpdateSpottedOpt {
|
|||
// --- Lock
|
||||
#[derive(Debug)]
|
||||
pub struct SpotLock {
|
||||
pub url: yazi_shared::url::Url,
|
||||
pub url: yazi_shared::url::UrlBuf,
|
||||
pub cha: yazi_fs::cha::Cha,
|
||||
pub mime: String,
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use anyhow::bail;
|
||||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UpdateTasksOpt {
|
||||
pub urls: Vec<Url>,
|
||||
pub urls: Vec<UrlBuf>,
|
||||
}
|
||||
|
||||
impl TryFrom<CmdCow> for UpdateTasksOpt {
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ use anyhow::bail;
|
|||
use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, MetaMethod, MultiValue, ObjectLike, UserData, UserDataFields, UserDataMethods, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yazi_binding::get_metatable;
|
||||
use yazi_shared::{event::CmdCow, url::CovUrl};
|
||||
use yazi_shared::{event::CmdCow, url::UrlCov};
|
||||
|
||||
type Iter = yazi_binding::Iter<
|
||||
std::iter::Map<std::collections::hash_set::IntoIter<CovUrl>, fn(CovUrl) -> yazi_binding::Url>,
|
||||
std::iter::Map<std::collections::hash_set::IntoIter<UrlCov>, fn(UrlCov) -> yazi_binding::Url>,
|
||||
yazi_binding::Url,
|
||||
>;
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct UpdateYankedOpt<'a> {
|
||||
pub cut: bool,
|
||||
pub urls: Cow<'a, HashSet<CovUrl>>,
|
||||
pub urls: Cow<'a, HashSet<UrlCov>>,
|
||||
}
|
||||
|
||||
impl TryFrom<CmdCow> for UpdateYankedOpt<'_> {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ use anyhow::anyhow;
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use tokio::sync::oneshot;
|
||||
use yazi_config::opener::OpenerRule;
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
use yazi_shared::{event::CmdCow, url::UrlBuf};
|
||||
|
||||
// --- Exec
|
||||
#[derive(Debug)]
|
||||
pub struct ProcessExecOpt {
|
||||
pub cwd: Url,
|
||||
pub cwd: UrlBuf,
|
||||
pub opener: Cow<'static, OpenerRule>,
|
||||
pub args: Vec<OsString>,
|
||||
pub done: Option<oneshot::Sender<()>>,
|
||||
|
|
|
|||
4
yazi-plugin/src/external/fd.rs
vendored
4
yazi-plugin/src/external/fd.rs
vendored
|
|
@ -3,10 +3,10 @@ use std::process::Stdio;
|
|||
use anyhow::Result;
|
||||
use tokio::{io::{AsyncBufReadExt, BufReader}, process::{Child, Command}, sync::mpsc::{self, UnboundedReceiver}};
|
||||
use yazi_fs::File;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
pub struct FdOpt {
|
||||
pub cwd: Url,
|
||||
pub cwd: UrlBuf,
|
||||
pub hidden: bool,
|
||||
pub subject: String,
|
||||
pub args: Vec<String>,
|
||||
|
|
|
|||
4
yazi-plugin/src/external/rg.rs
vendored
4
yazi-plugin/src/external/rg.rs
vendored
|
|
@ -3,10 +3,10 @@ use std::process::Stdio;
|
|||
use anyhow::{Result, bail};
|
||||
use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}};
|
||||
use yazi_fs::File;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
pub struct RgOpt {
|
||||
pub cwd: Url,
|
||||
pub cwd: UrlBuf,
|
||||
pub hidden: bool,
|
||||
pub subject: String,
|
||||
pub args: Vec<String>,
|
||||
|
|
|
|||
4
yazi-plugin/src/external/rga.rs
vendored
4
yazi-plugin/src/external/rga.rs
vendored
|
|
@ -3,10 +3,10 @@ use std::process::Stdio;
|
|||
use anyhow::{Result, bail};
|
||||
use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}};
|
||||
use yazi_fs::File;
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
pub struct RgaOpt {
|
||||
pub cwd: Url,
|
||||
pub cwd: UrlBuf,
|
||||
pub hidden: bool,
|
||||
pub subject: String,
|
||||
pub args: Vec<String>,
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@ use std::borrow::Cow;
|
|||
|
||||
use yazi_macro::{emit, relay};
|
||||
use yazi_parser::mgr::{FilterOpt, FindDoOpt, OpenDoOpt, SearchOpt, UpdatePeekedOpt, UpdateSpottedOpt};
|
||||
use yazi_shared::{SStr, url::Url};
|
||||
use yazi_shared::{SStr, url::UrlBuf};
|
||||
|
||||
pub struct MgrProxy;
|
||||
|
||||
impl MgrProxy {
|
||||
pub fn cd(target: &Url) {
|
||||
pub fn cd(target: &UrlBuf) {
|
||||
emit!(Call(relay!(mgr:cd, [target]).with("raw", true)));
|
||||
}
|
||||
|
||||
pub fn reveal(target: &Url) {
|
||||
pub fn reveal(target: &UrlBuf) {
|
||||
emit!(Call(relay!(mgr:reveal, [target]).with("raw", true).with("no-dummy", true)));
|
||||
}
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ impl MgrProxy {
|
|||
emit!(Call(relay!(mgr:open_do).with_any("option", opt)));
|
||||
}
|
||||
|
||||
pub fn remove_do(targets: Vec<Url>, permanently: bool) {
|
||||
pub fn remove_do(targets: Vec<UrlBuf>, permanently: bool) {
|
||||
emit!(Call(
|
||||
relay!(mgr:remove_do).with("permanently", permanently).with_any("targets", targets)
|
||||
));
|
||||
|
|
@ -54,11 +54,11 @@ impl MgrProxy {
|
|||
emit!(Call(relay!(mgr:update_spotted).with_any("opt", opt)));
|
||||
}
|
||||
|
||||
pub fn update_tasks(url: &Url) {
|
||||
pub fn update_tasks(url: &UrlBuf) {
|
||||
emit!(Call(relay!(mgr:update_tasks).with_any("urls", vec![url.clone()])));
|
||||
}
|
||||
|
||||
pub fn update_paged_by(page: usize, only_if: &Url) {
|
||||
pub fn update_paged_by(page: usize, only_if: &UrlBuf) {
|
||||
emit!(Call(relay!(mgr:update_paged, [page]).with_any("only-if", only_if.clone())));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,16 +4,16 @@ use tokio::sync::oneshot;
|
|||
use yazi_config::opener::OpenerRule;
|
||||
use yazi_macro::{emit, relay};
|
||||
use yazi_parser::{mgr::OpenWithOpt, tasks::ProcessExecOpt};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
pub struct TasksProxy;
|
||||
|
||||
impl TasksProxy {
|
||||
pub fn open_with(opener: Cow<'static, OpenerRule>, cwd: Url, targets: Vec<Url>) {
|
||||
pub fn open_with(opener: Cow<'static, OpenerRule>, cwd: UrlBuf, targets: Vec<UrlBuf>) {
|
||||
emit!(Call(relay!(tasks:open_with).with_any("option", OpenWithOpt { opener, cwd, targets })));
|
||||
}
|
||||
|
||||
pub async fn process_exec(opener: Cow<'static, OpenerRule>, cwd: Url, args: Vec<OsString>) {
|
||||
pub async fn process_exec(opener: Cow<'static, OpenerRule>, cwd: UrlBuf, args: Vec<OsString>) {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
emit!(Call(relay!(tasks:process_exec).with_any("option", ProcessExecOpt {
|
||||
cwd,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use tokio::{io::{self, ErrorKind::{AlreadyExists, NotFound}}, sync::mpsc};
|
|||
use tracing::warn;
|
||||
use yazi_config::YAZI;
|
||||
use yazi_fs::{SizeCalculator, cha::Cha, copy_with_progress, maybe_exists, ok_or_not_found, path::{skip_url, url_relative_to}, provider::{self, DirEntry}};
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
|
||||
use super::{FileIn, FileInDelete, FileInHardlink, FileInLink, FileInPaste, FileInTrash};
|
||||
use crate::{LOW, NORMAL, TaskOp, TaskProg};
|
||||
|
|
@ -320,13 +320,13 @@ impl File {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
async fn cha(url: &Url, follow: bool) -> io::Result<Cha> {
|
||||
async fn cha(url: &UrlBuf, follow: bool) -> io::Result<Cha> {
|
||||
let meta = provider::symlink_metadata(url).await?;
|
||||
Ok(if follow { Cha::from_follow(url, meta).await } else { Cha::new(url, meta) })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn cha_from(entry: DirEntry, url: &Url, follow: bool) -> io::Result<Cha> {
|
||||
async fn cha_from(entry: DirEntry, url: &UrlBuf, follow: bool) -> io::Result<Cha> {
|
||||
Ok(if follow {
|
||||
Cha::from_follow(url, entry.metadata().await?).await
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use yazi_fs::cha::Cha;
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FileIn {
|
||||
|
|
@ -26,8 +26,8 @@ impl FileIn {
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct FileInPaste {
|
||||
pub id: Id,
|
||||
pub from: Url,
|
||||
pub to: Url,
|
||||
pub from: UrlBuf,
|
||||
pub to: UrlBuf,
|
||||
pub cha: Option<Cha>,
|
||||
pub cut: bool,
|
||||
pub follow: bool,
|
||||
|
|
@ -35,7 +35,7 @@ pub struct FileInPaste {
|
|||
}
|
||||
|
||||
impl FileInPaste {
|
||||
pub(super) fn spawn(&self, from: Url, to: Url, cha: Cha) -> Self {
|
||||
pub(super) fn spawn(&self, from: UrlBuf, to: UrlBuf, cha: Cha) -> Self {
|
||||
Self {
|
||||
id: self.id,
|
||||
from,
|
||||
|
|
@ -52,8 +52,8 @@ impl FileInPaste {
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct FileInLink {
|
||||
pub id: Id,
|
||||
pub from: Url,
|
||||
pub to: Url,
|
||||
pub from: UrlBuf,
|
||||
pub to: UrlBuf,
|
||||
pub cha: Option<Cha>,
|
||||
pub resolve: bool,
|
||||
pub relative: bool,
|
||||
|
|
@ -78,14 +78,14 @@ impl From<FileInPaste> for FileInLink {
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct FileInHardlink {
|
||||
pub id: Id,
|
||||
pub from: Url,
|
||||
pub to: Url,
|
||||
pub from: UrlBuf,
|
||||
pub to: UrlBuf,
|
||||
pub cha: Option<Cha>,
|
||||
pub follow: bool,
|
||||
}
|
||||
|
||||
impl FileInHardlink {
|
||||
pub(super) fn spawn(&self, from: Url, to: Url, cha: Cha) -> Self {
|
||||
pub(super) fn spawn(&self, from: UrlBuf, to: UrlBuf, cha: Cha) -> Self {
|
||||
Self { id: self.id, from, to, cha: Some(cha), follow: self.follow }
|
||||
}
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ impl FileInHardlink {
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct FileInDelete {
|
||||
pub id: Id,
|
||||
pub target: Url,
|
||||
pub target: UrlBuf,
|
||||
pub length: u64,
|
||||
}
|
||||
|
||||
|
|
@ -102,6 +102,6 @@ pub struct FileInDelete {
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct FileInTrash {
|
||||
pub id: Id,
|
||||
pub target: Url,
|
||||
pub target: UrlBuf,
|
||||
pub length: u64,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use yazi_config::plugin::{Fetcher, Preloader};
|
||||
use yazi_shared::{Id, Throttle, url::Url};
|
||||
use yazi_shared::{Id, Throttle, url::UrlBuf};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PreworkIn {
|
||||
|
|
@ -37,6 +37,6 @@ pub struct PreworkInLoad {
|
|||
#[derive(Debug)]
|
||||
pub struct PreworkInSize {
|
||||
pub id: Id,
|
||||
pub target: Url,
|
||||
pub throttle: Arc<Throttle<(Url, u64)>>,
|
||||
pub target: UrlBuf,
|
||||
pub throttle: Arc<Throttle<(UrlBuf, u64)>>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use tracing::error;
|
|||
use yazi_config::Priority;
|
||||
use yazi_fs::{FilesOp, SizeCalculator};
|
||||
use yazi_plugin::isolate;
|
||||
use yazi_shared::{Id, event::CmdCow, url::Url};
|
||||
use yazi_shared::{Id, event::CmdCow, url::UrlBuf};
|
||||
|
||||
use super::{PreworkIn, PreworkInFetch, PreworkInLoad, PreworkInSize};
|
||||
use crate::{HIGH, NORMAL, TaskOp, TaskProg};
|
||||
|
|
@ -20,7 +20,7 @@ pub struct Prework {
|
|||
|
||||
pub loaded: Mutex<LruCache<u64, u32>>,
|
||||
pub loading: Mutex<LruCache<u64, CancellationToken>>,
|
||||
pub sizing: RwLock<HashSet<Url>>,
|
||||
pub sizing: RwLock<HashSet<UrlBuf>>,
|
||||
}
|
||||
|
||||
impl Prework {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::ffi::OsString;
|
||||
|
||||
use tokio::sync::mpsc;
|
||||
use yazi_shared::{Id, url::Url};
|
||||
use yazi_shared::{Id, url::UrlBuf};
|
||||
|
||||
use super::ShellOpt;
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ use super::ShellOpt;
|
|||
#[derive(Debug)]
|
||||
pub struct ProcessInBlock {
|
||||
pub id: Id,
|
||||
pub cwd: Url,
|
||||
pub cwd: UrlBuf,
|
||||
pub cmd: OsString,
|
||||
pub args: Vec<OsString>,
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ impl From<ProcessInBlock> for ShellOpt {
|
|||
#[derive(Debug)]
|
||||
pub struct ProcessInOrphan {
|
||||
pub id: Id,
|
||||
pub cwd: Url,
|
||||
pub cwd: UrlBuf,
|
||||
pub cmd: OsString,
|
||||
pub args: Vec<OsString>,
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ impl From<ProcessInOrphan> for ShellOpt {
|
|||
#[derive(Debug)]
|
||||
pub struct ProcessInBg {
|
||||
pub id: Id,
|
||||
pub cwd: Url,
|
||||
pub cwd: UrlBuf,
|
||||
pub cmd: OsString,
|
||||
pub args: Vec<OsString>,
|
||||
pub cancel: mpsc::Receiver<()>,
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ use std::{ffi::OsString, process::Stdio};
|
|||
|
||||
use anyhow::Result;
|
||||
use tokio::process::{Child, Command};
|
||||
use yazi_shared::url::Url;
|
||||
use yazi_shared::url::UrlBuf;
|
||||
|
||||
pub struct ShellOpt {
|
||||
pub cwd: Url,
|
||||
pub cwd: UrlBuf,
|
||||
pub cmd: OsString,
|
||||
pub args: Vec<OsString>,
|
||||
pub piped: bool,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use yazi_dds::Pump;
|
|||
use yazi_fs::{must_be_dir, path::unique_name, provider, remove_dir_clean};
|
||||
use yazi_parser::{app::PluginOpt, tasks::ProcessExecOpt};
|
||||
use yazi_proxy::MgrProxy;
|
||||
use yazi_shared::{Id, Throttle, url::Url};
|
||||
use yazi_shared::{Id, Throttle, url::UrlBuf};
|
||||
|
||||
use super::{Ongoing, TaskProg, TaskStage};
|
||||
use crate::{HIGH, LOW, NORMAL, TaskKind, TaskOp, file::{File, FileInDelete, FileInHardlink, FileInLink, FileInPaste, FileInTrash}, plugin::{Plugin, PluginInEntry}, prework::{Prework, PreworkInFetch, PreworkInLoad, PreworkInSize}, process::{Process, ProcessInBg, ProcessInBlock, ProcessInOrphan}};
|
||||
|
|
@ -73,7 +73,7 @@ impl Scheduler {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn file_cut(&self, from: Url, mut to: Url, force: bool) {
|
||||
pub fn file_cut(&self, from: UrlBuf, mut to: UrlBuf, force: bool) {
|
||||
let mut ongoing = self.ongoing.lock();
|
||||
let id = ongoing.add(TaskKind::User, format!("Cut {} to {}", from.display(), to.display()));
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ impl Scheduler {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn file_copy(&self, from: Url, mut to: Url, force: bool, follow: bool) {
|
||||
pub fn file_copy(&self, from: UrlBuf, mut to: UrlBuf, force: bool, follow: bool) {
|
||||
let id = self
|
||||
.ongoing
|
||||
.lock()
|
||||
|
|
@ -124,7 +124,7 @@ impl Scheduler {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn file_link(&self, from: Url, mut to: Url, relative: bool, force: bool) {
|
||||
pub fn file_link(&self, from: UrlBuf, mut to: UrlBuf, relative: bool, force: bool) {
|
||||
let id = self
|
||||
.ongoing
|
||||
.lock()
|
||||
|
|
@ -141,7 +141,7 @@ impl Scheduler {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn file_hardlink(&self, from: Url, mut to: Url, force: bool, follow: bool) {
|
||||
pub fn file_hardlink(&self, from: UrlBuf, mut to: UrlBuf, force: bool, follow: bool) {
|
||||
let id = self
|
||||
.ongoing
|
||||
.lock()
|
||||
|
|
@ -161,7 +161,7 @@ impl Scheduler {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn file_delete(&self, target: Url) {
|
||||
pub fn file_delete(&self, target: UrlBuf) {
|
||||
let mut ongoing = self.ongoing.lock();
|
||||
let id = ongoing.add(TaskKind::User, format!("Delete {}", target.display()));
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ impl Scheduler {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn file_trash(&self, target: Url) {
|
||||
pub fn file_trash(&self, target: UrlBuf) {
|
||||
let mut ongoing = self.ongoing.lock();
|
||||
let id = ongoing.add(TaskKind::User, format!("Trash {}", target.display()));
|
||||
|
||||
|
|
@ -246,7 +246,7 @@ impl Scheduler {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn prework_size(&self, targets: Vec<&Url>) {
|
||||
pub fn prework_size(&self, targets: Vec<&UrlBuf>) {
|
||||
let throttle = Arc::new(Throttle::new(targets.len(), Duration::from_millis(300)));
|
||||
let mut ongoing = self.ongoing.lock();
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use anyhow::{Result, anyhow, bail};
|
|||
use serde::{Deserialize, de};
|
||||
|
||||
use super::{Data, DataKey};
|
||||
use crate::{Id, Layer, SStr, Source, url::Url};
|
||||
use crate::{Id, Layer, SStr, Source, url::UrlBuf};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Cmd {
|
||||
|
|
@ -131,7 +131,7 @@ impl Cmd {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn take_first_url(&mut self) -> Option<Url> { self.take_first()?.into_url() }
|
||||
pub fn take_first_url(&mut self) -> Option<UrlBuf> { self.take_first()?.into_url() }
|
||||
|
||||
#[inline]
|
||||
pub fn take_any<T: 'static>(&mut self, name: impl Into<DataKey>) -> Option<T> {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue