Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Canop committed Jan 31, 2024
2 parents 15a8b5a + 9822f51 commit 594d9a0
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 157 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### next
- new syntax for special paths - Fix #687, #669

### v1.32.0 - 2024-01-02
<a name="v1.32.0"></a>
- whith "modal" enabled, `initial_mode` setting lets you choose whether to start in `input` mode or `command` mode (default) - Fix #708
- with "modal" enabled, `initial_mode` setting lets you choose whether to start in `input` mode or `command` mode (default) - Fix #708

### v1.31.0 - 2023-12-30
<a name="v1.31.0"></a>
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "broot"
version = "1.32.0"
version = "1.32.1-dev"
authors = ["dystroy <[email protected]>"]
repository = "https://github.com/Canop/broot"
homepage = "https://dystroy.org/broot"
Expand Down Expand Up @@ -58,7 +58,7 @@ splitty = "1.0"
strict = "0.1.4"
syntect = { package = "syntect-no-panic", version = "4.6.1" } # see issue #485
tempfile = "3.2"
termimad = "0.26.1"
termimad = "0.27.0"
terminal-clipboard = { version = "0.4.1", optional = true }
terminal-light = "1.1.1"
toml = "0.8"
Expand Down
24 changes: 20 additions & 4 deletions resources/default-conf/conf.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,28 @@ show_selection_mark: true
# Special paths
# If some paths must be handled specially, uncomment (and change
# this section as per the examples)
# Setting "list":"never" on a dir prevents broot from looking at its
# children when searching, unless the dir is the selected root.
# Setting "sum":"never" on a dir prevents broot from looking at its
# children when computing the total size and count of files.
# Setting "show":"always" makes a file visible even if its name
# starts with a dot.
# Setting "list":"always" may be useful on a link to a directory
# (they're otherwise not entered by broot unless selected)
#
special_paths: {
"/media" : "no-enter" // comment it if desired
# "/media/slow-backup-disk" : no-enter
# "/home/dys/useless" : hide
# "/home/dys/my-link-I-want-to-explore" : enter
"/media" : {
list: "never"
sum: "never"
}
"~/.config": { "show": "always" }
"trav": {
show: always
list: "always",
sum: "never"
}
# "~/useless": { "show": "never" }
# "~/my-link-I-want-to-explore": { "list": "always" }
}

###############################################################
Expand Down
11 changes: 4 additions & 7 deletions src/app/app_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use {
errors::*,
file_sum,
icon::*,
path,
pattern::SearchModeMap,
path::SpecialPaths,
skin::ExtColorMap,
syntactic::SyntaxTheme,
tree::TreeOptions,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub struct AppContext {
pub verb_store: VerbStore,

/// the paths for which there's a special behavior to follow (comes from conf)
pub special_paths: Vec<path::SpecialPath>,
pub special_paths: SpecialPaths,

/// the map between search prefixes and the search mode to apply
pub search_modes: SearchModeMap,
Expand Down Expand Up @@ -130,11 +130,8 @@ impl AppContext {
};
let icons = config.icon_theme.as_ref()
.and_then(|itn| icon_plugin(itn));
let mut special_paths = config.special_paths
.iter()
.map(|(k, v)| path::SpecialPath::new(k.clone(), *v))
.collect();
path::add_defaults(&mut special_paths);
let mut special_paths: SpecialPaths = (&config.special_paths).try_into()?;
special_paths.add_defaults();
let search_modes = config
.search_modes
.as_ref()
Expand Down
5 changes: 2 additions & 3 deletions src/conf/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use {
display::ColsConf,
errors::{ConfError, ProgramError},
path::{
Glob,
SpecialHandling,
path_from,
PathAnchor,
},
Expand All @@ -21,6 +19,7 @@ use {
crokey::crossterm::style::Attribute,
fnv::FnvHashMap,
serde::Deserialize,
std::collections::HashMap,
std::path::PathBuf,
};

Expand Down Expand Up @@ -59,7 +58,7 @@ pub struct Conf {
pub skin: Option<AHashMap<String, SkinEntry>>,

#[serde(default, alias="special-paths")]
pub special_paths: AHashMap<Glob, SpecialHandling>,
pub special_paths: HashMap<GlobConf, SpecialHandlingConf>,

#[serde(alias="search-modes")]
pub search_modes: Option<FnvHashMap<String, String>>,
Expand Down
2 changes: 2 additions & 0 deletions src/conf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod default_flags;
mod format;
pub mod file_size;
mod import;
mod special_handling_conf;
mod verb_conf;

pub use {
Expand All @@ -19,6 +20,7 @@ pub use {
default_flags::*,
format::*,
import::*,
special_handling_conf::*,
verb_conf::VerbConf,
};

Expand Down
101 changes: 101 additions & 0 deletions src/conf/special_handling_conf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use {
crate::{
errors::ConfError,
path::*,
},
directories::UserDirs,
lazy_regex::*,
serde::Deserialize,
std::collections::HashMap,
};


type SpecialPathsConf = HashMap<GlobConf, SpecialHandlingConf>;

#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Eq)]
#[serde(transparent)]
pub struct GlobConf {
pub pattern: String,
}

#[derive(Clone, Copy, Debug, Deserialize)]
#[serde(untagged)]
pub enum SpecialHandlingConf {
Shortcut(SpecialHandlingShortcut),
Detailed(SpecialHandling),
}

#[derive(Clone, Debug, Copy, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum SpecialHandlingShortcut {
None,
Enter,
#[serde(alias = "no-enter")]
NoEnter,
Hide,
#[serde(alias = "no-hide")]
NoHide,
}

impl From<SpecialHandlingShortcut> for SpecialHandling {
fn from(shortcut: SpecialHandlingShortcut) -> Self {
use Directive::*;
match shortcut {
SpecialHandlingShortcut::None => SpecialHandling {
show: Default, list: Default, sum: Default,
},
SpecialHandlingShortcut::Enter => SpecialHandling {
show: Always, list: Always, sum: Always,
},
SpecialHandlingShortcut::NoEnter => SpecialHandling {
show: Default, list: Never, sum: Never,
},
SpecialHandlingShortcut::Hide => SpecialHandling {
show: Never, list: Default, sum: Never,
},
SpecialHandlingShortcut::NoHide => SpecialHandling {
show: Always, list: Default, sum: Default,
},
}
}
}

impl From<SpecialHandlingConf> for SpecialHandling {
fn from(conf: SpecialHandlingConf) -> Self {
match conf {
SpecialHandlingConf::Shortcut(shortcut) => shortcut.into(),
SpecialHandlingConf::Detailed(handling) => handling,
}
}
}

impl TryFrom<&SpecialPathsConf> for SpecialPaths {
type Error = ConfError;
fn try_from(map: &SpecialPathsConf) -> Result<Self, ConfError> {
let mut entries = Vec::new();
for (k, v) in map {
entries.push(SpecialPath::new(k.to_glob()?, (*v).into()));
}
Ok(Self { entries })
}
}

impl GlobConf {
pub fn to_glob(&self) -> Result<glob::Pattern, ConfError> {
let s = regex_replace!(r"^~(/|$)", &self.pattern, |_, sep| {
match UserDirs::new() {
Some(dirs) => format!("{}{}", dirs.home_dir().to_string_lossy(), sep),
None => "~/".to_string(),
}
});
let glob = if s.starts_with('/') || s.starts_with('~') {
glob::Pattern::new(&s)
} else {
let pattern = format!("**/{}", &s);
glob::Pattern::new(&pattern)
};
glob.map_err(|_| ConfError::InvalidGlobPattern {
pattern: self.pattern.to_string(),
})
}
}
1 change: 1 addition & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ custom_error! {pub ConfError
InvalidThreadsCount { count: usize } = "invalid threads count: {count}",
InvalidDefaultFlags { flags: String } = "invalid default flags: {flags:?}",
InvalidSyntaxTheme { name: String } = "invalid syntax theme: {name:?}",
InvalidGlobPattern { pattern: String } = "invalid glob pattern: {pattern:?}",
}

// error which can be raised when parsing a pattern the user typed
Expand Down
19 changes: 4 additions & 15 deletions src/file_sum/sum_computation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ struct NodeId {
dev: u64,
}

#[inline(always)]
fn is_ignored(path: &Path, special_paths: &[SpecialPath]) -> bool {
match special_paths.find(path) {
SpecialHandling::NoEnter | SpecialHandling::Hide => true,
SpecialHandling::None | SpecialHandling::Enter | SpecialHandling::NoHide => false,
}
}

impl DirSummer {
pub fn new(thread_count: usize) -> Self {
let thread_pool = ThreadPoolBuilder::new()
Expand All @@ -75,7 +67,7 @@ impl DirSummer {
) -> Option<FileSum> {
let threads_count = self.thread_count;

if is_ignored(path, &con.special_paths) {
if con.special_paths.sum(path) == Directive::Never {
return Some(FileSum::zero());
}

Expand All @@ -102,10 +94,7 @@ impl DirSummer {
// A None means there's nothing left and the thread may send its result and stop
let (dirs_sender, dirs_receiver) = channel::unbounded();

let special_paths: Vec<SpecialPath> = con.special_paths.iter()
.filter(|sp| sp.can_have_matches_in(path))
.cloned()
.collect();
let special_paths = con.special_paths.reduce(path);

// the first level is managed a little differently: we look at the cache
// before adding. This enables faster computations in two cases:
Expand All @@ -117,7 +106,7 @@ impl DirSummer {
if md.is_dir() {
let entry_path = e.path();

if is_ignored(&entry_path, &special_paths) {
if con.special_paths.sum(&entry_path) == Directive::Never {
debug!("not summing special path {:?}", entry_path);
continue;
}
Expand Down Expand Up @@ -188,7 +177,7 @@ impl DirSummer {

let path = e.path();

if is_ignored(&path, &special_paths) {
if special_paths.sum(&path) == Directive::Never {
debug!("not summing (deep) special path {:?}", path);
continue;
}
Expand Down
Loading

0 comments on commit 594d9a0

Please sign in to comment.