Skip to content

Commit 9810196

Browse files
authored
refactor: introduce LocBuf (#3062)
1 parent 2ec3a6c commit 9810196

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1156
-1024
lines changed

yazi-actor/src/cmp/trigger.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use yazi_fs::{CWD, path::expand_url, provider};
55
use yazi_macro::{act, render, succ};
66
use yazi_parser::cmp::{CmpItem, ShowOpt, TriggerOpt};
77
use yazi_proxy::CmpProxy;
8-
use yazi_shared::{OsStrSplit, event::Data, natsort, url::{Url, UrnBuf}};
8+
use yazi_shared::{OsStrSplit, event::Data, natsort, url::{UrlBuf, UrnBuf}};
99

1010
use crate::{Actor, Ctx};
1111

@@ -66,8 +66,8 @@ impl Actor for Trigger {
6666
}
6767

6868
impl Trigger {
69-
fn split_url(s: &str) -> Option<(Url, UrnBuf)> {
70-
let (scheme, path, ..) = Url::parse(s.as_bytes()).ok()?;
69+
fn split_url(s: &str) -> Option<(UrlBuf, UrnBuf)> {
70+
let (scheme, path, ..) = UrlBuf::parse(s.as_bytes()).ok()?;
7171

7272
if !scheme.is_virtual() && path.as_os_str() == "~" {
7373
return None; // We don't autocomplete a `~`, but `~/`
@@ -79,8 +79,8 @@ impl Trigger {
7979
const SEP: char = std::path::MAIN_SEPARATOR;
8080

8181
Some(match path.as_os_str().rsplit_once(SEP) {
82-
Some((p, c)) if p.is_empty() => (Url { loc: MAIN_SEPARATOR_STR.into(), scheme }, c.into()),
83-
Some((p, c)) => (expand_url(Url { loc: p.into(), scheme }), c.into()),
82+
Some((p, c)) if p.is_empty() => (UrlBuf { loc: MAIN_SEPARATOR_STR.into(), scheme }, c.into()),
83+
Some((p, c)) => (expand_url(UrlBuf { loc: p.into(), scheme }), c.into()),
8484
None => (CWD.load().as_ref().clone(), path.into()),
8585
})
8686
}
@@ -95,7 +95,7 @@ mod tests {
9595
fn compare(s: &str, parent: &str, child: &str) {
9696
let (mut p, c) = Trigger::split_url(s).unwrap();
9797
if let Some(u) = p.strip_prefix(yazi_fs::CWD.load().as_ref()) {
98-
p = Url::from(&**u);
98+
p = UrlBuf::from(&**u);
9999
}
100100
assert_eq!((p, c.as_urn()), (parent.parse().unwrap(), Urn::new(child)));
101101
}

yazi-actor/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::{Deref, DerefMut};
33
use anyhow::{Result, anyhow};
44
use yazi_core::{Core, mgr::Tabs, tab::{Folder, Tab}, tasks::Tasks};
55
use yazi_fs::File;
6-
use yazi_shared::{Source, event::Cmd, url::Url};
6+
use yazi_shared::{Source, event::Cmd, url::UrlBuf};
77

88
pub struct Ctx<'a> {
99
pub core: &'a mut Core,
@@ -68,7 +68,7 @@ impl<'a> Ctx<'a> {
6868
pub fn tab_mut(&mut self) -> &mut Tab { &mut self.core.mgr.tabs[self.tab] }
6969

7070
#[inline]
71-
pub fn cwd(&self) -> &Url { self.tab().cwd() }
71+
pub fn cwd(&self) -> &UrlBuf { self.tab().cwd() }
7272

7373
#[inline]
7474
pub fn parent(&self) -> Option<&Folder> { self.tab().parent.as_ref() }

yazi-actor/src/mgr/bulk_rename.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use yazi_fs::{File, FilesOp, max_common_root, maybe_exists, path::skip_url, path
1010
use yazi_macro::{err, succ};
1111
use yazi_parser::VoidOpt;
1212
use yazi_proxy::{AppProxy, HIDER, TasksProxy, WATCHER};
13-
use yazi_shared::{OsStrJoin, event::Data, terminal_clear, url::{Component, Url}};
13+
use yazi_shared::{OsStrJoin, event::Data, terminal_clear, url::{Component, UrlBuf}};
1414
use yazi_term::tty::TTY;
1515

1616
use crate::{Actor, Ctx};
@@ -73,7 +73,12 @@ impl Actor for BulkRename {
7373
}
7474

7575
impl BulkRename {
76-
async fn r#do(root: usize, old: Vec<Tuple>, new: Vec<Tuple>, selected: Vec<Url>) -> Result<()> {
76+
async fn r#do(
77+
root: usize,
78+
old: Vec<Tuple>,
79+
new: Vec<Tuple>,
80+
selected: Vec<UrlBuf>,
81+
) -> Result<()> {
7782
terminal_clear(TTY.writer())?;
7883
if old.len() != new.len() {
7984
#[rustfmt::skip]
@@ -108,7 +113,7 @@ impl BulkRename {
108113
let permit = WATCHER.acquire().await.unwrap();
109114
let (mut failed, mut succeeded) = (Vec::new(), HashMap::with_capacity(todo.len()));
110115
for (o, n) in todo {
111-
let (old, new): (Url, Url) = (
116+
let (old, new): (UrlBuf, UrlBuf) = (
112117
selected[o.0].components().take(root).chain([Component::Normal(&o)]).collect(),
113118
selected[n.0].components().take(root).chain([Component::Normal(&n)]).collect(),
114119
);
@@ -138,7 +143,7 @@ impl BulkRename {
138143
}
139144

140145
fn opener() -> Option<&'static OpenerRule> {
141-
YAZI.opener.block(YAZI.open.all(Url::from(Path::new("bulk-rename.txt")), "text/plain"))
146+
YAZI.opener.block(YAZI.open.all(UrlBuf::from(Path::new("bulk-rename.txt")), "text/plain"))
142147
}
143148

144149
async fn output_failed(failed: Vec<(Tuple, Tuple, anyhow::Error)>) -> Result<()> {

yazi-actor/src/mgr/cd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use yazi_fs::{File, FilesOp, path::expand_url};
99
use yazi_macro::{act, err, render, succ};
1010
use yazi_parser::mgr::CdOpt;
1111
use yazi_proxy::{CmpProxy, InputProxy, MgrProxy};
12-
use yazi_shared::{Debounce, errors::InputError, event::Data, url::Url};
12+
use yazi_shared::{Debounce, errors::InputError, event::Data, url::UrlBuf};
1313

1414
use crate::{Actor, Ctx};
1515

@@ -76,7 +76,7 @@ impl Cd {
7676
while let Some(result) = rx.next().await {
7777
match result {
7878
Ok(s) => {
79-
let Ok(url) = Url::try_from(s).map(expand_url) else { return };
79+
let Ok(url) = UrlBuf::try_from(s).map(expand_url) else { return };
8080

8181
let Ok(file) = File::new(url.clone()).await else { return };
8282
if file.is_dir() {

yazi-actor/src/mgr/create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use yazi_fs::{File, FilesOp, maybe_exists, ok_or_not_found, provider, realname};
44
use yazi_macro::succ;
55
use yazi_parser::mgr::CreateOpt;
66
use yazi_proxy::{ConfirmProxy, InputProxy, MgrProxy, WATCHER};
7-
use yazi_shared::{event::Data, url::{Url, UrnBuf}};
7+
use yazi_shared::{event::Data, url::{UrlBuf, UrnBuf}};
88

99
use crate::{Actor, Ctx};
1010

@@ -40,7 +40,7 @@ impl Actor for Create {
4040
}
4141

4242
impl Create {
43-
async fn r#do(new: Url, dir: bool) -> Result<()> {
43+
async fn r#do(new: UrlBuf, dir: bool) -> Result<()> {
4444
let Some(parent) = new.parent_url() else { return Ok(()) };
4545
let _permit = WATCHER.acquire().await.unwrap();
4646

yazi-actor/src/mgr/open.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use yazi_macro::{act, succ};
99
use yazi_parser::mgr::{OpenDoOpt, OpenOpt};
1010
use yazi_plugin::isolate;
1111
use yazi_proxy::{MgrProxy, PickProxy, TasksProxy};
12-
use yazi_shared::{MIME_DIR, event::{CmdCow, Data}, url::Url};
12+
use yazi_shared::{MIME_DIR, event::{CmdCow, Data}, url::UrlBuf};
1313

1414
use crate::{Actor, Ctx, mgr::Quit};
1515

@@ -110,7 +110,7 @@ impl Actor for OpenDo {
110110
}
111111

112112
impl Open {
113-
fn guess_folder(cx: &Ctx, url: &Url) -> bool {
113+
fn guess_folder(cx: &Ctx, url: &UrlBuf) -> bool {
114114
let Some(p) = url.parent_url() else {
115115
return true;
116116
};

yazi-actor/src/mgr/quit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use yazi_dds::spark::SparkKind;
88
use yazi_macro::{emit, succ};
99
use yazi_parser::mgr::{OpenOpt, QuitOpt};
1010
use yazi_proxy::ConfirmProxy;
11-
use yazi_shared::{event::{Data, EventQuit}, url::Url};
11+
use yazi_shared::{event::{Data, EventQuit}, url::UrlBuf};
1212

1313
use crate::{Actor, Ctx};
1414

@@ -69,7 +69,7 @@ impl Actor for Quit {
6969
impl Quit {
7070
pub(super) fn quit_with_selected<'a, I>(opt: OpenOpt, selected: I) -> bool
7171
where
72-
I: Iterator<Item = &'a Url>,
72+
I: Iterator<Item = &'a UrlBuf>,
7373
{
7474
if opt.interactive || ARGS.chooser_file.is_none() {
7575
return false;

yazi-actor/src/mgr/rename.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use yazi_fs::{File, FilesOp, maybe_exists, ok_or_not_found, paths_to_same_file,
55
use yazi_macro::{act, err, succ};
66
use yazi_parser::mgr::RenameOpt;
77
use yazi_proxy::{ConfirmProxy, InputProxy, MgrProxy, WATCHER};
8-
use yazi_shared::{Id, event::Data, url::{Url, UrnBuf}};
8+
use yazi_shared::{Id, event::Data, url::{UrlBuf, UrnBuf}};
99

1010
use crate::{Actor, Ctx};
1111

@@ -47,7 +47,7 @@ impl Actor for Rename {
4747
return;
4848
}
4949

50-
let new = Url::from(old.parent().unwrap().join(name));
50+
let new = UrlBuf::from(old.parent().unwrap().join(name));
5151
if opt.force || !maybe_exists(&new).await || paths_to_same_file(&old, &new).await {
5252
Self::r#do(tab, old, new).await.ok();
5353
} else if ConfirmProxy::show(ConfirmCfg::overwrite(&new)).await {
@@ -59,7 +59,7 @@ impl Actor for Rename {
5959
}
6060

6161
impl Rename {
62-
async fn r#do(tab: Id, old: Url, new: Url) -> Result<()> {
62+
async fn r#do(tab: Id, old: UrlBuf, new: UrlBuf) -> Result<()> {
6363
let Some((p_old, n_old)) = old.pair() else { return Ok(()) };
6464
let Some((p_new, n_new)) = new.pair() else { return Ok(()) };
6565
let _permit = WATCHER.acquire().await.unwrap();
@@ -85,7 +85,7 @@ impl Rename {
8585
Ok(())
8686
}
8787

88-
fn empty_url_part(url: &Url, by: &str) -> String {
88+
fn empty_url_part(url: &UrlBuf, by: &str) -> String {
8989
if by == "all" {
9090
return String::new();
9191
}

yazi-actor/src/mgr/yank.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Result;
22
use yazi_core::mgr::Yanked;
33
use yazi_macro::{act, render};
44
use yazi_parser::mgr::YankOpt;
5-
use yazi_shared::{event::Data, url::CovUrl};
5+
use yazi_shared::{event::Data, url::UrlCov};
66

77
use crate::{Actor, Ctx};
88

@@ -17,7 +17,7 @@ impl Actor for Yank {
1717
act!(mgr:escape_visual, cx)?;
1818

1919
cx.mgr.yanked =
20-
Yanked::new(opt.cut, cx.tab().selected_or_hovered().cloned().map(CovUrl).collect());
20+
Yanked::new(opt.cut, cx.tab().selected_or_hovered().cloned().map(UrlCov).collect());
2121
render!(cx.mgr.yanked.catchup_revision(true));
2222

2323
act!(mgr:escape_select, cx)

yazi-adapter/src/adapter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{env, fmt::Display};
33
use anyhow::Result;
44
use ratatui::layout::Rect;
55
use tracing::warn;
6-
use yazi_shared::{env_exists, url::Url};
6+
use yazi_shared::{env_exists, url::UrlBuf};
77

88
use crate::{Emulator, SHOWN, TMUX, drivers};
99

@@ -35,7 +35,7 @@ impl Display for Adapter {
3535
}
3636

3737
impl Adapter {
38-
pub async fn image_show(self, url: &Url, max: Rect) -> Result<Rect> {
38+
pub async fn image_show(self, url: &UrlBuf, max: Rect) -> Result<Rect> {
3939
if max.is_empty() {
4040
return Ok(Rect::default());
4141
}

0 commit comments

Comments
 (0)