mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Format files
Signed-off-by: Xuanwo <github@xuanwo.io>
This commit is contained in:
parent
447326214e
commit
cfe35cc691
5 changed files with 47 additions and 108 deletions
|
|
@ -19,13 +19,14 @@ pub mod theme;
|
||||||
mod validation;
|
mod validation;
|
||||||
pub mod which;
|
pub mod which;
|
||||||
|
|
||||||
use crate::schemes::Schemes;
|
|
||||||
pub use layout::*;
|
pub use layout::*;
|
||||||
pub(crate) use pattern::*;
|
pub(crate) use pattern::*;
|
||||||
pub(crate) use preset::*;
|
pub(crate) use preset::*;
|
||||||
pub use priority::*;
|
pub use priority::*;
|
||||||
use yazi_shared::fs::SCHEMES;
|
use yazi_shared::fs::SCHEMES;
|
||||||
|
|
||||||
|
use crate::schemes::Schemes;
|
||||||
|
|
||||||
static MERGED_YAZI: RoCell<String> = RoCell::new();
|
static MERGED_YAZI: RoCell<String> = RoCell::new();
|
||||||
static MERGED_KEYMAP: RoCell<String> = RoCell::new();
|
static MERGED_KEYMAP: RoCell<String> = RoCell::new();
|
||||||
static MERGED_THEME: RoCell<String> = RoCell::new();
|
static MERGED_THEME: RoCell<String> = RoCell::new();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::MERGED_YAZI;
|
use crate::MERGED_YAZI;
|
||||||
|
|
||||||
|
|
@ -11,9 +12,7 @@ pub struct Schemes {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Schemes {
|
impl Default for Schemes {
|
||||||
fn default() -> Self {
|
fn default() -> Self { toml::from_str(&MERGED_YAZI).unwrap() }
|
||||||
toml::from_str(&MERGED_YAZI).unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Schemes {
|
impl Schemes {
|
||||||
|
|
@ -47,8 +46,8 @@ impl<'de> Deserialize<'de> for Schemes {
|
||||||
/// Scheme in configuration file.
|
/// Scheme in configuration file.
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Scheme {
|
pub struct Scheme {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub typ: String,
|
pub typ: String,
|
||||||
pub config: HashMap<String, String>,
|
pub config: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,23 @@
|
||||||
use std::ops::Add;
|
use std::{cell::Cell, ffi::OsStr, fs::Metadata, ops::{Add, Deref}, time::{Duration, SystemTime}};
|
||||||
use std::time::{Duration, SystemTime};
|
|
||||||
use std::{cell::Cell, ffi::OsStr, fs::Metadata, ops::Deref};
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
use crate::fs::SCHEMES;
|
use crate::{fs::{Cha, ChaKind, Url, SCHEMES}, theme::IconCache};
|
||||||
use crate::{
|
|
||||||
fs::{Cha, ChaKind, Url},
|
|
||||||
theme::IconCache,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub url: Url,
|
pub url: Url,
|
||||||
pub cha: Cha,
|
pub cha: Cha,
|
||||||
pub link_to: Option<Url>,
|
pub link_to: Option<Url>,
|
||||||
pub icon: Cell<IconCache>,
|
pub icon: Cell<IconCache>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for File {
|
impl Deref for File {
|
||||||
type Target = Cha;
|
type Target = Cha;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.cha }
|
||||||
&self.cha
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
|
|
@ -102,30 +94,20 @@ impl File {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_dummy(url: &Url) -> Self {
|
pub fn from_dummy(url: &Url) -> Self { Self { url: url.to_owned(), ..Default::default() } }
|
||||||
Self { url: url.to_owned(), ..Default::default() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
// --- Url
|
// --- Url
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn url(&self) -> Url {
|
pub fn url(&self) -> Url { self.url.clone() }
|
||||||
self.url.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn name(&self) -> Option<&OsStr> {
|
pub fn name(&self) -> Option<&OsStr> { self.url.file_name() }
|
||||||
self.url.file_name()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn stem(&self) -> Option<&OsStr> {
|
pub fn stem(&self) -> Option<&OsStr> { self.url.file_stem() }
|
||||||
self.url.file_stem()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parent(&self) -> Option<Url> {
|
pub fn parent(&self) -> Option<Url> { self.url.parent_url() }
|
||||||
self.url.parent_url()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::RoCell;
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use opendal::Operator;
|
use opendal::Operator;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::str::FromStr;
|
use crate::RoCell;
|
||||||
|
|
||||||
/// SCHEMES is the read only cell of schemes that already loaded.
|
/// SCHEMES is the read only cell of schemes that already loaded.
|
||||||
pub static SCHEMES: RoCell<Schemes> = RoCell::new();
|
pub static SCHEMES: RoCell<Schemes> = RoCell::new();
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,4 @@
|
||||||
use std::{
|
use std::{ffi::{OsStr, OsString}, fmt::{Debug, Display, Formatter}, ops::{Deref, DerefMut}, path::{Path, PathBuf}};
|
||||||
ffi::{OsStr, OsString},
|
|
||||||
fmt::{Debug, Display, Formatter},
|
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
use percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS};
|
use percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -13,8 +8,8 @@ const ENCODE_SET: &AsciiSet = &CONTROLS.add(b'#');
|
||||||
#[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct Url {
|
pub struct Url {
|
||||||
scheme: UrlScheme,
|
scheme: UrlScheme,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
frag: String,
|
frag: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
|
|
@ -29,51 +24,35 @@ pub enum UrlScheme {
|
||||||
impl Deref for Url {
|
impl Deref for Url {
|
||||||
type Target = PathBuf;
|
type Target = PathBuf;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.path }
|
||||||
&self.path
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for Url {
|
impl DerefMut for Url {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.path }
|
||||||
&mut self.path
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Url {
|
impl Debug for Url {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.path.display()) }
|
||||||
write!(f, "{}", self.path.display())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<PathBuf> for Url {
|
impl From<PathBuf> for Url {
|
||||||
fn from(path: PathBuf) -> Self {
|
fn from(path: PathBuf) -> Self { Self { path, ..Default::default() } }
|
||||||
Self { path, ..Default::default() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&PathBuf> for Url {
|
impl From<&PathBuf> for Url {
|
||||||
fn from(path: &PathBuf) -> Self {
|
fn from(path: &PathBuf) -> Self { Self::from(path.clone()) }
|
||||||
Self::from(path.clone())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Path> for Url {
|
impl From<&Path> for Url {
|
||||||
fn from(path: &Path) -> Self {
|
fn from(path: &Path) -> Self { Self::from(path.to_path_buf()) }
|
||||||
Self::from(path.to_path_buf())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Url {
|
impl From<String> for Url {
|
||||||
fn from(path: String) -> Self {
|
fn from(path: String) -> Self { Self::from(path.as_str()) }
|
||||||
Self::from(path.as_str())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&String> for Url {
|
impl From<&String> for Url {
|
||||||
fn from(path: &String) -> Self {
|
fn from(path: &String) -> Self { Self::from(path.as_str()) }
|
||||||
Self::from(path.as_str())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&str> for Url {
|
impl From<&str> for Url {
|
||||||
|
|
@ -107,21 +86,15 @@ impl From<&str> for Url {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<Url> for Url {
|
impl AsRef<Url> for Url {
|
||||||
fn as_ref(&self) -> &Url {
|
fn as_ref(&self) -> &Url { self }
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<Path> for Url {
|
impl AsRef<Path> for Url {
|
||||||
fn as_ref(&self) -> &Path {
|
fn as_ref(&self) -> &Path { &self.path }
|
||||||
&self.path
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<OsStr> for Url {
|
impl AsRef<OsStr> for Url {
|
||||||
fn as_ref(&self) -> &OsStr {
|
fn as_ref(&self) -> &OsStr { self.path.as_os_str() }
|
||||||
self.path.as_os_str()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Url {
|
impl Display for Url {
|
||||||
|
|
@ -175,9 +148,7 @@ impl Url {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_os_string(self) -> OsString {
|
pub fn into_os_string(self) -> OsString { self.path.into_os_string() }
|
||||||
self.path.into_os_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -189,14 +160,10 @@ impl Url {
|
||||||
impl Url {
|
impl Url {
|
||||||
// --- Scheme
|
// --- Scheme
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_regular(&self) -> bool {
|
pub fn is_regular(&self) -> bool { self.scheme == UrlScheme::Regular }
|
||||||
self.scheme == UrlScheme::Regular
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_regular(&self) -> Self {
|
pub fn to_regular(&self) -> Self { self.clone().into_regular() }
|
||||||
self.clone().into_regular()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_regular(mut self) -> Self {
|
pub fn into_regular(mut self) -> Self {
|
||||||
|
|
@ -205,14 +172,10 @@ impl Url {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_search(&self) -> bool {
|
pub fn is_search(&self) -> bool { self.scheme == UrlScheme::Search }
|
||||||
self.scheme == UrlScheme::Search
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_search(&self, frag: String) -> Self {
|
pub fn to_search(&self, frag: String) -> Self { self.clone().into_search(frag) }
|
||||||
self.clone().into_search(frag)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_search(mut self, frag: String) -> Self {
|
pub fn into_search(mut self, frag: String) -> Self {
|
||||||
|
|
@ -222,14 +185,10 @@ impl Url {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_archive(&self) -> bool {
|
pub fn is_archive(&self) -> bool { self.scheme == UrlScheme::Archive }
|
||||||
self.scheme == UrlScheme::Archive
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_archive(&self) -> Self {
|
pub fn to_archive(&self) -> Self { self.clone().into_archive() }
|
||||||
self.clone().into_archive()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_archive(mut self) -> Self {
|
pub fn into_archive(mut self) -> Self {
|
||||||
|
|
@ -239,7 +198,8 @@ impl Url {
|
||||||
|
|
||||||
/// Check and fetch remote scheme.
|
/// Check and fetch remote scheme.
|
||||||
///
|
///
|
||||||
/// Returns None if current url is not remote, otherwise returns `Some(scheme)`
|
/// Returns None if current url is not remote, otherwise returns
|
||||||
|
/// `Some(scheme)`
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_remote(&self) -> Option<&str> {
|
pub fn is_remote(&self) -> Option<&str> {
|
||||||
match &self.scheme {
|
match &self.scheme {
|
||||||
|
|
@ -250,15 +210,11 @@ impl Url {
|
||||||
|
|
||||||
// --- Path
|
// --- Path
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_path(&mut self, path: PathBuf) {
|
pub fn set_path(&mut self, path: PathBuf) { self.path = path; }
|
||||||
self.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Frag
|
// --- Frag
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn frag(&self) -> &str {
|
pub fn frag(&self) -> &str { &self.frag }
|
||||||
&self.frag
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&str> for UrlScheme {
|
impl From<&str> for UrlScheme {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue