mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
591f7e4b12
commit
04dc43440e
2 changed files with 15 additions and 11 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use anyhow::bail;
|
||||
|
||||
#[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
|
|
@ -21,3 +23,14 @@ impl TryFrom<&[u8]> for Scheme {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Scheme {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Scheme::Regular => write!(f, "regular"),
|
||||
Scheme::Search => write!(f, "search"),
|
||||
Scheme::SearchItem => write!(f, "search_item"),
|
||||
Scheme::Archive => write!(f, "archive"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,10 +89,6 @@ impl TryFrom<String> for Url {
|
|||
fn try_from(value: String) -> Result<Self, Self::Error> { value.as_bytes().try_into() }
|
||||
}
|
||||
|
||||
// impl From<&String> for Url {
|
||||
// fn from(path: &String) -> Self { path.as_str().into() }
|
||||
// }
|
||||
|
||||
impl AsRef<Url> for Url {
|
||||
fn as_ref(&self) -> &Url { self }
|
||||
}
|
||||
|
|
@ -111,14 +107,9 @@ impl Display for Url {
|
|||
return write!(f, "{}", self.loc.display());
|
||||
}
|
||||
|
||||
let scheme = match self.scheme {
|
||||
Scheme::Regular | Scheme::SearchItem => unreachable!(),
|
||||
Scheme::Search => "search://",
|
||||
Scheme::Archive => "archive://",
|
||||
};
|
||||
let path = percent_encode(self.loc.as_os_str().as_encoded_bytes(), ENCODE_SET);
|
||||
let loc = percent_encode(self.loc.as_os_str().as_encoded_bytes(), ENCODE_SET);
|
||||
write!(f, "{}://{loc}", self.scheme)?;
|
||||
|
||||
write!(f, "{scheme}{path}")?;
|
||||
if !self.frag.is_empty() {
|
||||
write!(f, "#{}", percent_encode(self.frag.as_encoded_bytes(), ENCODE_SET))?;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue