rerstore firmatting diffs

This commit is contained in:
Ahmed Hassan 2025-07-30 06:28:55 +04:00
parent 518612857b
commit 83b46c8230
6 changed files with 69 additions and 147 deletions

View file

@ -6,10 +6,7 @@ use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream};
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_fs::{FilesOp, cha::Cha}; use yazi_fs::{FilesOp, cha::Cha};
use yazi_macro::{act, succ}; use yazi_macro::{act, succ};
use yazi_parser::{ use yazi_parser::{VoidOpt, mgr::{SearchOpt, SearchOptVia}};
VoidOpt,
mgr::{SearchOpt, SearchOptVia},
};
use yazi_plugin::external; use yazi_plugin::external;
use yazi_proxy::{InputProxy, MgrProxy}; use yazi_proxy::{InputProxy, MgrProxy};
use yazi_shared::event::Data; use yazi_shared::event::Data;

View file

@ -1,7 +1,4 @@
use std::{ use std::{fs::{FileType, Metadata}, time::SystemTime};
fs::{FileType, Metadata},
time::SystemTime,
};
use yazi_macro::{unix_either, win_either}; use yazi_macro::{unix_either, win_either};
use yazi_shared::url::Url; use yazi_shared::url::Url;
@ -132,10 +129,7 @@ impl Cha {
fn from_just_meta(m: &Metadata) -> Self { fn from_just_meta(m: &Metadata) -> Self {
#[cfg(unix)] #[cfg(unix)]
use std::{ use std::{os::unix::{fs::MetadataExt, prelude::PermissionsExt}, time::{Duration, UNIX_EPOCH}};
os::unix::{fs::MetadataExt, prelude::PermissionsExt},
time::{Duration, UNIX_EPOCH},
};
let mut kind = ChaKind::empty(); let mut kind = ChaKind::empty();
if m.is_dir() { if m.is_dir() {
@ -184,9 +178,7 @@ impl Cha {
impl Cha { impl Cha {
#[inline] #[inline]
pub const fn is_dir(&self) -> bool { pub const fn is_dir(&self) -> bool { self.kind.contains(ChaKind::DIR) }
self.kind.contains(ChaKind::DIR)
}
#[inline] #[inline]
pub const fn is_hidden(&self) -> bool { pub const fn is_hidden(&self) -> bool {
@ -197,19 +189,13 @@ impl Cha {
} }
#[inline] #[inline]
pub const fn is_link(&self) -> bool { pub const fn is_link(&self) -> bool { self.kind.contains(ChaKind::LINK) }
self.kind.contains(ChaKind::LINK)
}
#[inline] #[inline]
pub const fn is_orphan(&self) -> bool { pub const fn is_orphan(&self) -> bool { self.kind.contains(ChaKind::ORPHAN) }
self.kind.contains(ChaKind::ORPHAN)
}
#[inline] #[inline]
pub const fn is_dummy(&self) -> bool { pub const fn is_dummy(&self) -> bool { self.kind.contains(ChaKind::DUMMY) }
self.kind.contains(ChaKind::DUMMY)
}
#[inline] #[inline]
pub const fn is_block(&self) -> bool { pub const fn is_block(&self) -> bool {
@ -232,12 +218,8 @@ impl Cha {
} }
#[inline] #[inline]
pub const fn is_exec(&self) -> bool { pub const fn is_exec(&self) -> bool { unix_either!(self.mode & libc::S_IXUSR != 0, false) }
unix_either!(self.mode & libc::S_IXUSR != 0, false)
}
#[inline] #[inline]
pub const fn is_sticky(&self) -> bool { pub const fn is_sticky(&self) -> bool { unix_either!(self.mode & libc::S_ISVTX != 0, false) }
unix_either!(self.mode & libc::S_ISVTX != 0, false)
}
} }

View file

@ -36,9 +36,7 @@ impl TryFrom<CmdCow> for SearchOpt {
} }
impl IntoLua for &SearchOpt { impl IntoLua for &SearchOpt {
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
Err("unsupported".into_lua_err())
}
} }
// Via // Via

View file

@ -2,11 +2,7 @@ use std::path::Path;
use std::process::Stdio; use std::process::Stdio;
use anyhow::Result; use anyhow::Result;
use tokio::{ use tokio::{io::{AsyncBufReadExt, BufReader},process::{Child, Command},sync::mpsc::{self, UnboundedReceiver},};
io::{AsyncBufReadExt, BufReader},
process::{Child, Command},
sync::mpsc::{self, UnboundedReceiver},
};
use yazi_fs::File; use yazi_fs::File;
use yazi_shared::url::Url; use yazi_shared::url::Url;

View file

@ -1,20 +1,10 @@
use std::{ use std::{borrow::Cow, ffi::OsStr, fmt::{Debug, Formatter}, hash::BuildHasher, ops::Deref, path::{Path, PathBuf}};
borrow::Cow,
ffi::OsStr,
fmt::{Debug, Formatter},
hash::BuildHasher,
ops::Deref,
path::{Path, PathBuf},
};
use percent_encoding::percent_decode; use percent_encoding::percent_decode;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::UrnBuf; use super::UrnBuf;
use crate::{ use crate::{IntoOsStr, url::{Components, Display, Loc, Scheme}};
IntoOsStr,
url::{Components, Display, Loc, Scheme},
};
#[derive(Clone, Default, Eq, Ord, PartialOrd, PartialEq, Hash)] #[derive(Clone, Default, Eq, Ord, PartialOrd, PartialEq, Hash)]
pub struct Url { pub struct Url {
@ -25,33 +15,23 @@ pub struct Url {
impl Deref for Url { impl Deref for Url {
type Target = Loc; type Target = Loc;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target { &self.loc }
&self.loc
}
} }
impl From<Loc> for Url { impl From<Loc> for Url {
fn from(loc: Loc) -> Self { fn from(loc: Loc) -> Self { Self { loc, scheme: Scheme::Regular } }
Self { loc, scheme: Scheme::Regular }
}
} }
impl From<PathBuf> for Url { impl From<PathBuf> for Url {
fn from(path: PathBuf) -> Self { fn from(path: PathBuf) -> Self { Loc::from(path).into() }
Loc::from(path).into()
}
} }
impl From<&PathBuf> for Url { impl From<&PathBuf> for Url {
fn from(path: &PathBuf) -> Self { fn from(path: &PathBuf) -> Self { path.to_owned().into() }
path.to_owned().into()
}
} }
impl From<&Path> for Url { impl From<&Path> for Url {
fn from(path: &Path) -> Self { fn from(path: &Path) -> Self { path.to_path_buf().into() }
path.to_path_buf().into()
}
} }
impl TryFrom<&[u8]> for Url { impl TryFrom<&[u8]> for Url {
@ -73,48 +53,34 @@ impl TryFrom<&[u8]> for Url {
impl TryFrom<&str> for Url { impl TryFrom<&str> for Url {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(value: &str) -> Result<Self, Self::Error> { fn try_from(value: &str) -> Result<Self, Self::Error> { value.as_bytes().try_into() }
value.as_bytes().try_into()
}
} }
impl TryFrom<String> for Url { impl TryFrom<String> for Url {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(value: String) -> Result<Self, Self::Error> { fn try_from(value: String) -> Result<Self, Self::Error> { value.as_bytes().try_into() }
value.as_bytes().try_into()
}
} }
impl AsRef<Url> for Url { impl AsRef<Url> for Url {
fn as_ref(&self) -> &Url { fn as_ref(&self) -> &Url { self }
self
}
} }
// FIXME: remove // FIXME: remove
impl AsRef<Path> for Url { impl AsRef<Path> for Url {
fn as_ref(&self) -> &Path { fn as_ref(&self) -> &Path { &self.loc }
&self.loc
}
} }
impl<'a> From<&'a Url> for Cow<'a, Url> { impl<'a> From<&'a Url> for Cow<'a, Url> {
fn from(url: &'a Url) -> Self { fn from(url: &'a Url) -> Self { Cow::Borrowed(url) }
Cow::Borrowed(url)
}
} }
impl From<Url> for Cow<'_, Url> { impl From<Url> for Cow<'_, Url> {
fn from(url: Url) -> Self { fn from(url: Url) -> Self { Cow::Owned(url) }
Cow::Owned(url)
}
} }
impl From<Cow<'_, Url>> for Url { impl From<Cow<'_, Url>> for Url {
fn from(url: Cow<'_, Url>) -> Self { fn from(url: Cow<'_, Url>) -> Self { url.into_owned() }
url.into_owned()
}
} }
impl Url { impl Url {
@ -139,16 +105,16 @@ impl Url {
Scheme::SearchItem => { Scheme::SearchItem => {
Self { loc: Loc::with(self.loc.base(), self.loc.join(path)), scheme: Scheme::SearchItem } Self { loc: Loc::with(self.loc.base(), self.loc.join(path)), scheme: Scheme::SearchItem }
} }
Scheme::Archive(_) => Self { loc: self.loc.join(path).into(), scheme: self.scheme.clone() }, Scheme::Archive(_) => {
Self { loc: self.loc.join(path).into(), scheme: self.scheme.clone() }
}
Scheme::Sftp(_) => Self { loc: self.loc.join(path).into(), scheme: self.scheme.clone() }, Scheme::Sftp(_) => Self { loc: self.loc.join(path).into(), scheme: self.scheme.clone() },
} }
} }
// FIXME: check usages // FIXME: check usages
#[inline] #[inline]
pub fn components(&self) -> Components<'_> { pub fn components(&self) -> Components<'_> { Components::new(self) }
Components::new(self)
}
#[inline] #[inline]
pub fn covariant(&self, other: &Self) -> bool { pub fn covariant(&self, other: &Self) -> bool {
@ -156,14 +122,10 @@ impl Url {
} }
#[inline] #[inline]
pub fn display(&self) -> Display<'_> { pub fn display(&self) -> Display<'_> { Display::new(self) }
Display::new(self)
}
#[inline] #[inline]
pub fn os_str(&self) -> Cow<'_, OsStr> { pub fn os_str(&self) -> Cow<'_, OsStr> { self.components().os_str() }
self.components().os_str()
}
pub fn parent_url(&self) -> Option<Url> { pub fn parent_url(&self) -> Option<Url> {
let parent = self.loc.parent()?; let parent = self.loc.parent()?;
@ -189,7 +151,10 @@ impl Url {
return None; return None;
} }
Some(Self { loc: self.loc.strip_prefix(&base.loc).ok()?.into(), scheme: self.scheme.clone() }) Some(Self {
loc: self.loc.strip_prefix(&base.loc).ok()?.into(),
scheme: self.scheme.clone(),
})
} }
#[inline] #[inline]
@ -198,19 +163,13 @@ impl Url {
} }
#[inline] #[inline]
pub fn set_name(&mut self, name: impl AsRef<OsStr>) { pub fn set_name(&mut self, name: impl AsRef<OsStr>) { self.loc.set_name(name); }
self.loc.set_name(name);
}
#[inline] #[inline]
pub fn pair(&self) -> Option<(Self, UrnBuf)> { pub fn pair(&self) -> Option<(Self, UrnBuf)> { Some((self.parent_url()?, self.loc.urn_owned())) }
Some((self.parent_url()?, self.loc.urn_owned()))
}
#[inline] #[inline]
pub fn hash_u64(&self) -> u64 { pub fn hash_u64(&self) -> u64 { foldhash::fast::FixedState::default().hash_one(self) }
foldhash::fast::FixedState::default().hash_one(self)
}
#[inline] #[inline]
pub fn rebase(&self, parent: &Path) -> Self { pub fn rebase(&self, parent: &Path) -> Self {
@ -222,14 +181,10 @@ impl Url {
impl Url { impl Url {
// --- Regular // --- Regular
#[inline] #[inline]
pub fn is_regular(&self) -> bool { pub fn is_regular(&self) -> bool { self.scheme == Scheme::Regular }
self.scheme == Scheme::Regular
}
#[inline] #[inline]
pub fn to_regular(&self) -> Self { pub fn to_regular(&self) -> Self { Self { loc: self.loc.clone(), scheme: Scheme::Regular } }
Self { loc: self.loc.clone(), scheme: Scheme::Regular }
}
#[inline] #[inline]
pub fn into_regular(mut self) -> Self { pub fn into_regular(mut self) -> Self {
@ -239,9 +194,7 @@ impl Url {
// --- Search // --- Search
#[inline] #[inline]
pub fn is_search(&self) -> bool { pub fn is_search(&self) -> bool { matches!(self.scheme, Scheme::Search(_)) }
matches!(self.scheme, Scheme::Search(_))
}
#[inline] #[inline]
pub fn to_search(&self, frag: impl AsRef<str>) -> Self { pub fn to_search(&self, frag: impl AsRef<str>) -> Self {
@ -256,15 +209,11 @@ impl Url {
// --- Archive // --- Archive
#[inline] #[inline]
pub fn is_archive(&self) -> bool { pub fn is_archive(&self) -> bool { matches!(self.scheme, Scheme::Archive(_)) }
matches!(self.scheme, Scheme::Archive(_))
}
// FIXME: remove // FIXME: remove
#[inline] #[inline]
pub fn into_path(self) -> PathBuf { pub fn into_path(self) -> PathBuf { self.loc.into_path() }
self.loc.into_path()
}
} }
impl Debug for Url { impl Debug for Url {