mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
c6eb52b457
commit
68c849066f
1 changed files with 21 additions and 34 deletions
|
|
@ -1,9 +1,4 @@
|
||||||
use std::{
|
use std::{cmp::Ordering, collections::BTreeMap, ops::{Deref, DerefMut}, path::{Path, PathBuf}};
|
||||||
cmp::Ordering,
|
|
||||||
collections::BTreeMap,
|
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use config::{manager::SortBy, MANAGER};
|
use config::{manager::SortBy, MANAGER};
|
||||||
|
|
@ -13,14 +8,18 @@ use tokio::fs;
|
||||||
use super::File;
|
use super::File;
|
||||||
|
|
||||||
pub struct Files {
|
pub struct Files {
|
||||||
items: IndexMap<PathBuf, File>,
|
items: IndexMap<PathBuf, File>,
|
||||||
pub sort: FilesSort,
|
pub sort: FilesSort,
|
||||||
pub show_hidden: bool,
|
pub show_hidden: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Files {
|
impl Default for Files {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { items: Default::default(), sort: Default::default(), show_hidden: MANAGER.show_hidden }
|
Self {
|
||||||
|
items: Default::default(),
|
||||||
|
sort: Default::default(),
|
||||||
|
show_hidden: MANAGER.show_hidden,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,21 +122,13 @@ impl Files {
|
||||||
if promote != Ordering::Equal {
|
if promote != Ordering::Equal {
|
||||||
promote
|
promote
|
||||||
} else {
|
} else {
|
||||||
if reverse {
|
if reverse { b.cmp(&a) } else { a.cmp(&b) }
|
||||||
b.cmp(&a)
|
|
||||||
} else {
|
|
||||||
a.cmp(&b)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn promote(a: &File, b: &File, dir_first: bool) -> Ordering {
|
fn promote(a: &File, b: &File, dir_first: bool) -> Ordering {
|
||||||
if dir_first {
|
if dir_first { b.meta.is_dir().cmp(&a.meta.is_dir()) } else { Ordering::Equal }
|
||||||
b.meta.is_dir().cmp(&a.meta.is_dir())
|
|
||||||
} else {
|
|
||||||
Ordering::Equal
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let reverse = self.sort.reverse;
|
let reverse = self.sort.reverse;
|
||||||
|
|
@ -172,27 +163,27 @@ impl Files {
|
||||||
impl Deref for Files {
|
impl Deref for Files {
|
||||||
type Target = IndexMap<PathBuf, File>;
|
type Target = IndexMap<PathBuf, File>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.items }
|
||||||
&self.items
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for Files {
|
impl DerefMut for Files {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items }
|
||||||
&mut self.items
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct FilesSort {
|
pub struct FilesSort {
|
||||||
pub by: SortBy,
|
pub by: SortBy,
|
||||||
pub reverse: bool,
|
pub reverse: bool,
|
||||||
pub dir_first: bool,
|
pub dir_first: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FilesSort {
|
impl Default for FilesSort {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { by: MANAGER.sort_by, reverse: MANAGER.sort_reverse, dir_first: MANAGER.sort_dir_first }
|
Self {
|
||||||
|
by: MANAGER.sort_by,
|
||||||
|
reverse: MANAGER.sort_reverse,
|
||||||
|
dir_first: MANAGER.sort_dir_first,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,12 +208,8 @@ impl FilesOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn read_empty(path: &Path) -> Self {
|
pub fn read_empty(path: &Path) -> Self { Self::Read(path.to_path_buf(), BTreeMap::new()) }
|
||||||
Self::Read(path.to_path_buf(), BTreeMap::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn search_empty(path: &Path) -> Self {
|
pub fn search_empty(path: &Path) -> Self { Self::Search(path.to_path_buf(), BTreeMap::new()) }
|
||||||
Self::Search(path.to_path_buf(), BTreeMap::new())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue