use std::path::PathBuf;
use crate::entry::LoadedEntry;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum DisplayFilter {
FoldersOnly,
#[default]
FilesAndFolders,
AllIncludingHidden,
}
impl DisplayFilter {
pub fn admits(self, entry: &LoadedEntry) -> bool {
match self {
Self::FoldersOnly => entry.is_dir && !entry.is_hidden,
Self::FilesAndFolders => !entry.is_hidden,
Self::AllIncludingHidden => true,
}
}
}
pub const DEFAULT_PREFETCH_SKIP: &[&str] = &[
".git",
".hg",
".svn",
"node_modules",
"__pycache__",
".venv",
"venv",
"target",
"build",
"dist",
];
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TreeConfig {
pub root_path: PathBuf,
pub filter: DisplayFilter,
pub max_depth: Option<u32>,
pub prefetch_per_parent: u32,
pub prefetch_skip: Vec<String>,
}
impl TreeConfig {
pub fn new(root_path: impl Into<PathBuf>) -> Self {
Self {
root_path: root_path.into(),
filter: DisplayFilter::default(),
max_depth: None,
prefetch_per_parent: 0,
prefetch_skip: DEFAULT_PREFETCH_SKIP
.iter()
.map(|s| s.to_string())
.collect(),
}
}
}