mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
0feb025dcf
commit
ab27c7a069
7 changed files with 26 additions and 19 deletions
|
|
@ -36,7 +36,7 @@ impl<'a> Folder<'a> {
|
|||
THEME
|
||||
.filetypes
|
||||
.iter()
|
||||
.find(|x| x.matches(file.path(), mimetype.get(file.path()), file.meta.is_dir()))
|
||||
.find(|x| x.matches(file.path(), mimetype.get(file.path()), file.is_dir()))
|
||||
.map(|x| x.style.get())
|
||||
.unwrap_or_else(Style::new)
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ impl<'a> Widget for Folder<'a> {
|
|||
let icon = THEME
|
||||
.icons
|
||||
.iter()
|
||||
.find(|x| x.name.match_path(f.path(), Some(f.meta.is_dir())))
|
||||
.find(|x| x.name.match_path(f.path(), Some(f.is_dir())))
|
||||
.map(|x| x.display.as_ref())
|
||||
.unwrap_or("");
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ impl Widget for Right<'_> {
|
|||
#[cfg(not(target_os = "windows"))]
|
||||
if let Some(h) = &manager.hovered {
|
||||
use std::os::unix::prelude::PermissionsExt;
|
||||
spans.extend(self.permissions(&shared::file_mode(h.meta.permissions().mode())))
|
||||
spans.extend(self.permissions(&shared::file_mode(h.meta().permissions().mode())))
|
||||
}
|
||||
|
||||
// Position
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use tokio::fs;
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct File {
|
||||
pub(super) path: PathBuf,
|
||||
pub meta: Metadata,
|
||||
pub(super) meta: Metadata,
|
||||
pub length: Option<u64>,
|
||||
pub link_to: Option<PathBuf>,
|
||||
pub is_link: bool,
|
||||
|
|
@ -36,6 +36,7 @@ impl File {
|
|||
}
|
||||
|
||||
impl File {
|
||||
// --- Path
|
||||
#[inline]
|
||||
pub fn path(&self) -> &PathBuf { &self.path }
|
||||
|
||||
|
|
@ -44,4 +45,14 @@ impl File {
|
|||
|
||||
#[inline]
|
||||
pub fn name(&self) -> Option<Cow<str>> { self.path.file_name().map(|s| s.to_string_lossy()) }
|
||||
|
||||
// --- Meta
|
||||
#[inline]
|
||||
pub fn meta(&self) -> &Metadata { &self.meta }
|
||||
|
||||
#[inline]
|
||||
pub fn is_file(&self) -> bool { self.meta.is_file() }
|
||||
|
||||
#[inline]
|
||||
pub fn is_dir(&self) -> bool { self.meta.is_dir() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ impl FilesSorter {
|
|||
fn sort_naturally(&self, items: &mut Vec<File>) {
|
||||
let mut indices = Vec::with_capacity(items.len());
|
||||
let mut entities = Vec::with_capacity(items.len());
|
||||
for (i, file) in items.into_iter().enumerate() {
|
||||
for (i, file) in items.iter().enumerate() {
|
||||
indices.push(i);
|
||||
entities.push((file.path.to_string_lossy(), &*file));
|
||||
entities.push((file.path.to_string_lossy(), file));
|
||||
}
|
||||
|
||||
indices.sort_unstable_by(|&a, &b| {
|
||||
|
|
@ -85,6 +85,6 @@ impl FilesSorter {
|
|||
|
||||
#[inline]
|
||||
fn promote(&self, a: &File, b: &File) -> Ordering {
|
||||
if self.dir_first { b.meta.is_dir().cmp(&a.meta.is_dir()) } else { Ordering::Equal }
|
||||
if self.dir_first { b.is_dir().cmp(&a.is_dir()) } else { Ordering::Equal }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl Manager {
|
|||
for tab in self.tabs.iter() {
|
||||
to_watch.insert(&tab.current.cwd);
|
||||
if let Some(ref h) = tab.current.hovered {
|
||||
if h.meta.is_dir() {
|
||||
if h.is_dir() {
|
||||
to_watch.insert(h.path());
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ impl Manager {
|
|||
self.active_mut().preview_reset_image();
|
||||
}
|
||||
|
||||
let mime = if hovered.meta.is_dir() {
|
||||
let mime = if hovered.is_dir() {
|
||||
MIME_DIR.to_owned()
|
||||
} else if let Some(m) = self.mimetype.get(hovered.path()).cloned() {
|
||||
m
|
||||
|
|
@ -123,11 +123,7 @@ impl Manager {
|
|||
.map(|f| {
|
||||
(
|
||||
f.path().as_os_str().to_owned(),
|
||||
if f.meta.is_dir() {
|
||||
Some(MIME_DIR.to_owned())
|
||||
} else {
|
||||
self.mimetype.get(f.path()).cloned()
|
||||
},
|
||||
if f.is_dir() { Some(MIME_DIR.to_owned()) } else { self.mimetype.get(f.path()).cloned() },
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
|
@ -401,7 +397,7 @@ impl Manager {
|
|||
return b;
|
||||
};
|
||||
|
||||
if hovered.meta.is_dir() {
|
||||
if hovered.is_dir() {
|
||||
self.watcher.trigger_dirs(&[hovered.path()]);
|
||||
}
|
||||
b
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ impl Tab {
|
|||
};
|
||||
|
||||
let mut hovered = None;
|
||||
if !file.meta.is_dir() {
|
||||
if !file.is_dir() {
|
||||
hovered = Some(file);
|
||||
target = target.parent().unwrap().to_path_buf();
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ impl Tab {
|
|||
let Some(hovered) = self.current.hovered.clone() else {
|
||||
return false;
|
||||
};
|
||||
if !hovered.meta.is_dir() {
|
||||
if !hovered.is_dir() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ impl Tasks {
|
|||
}
|
||||
|
||||
let targets: Vec<_> =
|
||||
targets.iter().filter(|f| f.meta.is_dir() && f.length.is_none()).map(|f| f.path()).collect();
|
||||
targets.iter().filter(|f| f.is_dir() && f.length.is_none()).map(|f| f.path()).collect();
|
||||
|
||||
if !targets.is_empty() {
|
||||
self.scheduler.precache_size(targets);
|
||||
|
|
@ -230,7 +230,7 @@ impl Tasks {
|
|||
pub fn precache_mime(&self, targets: &[File], mimetype: &HashMap<PathBuf, String>) -> bool {
|
||||
let targets: Vec<_> = targets
|
||||
.iter()
|
||||
.filter(|f| f.meta.is_file() && !mimetype.contains_key(f.path()))
|
||||
.filter(|f| f.is_file() && !mimetype.contains_key(f.path()))
|
||||
.map(|f| f.path().clone())
|
||||
.collect();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue