mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: hide specified files and dirs
This commit is contained in:
parent
abfbd1cd9f
commit
8dded0e54d
3 changed files with 32 additions and 3 deletions
|
|
@ -26,6 +26,7 @@ pub struct Mgr {
|
||||||
pub scrolloff: u8,
|
pub scrolloff: u8,
|
||||||
pub mouse_events: MouseEvents,
|
pub mouse_events: MouseEvents,
|
||||||
pub title_format: String,
|
pub title_format: String,
|
||||||
|
pub ignore_rule: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Mgr {
|
impl FromStr for Mgr {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use std::mem;
|
||||||
|
|
||||||
use yazi_config::{LAYOUT, MGR};
|
use yazi_config::{LAYOUT, MGR};
|
||||||
use yazi_dds::Pubsub;
|
use yazi_dds::Pubsub;
|
||||||
use yazi_fs::{File, Files, FilesOp, FolderStage, Step, cha::Cha};
|
use yazi_fs::{File, Files, FilesOp, FolderStage, Step, cha::Cha, Filter};
|
||||||
use yazi_proxy::MgrProxy;
|
use yazi_proxy::MgrProxy;
|
||||||
use yazi_shared::{Id, url::{Url, Urn, UrnBuf}};
|
use yazi_shared::{Id, url::{Url, Urn, UrnBuf}};
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ impl Default for Folder {
|
||||||
Self {
|
Self {
|
||||||
url: Default::default(),
|
url: Default::default(),
|
||||||
cha: Default::default(),
|
cha: Default::default(),
|
||||||
files: Files::new(MGR.show_hidden),
|
files: Files::new(MGR.show_hidden, Filter::new(MGR.ignore_rule.as_str(), yazi_fs::FilterCase::Smart).ok()),
|
||||||
stage: Default::default(),
|
stage: Default::default(),
|
||||||
offset: Default::default(),
|
offset: Default::default(),
|
||||||
cursor: Default::default(),
|
cursor: Default::default(),
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ pub struct Files {
|
||||||
|
|
||||||
sorter: FilesSorter,
|
sorter: FilesSorter,
|
||||||
filter: Option<Filter>,
|
filter: Option<Filter>,
|
||||||
|
ignore_filter: Option<Filter>,
|
||||||
show_hidden: bool,
|
show_hidden: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ impl Deref for Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Files {
|
impl Files {
|
||||||
pub fn new(show_hidden: bool) -> Self { Self { show_hidden, ..Default::default() } }
|
pub fn new(show_hidden: bool, ignore_filter: Option<Filter>) -> Self { Self { show_hidden, ignore_filter, ..Default::default() } }
|
||||||
|
|
||||||
pub async fn from_dir(dir: &Url) -> std::io::Result<UnboundedReceiver<File>> {
|
pub async fn from_dir(dir: &Url) -> std::io::Result<UnboundedReceiver<File>> {
|
||||||
let mut it = fs::read_dir(dir).await?;
|
let mut it = fs::read_dir(dir).await?;
|
||||||
|
|
@ -320,6 +321,13 @@ impl Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split_files(&self, files: impl IntoIterator<Item = File>) -> (Vec<File>, Vec<File>) {
|
fn split_files(&self, files: impl IntoIterator<Item = File>) -> (Vec<File>, Vec<File>) {
|
||||||
|
let mut files: Vec<File> = files.into_iter().collect();
|
||||||
|
if let Some(ignore_filter) = &self.ignore_filter {
|
||||||
|
files = files
|
||||||
|
.into_iter()
|
||||||
|
.filter(|f| !ignore_filter.matches(f.name()))
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
if let Some(filter) = &self.filter {
|
if let Some(filter) = &self.filter {
|
||||||
files
|
files
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -380,6 +388,26 @@ impl Files {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Ignore Filter
|
||||||
|
#[inline]
|
||||||
|
pub fn ignore_filter(&self) -> Option<&Filter> { self.ignore_filter.as_ref() }
|
||||||
|
|
||||||
|
pub fn set_ignore_filter(&mut self, filter: Option<Filter>) -> bool {
|
||||||
|
if self.ignore_filter == filter {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.ignore_filter = filter;
|
||||||
|
if self.ignore_filter.is_none() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let it = mem::take(&mut self.items).into_iter().chain(mem::take(&mut self.hidden));
|
||||||
|
(self.hidden, self.items) = self.split_files(it);
|
||||||
|
self.sorter.sort(&mut self.items, &self.sizes);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
// --- Show hidden
|
// --- Show hidden
|
||||||
pub fn set_show_hidden(&mut self, state: bool) {
|
pub fn set_show_hidden(&mut self, state: bool) {
|
||||||
if self.show_hidden == state {
|
if self.show_hidden == state {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue