Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df6a02c

Browse files
committed
Implements glob search mode
1 parent b23e134 commit df6a02c

19 files changed

Lines changed: 1037 additions & 339 deletions

Cargo.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ wild = "2.0.4"
4040
owo-colors = "3.5.0"
4141
human_format = "1.0.3"
4242
once_cell = "1.19"
43+
globset = "0.4.14"
4344

4445
[[bin]]
4546
name="dua"

src/interactive/app/common.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::interactive::path_of;
22
use dua::traverse::{EntryData, Tree, TreeIndex};
33
use itertools::Itertools;
44
use petgraph::Direction;
5-
use std::cmp::Ordering;
5+
use std::path::Path;
6+
use std::{cmp::Ordering, path::PathBuf};
67
use unicode_segmentation::UnicodeSegmentation;
78

89
#[derive(Default, Debug, Copy, Clone, PartialOrd, PartialEq, Eq)]
@@ -50,9 +51,21 @@ pub struct EntryDataBundle {
5051
pub data: EntryData,
5152
pub is_dir: bool,
5253
pub exists: bool,
54+
pub glob_name: Option<PathBuf>,
5355
}
5456

55-
pub fn sorted_entries(tree: &Tree, node_idx: TreeIndex, sorting: SortMode) -> Vec<EntryDataBundle> {
57+
impl EntryDataBundle {
58+
pub fn name(&self) -> &Path {
59+
self.glob_name.as_deref().unwrap_or(&self.data.name)
60+
}
61+
}
62+
63+
pub fn sorted_entries(
64+
tree: &Tree,
65+
node_idx: TreeIndex,
66+
sorting: SortMode,
67+
glob_root: Option<TreeIndex>,
68+
) -> Vec<EntryDataBundle> {
5669
use SortMode::*;
5770
fn cmp_count(l: &EntryDataBundle, r: &EntryDataBundle) -> Ordering {
5871
l.data
@@ -63,13 +76,18 @@ pub fn sorted_entries(tree: &Tree, node_idx: TreeIndex, sorting: SortMode) -> Ve
6376
tree.neighbors_directed(node_idx, Direction::Outgoing)
6477
.filter_map(|idx| {
6578
tree.node_weight(idx).map(|w| {
66-
let p = path_of(tree, idx);
79+
let mut use_glob_path = false;
80+
if let Some(glob_root) = glob_root {
81+
use_glob_path = node_idx == glob_root;
82+
}
83+
let p = path_of(tree, idx, glob_root);
6784
let pm = p.symlink_metadata();
6885
EntryDataBundle {
6986
index: idx,
7087
data: w.clone(),
7188
exists: pm.is_ok(),
7289
is_dir: pm.ok().map_or(false, |m| m.is_dir()),
90+
glob_name: if use_glob_path { Some(p) } else { None },
7391
}
7492
})
7593
})

0 commit comments

Comments
 (0)