mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
d7e2e1bc93
commit
05964eb26c
8 changed files with 37 additions and 20 deletions
|
|
@ -106,7 +106,7 @@ impl Executor {
|
|||
}
|
||||
}
|
||||
"remove" => {
|
||||
let targets = cx.manager.selected().into_iter().map(|f| f.path().clone()).collect();
|
||||
let targets = cx.manager.selected().into_iter().map(|f| f.path_owned()).collect();
|
||||
cx.tasks.file_remove(targets, exec.named.contains_key("permanently"))
|
||||
}
|
||||
"create" => cx.manager.create(),
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl<'a> Widget for Left<'a> {
|
|||
}
|
||||
|
||||
// Filename
|
||||
spans.push(Span::raw(format!(" {} ", h.name().unwrap())));
|
||||
spans.push(Span::raw(format!(" {} ", h.name_display().unwrap())));
|
||||
}
|
||||
|
||||
Paragraph::new(Line::from(spans)).render(area, buf);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{borrow::Cow, fs::Metadata, path::{Path, PathBuf}};
|
||||
use std::{borrow::Cow, ffi::OsStr, fs::Metadata, path::{Path, PathBuf}};
|
||||
|
||||
use anyhow::Result;
|
||||
use tokio::fs;
|
||||
|
|
@ -44,7 +44,24 @@ impl File {
|
|||
pub fn set_path(&mut self, path: PathBuf) { self.path = path; }
|
||||
|
||||
#[inline]
|
||||
pub fn name(&self) -> Option<Cow<str>> { self.path.file_name().map(|s| s.to_string_lossy()) }
|
||||
pub fn path_owned(&self) -> PathBuf { self.path.clone() }
|
||||
|
||||
#[inline]
|
||||
pub fn path_os_str(&self) -> &OsStr { self.path.as_os_str() }
|
||||
|
||||
#[inline]
|
||||
pub fn name(&self) -> Option<&OsStr> { self.path.file_name() }
|
||||
|
||||
#[inline]
|
||||
pub fn name_display(&self) -> Option<Cow<str>> {
|
||||
self.path.file_name().map(|s| s.to_string_lossy())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn stem(&self) -> Option<&OsStr> { self.path.file_stem() }
|
||||
|
||||
#[inline]
|
||||
pub fn parent(&self) -> Option<&Path> { self.path.parent() }
|
||||
|
||||
// --- Meta
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ impl Files {
|
|||
|
||||
match state {
|
||||
Some(true) => {
|
||||
self.selected = self.iter().map(|f| f.path().clone()).collect();
|
||||
self.selected = self.iter().map(|f| f.path_owned()).collect();
|
||||
}
|
||||
Some(false) => {
|
||||
self.selected.clear();
|
||||
|
|
@ -96,7 +96,7 @@ impl Files {
|
|||
if self.selected.contains(&item.path) {
|
||||
self.selected.remove(&item.path);
|
||||
} else {
|
||||
self.selected.insert(item.path().clone());
|
||||
self.selected.insert(item.path_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ impl Files {
|
|||
|
||||
pub fn select_index(&mut self, indices: &BTreeSet<usize>, state: Option<bool>) -> bool {
|
||||
let mut applied = false;
|
||||
let paths: Vec<_> = self.pick(indices).iter().map(|f| f.path().clone()).collect();
|
||||
let paths: Vec<_> = self.pick(indices).iter().map(|f| f.path_owned()).collect();
|
||||
|
||||
for path in paths {
|
||||
applied |= self.select(&path, state);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl Folder {
|
|||
self.cursor = self.cursor.min(len.saturating_sub(1));
|
||||
self.set_page(true);
|
||||
|
||||
if let Some(h) = self.hovered.as_ref().map(|h| h.path().clone()) {
|
||||
if let Some(h) = self.hovered.as_ref().map(|h| h.path_owned()) {
|
||||
self.hover(&h);
|
||||
}
|
||||
self.hovered = self.files.duplicate(self.cursor);
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl Manager {
|
|||
|
||||
pub fn yank(&mut self, cut: bool) -> bool {
|
||||
self.yanked.0 = cut;
|
||||
self.yanked.1 = self.selected().into_iter().map(|f| f.path().clone()).collect();
|
||||
self.yanked.1 = self.selected().into_iter().map(|f| f.path_owned()).collect();
|
||||
false
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ impl Manager {
|
|||
.into_iter()
|
||||
.map(|f| {
|
||||
(
|
||||
f.path().as_os_str().to_owned(),
|
||||
f.path_os_str().to_owned(),
|
||||
if f.is_dir() { Some(MIME_DIR.to_owned()) } else { self.mimetype.get(f.path()).cloned() },
|
||||
)
|
||||
})
|
||||
|
|
@ -197,7 +197,7 @@ impl Manager {
|
|||
return self.bulk_rename();
|
||||
}
|
||||
|
||||
let Some(hovered) = self.hovered().map(|h| h.path().clone()) else {
|
||||
let Some(hovered) = self.hovered().map(|h| h.path_owned()) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
@ -321,7 +321,7 @@ impl Manager {
|
|||
pub fn update_read(&mut self, op: FilesOp) -> bool {
|
||||
let path = op.path();
|
||||
let cwd = self.cwd().to_owned();
|
||||
let hovered = self.hovered().map(|h| h.path().clone());
|
||||
let hovered = self.hovered().map(|h| h.path_owned());
|
||||
|
||||
let mut b = if cwd == path && !self.current().in_search {
|
||||
self.current_mut().update(op)
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ impl Tab {
|
|||
if let Some(rep) = self.parent.take() {
|
||||
self.history.insert(rep.cwd.clone(), rep);
|
||||
}
|
||||
self.parent = Some(self.history_new(hovered.path().parent().unwrap()));
|
||||
self.parent = Some(self.history_new(hovered.parent().unwrap()));
|
||||
|
||||
emit!(Refresh);
|
||||
true
|
||||
|
|
@ -151,7 +151,7 @@ impl Tab {
|
|||
.current
|
||||
.hovered
|
||||
.as_ref()
|
||||
.and_then(|h| h.path().parent())
|
||||
.and_then(|h| h.parent())
|
||||
.and_then(|p| if p == self.current.cwd { None } else { Some(p) })
|
||||
.or_else(|| self.current.cwd.parent());
|
||||
|
||||
|
|
@ -209,10 +209,10 @@ impl Tab {
|
|||
let mut it = self.selected().into_iter().peekable();
|
||||
while let Some(f) = it.next() {
|
||||
s.push(match type_ {
|
||||
"path" => f.path().as_os_str(),
|
||||
"dirname" => f.path().parent().map_or(OsStr::new(""), |p| p.as_os_str()),
|
||||
"filename" => f.path().file_name().unwrap_or(OsStr::new("")),
|
||||
"name_without_ext" => f.path().file_stem().unwrap_or(OsStr::new("")),
|
||||
"path" => f.path_os_str(),
|
||||
"dirname" => f.parent().map_or(OsStr::new(""), |p| p.as_os_str()),
|
||||
"filename" => f.name().unwrap_or(OsStr::new("")),
|
||||
"name_without_ext" => f.stem().unwrap_or(OsStr::new("")),
|
||||
_ => return false,
|
||||
});
|
||||
if it.peek().is_some() {
|
||||
|
|
@ -288,7 +288,7 @@ impl Tab {
|
|||
let selected: Vec<_> = self
|
||||
.selected()
|
||||
.into_iter()
|
||||
.map(|f| (f.path().as_os_str().to_owned(), Default::default()))
|
||||
.map(|f| (f.path_os_str().to_owned(), Default::default()))
|
||||
.collect();
|
||||
|
||||
let mut exec = exec.to_owned();
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ impl Tasks {
|
|||
let targets: Vec<_> = targets
|
||||
.iter()
|
||||
.filter(|f| f.is_file() && !mimetype.contains_key(f.path()))
|
||||
.map(|f| f.path().clone())
|
||||
.map(|f| f.path_owned())
|
||||
.collect();
|
||||
|
||||
if !targets.is_empty() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue