This commit is contained in:
sxyazi 2023-08-28 13:57:06 +08:00
parent ab27c7a069
commit 0967a701f9
No known key found for this signature in database
4 changed files with 13 additions and 9 deletions

View file

@ -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()));
}

View file

@ -5,12 +5,12 @@ use tokio::fs;
#[derive(Clone, Debug)]
pub struct File {
pub(super) path: PathBuf,
pub(super) meta: Metadata,
pub length: Option<u64>,
pub link_to: Option<PathBuf>,
pub is_link: bool,
pub is_hidden: bool,
pub(super) path: PathBuf,
pub(super) meta: Metadata,
pub(super) length: Option<u64>,
pub link_to: Option<PathBuf>,
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<u64> { self.length }
}

View file

@ -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

View file

@ -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);