From 0967a701f98c0387d2d7840c7bea3470721fce1d Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 28 Aug 2023 13:57:06 +0800 Subject: [PATCH] .. --- app/src/status/left.rs | 2 +- core/src/files/file.rs | 16 ++++++++++------ core/src/files/sorter.rs | 2 +- core/src/tasks/tasks.rs | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/status/left.rs b/app/src/status/left.rs index e9c34d78..9e036bf1 100644 --- a/app/src/status/left.rs +++ b/app/src/status/left.rs @@ -35,7 +35,7 @@ impl<'a> Widget for Left<'a> { if let Some(h) = &manager.hovered { // Length - if let Some(len) = h.length { + if let Some(len) = h.length() { spans.push(Span::styled(format!(" {} ", readable_size(len)), body.bg().fg(**primary))); spans.push(Span::styled(&separator.closing, body.fg())); } diff --git a/core/src/files/file.rs b/core/src/files/file.rs index 8107ee4d..e17a2563 100644 --- a/core/src/files/file.rs +++ b/core/src/files/file.rs @@ -5,12 +5,12 @@ use tokio::fs; #[derive(Clone, Debug)] pub struct File { - pub(super) path: PathBuf, - pub(super) meta: Metadata, - pub length: Option, - pub link_to: Option, - pub is_link: bool, - pub is_hidden: bool, + pub(super) path: PathBuf, + pub(super) meta: Metadata, + pub(super) length: Option, + pub link_to: Option, + pub is_link: bool, + pub is_hidden: bool, } impl File { @@ -55,4 +55,8 @@ impl File { #[inline] pub fn is_dir(&self) -> bool { self.meta.is_dir() } + + // --- Length + #[inline] + pub fn length(&self) -> Option { self.length } } diff --git a/core/src/files/sorter.rs b/core/src/files/sorter.rs index 268438de..2f4bc857 100644 --- a/core/src/files/sorter.rs +++ b/core/src/files/sorter.rs @@ -45,7 +45,7 @@ impl FilesSorter { }), SortBy::Natural => self.sort_naturally(items), SortBy::Size => items.sort_unstable_by(|a, b| { - self.cmp(a.length.unwrap_or(0), b.length.unwrap_or(0), self.promote(a, b)) + self.cmp(a.length().unwrap_or(0), b.length().unwrap_or(0), self.promote(a, b)) }), } true diff --git a/core/src/tasks/tasks.rs b/core/src/tasks/tasks.rs index 82a8af19..1cf688eb 100644 --- a/core/src/tasks/tasks.rs +++ b/core/src/tasks/tasks.rs @@ -217,7 +217,7 @@ impl Tasks { } let targets: Vec<_> = - targets.iter().filter(|f| f.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);