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

Skip to content

Commit 1c4d6a7

Browse files
committed
Merge branch 'glob-review'
2 parents b23e134 + 2e1858c commit 1c4d6a7

20 files changed

Lines changed: 1226 additions & 401 deletions

Cargo.lock

Lines changed: 117 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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ default = ["tui-crossplatform", "trash-move"]
1414
tui-unix = ["crosstermion/tui-react-termion", "tui-shared"]
1515
tui-crossplatform = ["crosstermion/tui-react-crossterm", "tui-shared"]
1616

17-
tui-shared = ["tui", "tui-react", "open", "unicode-segmentation"]
17+
tui-shared = ["tui", "tui-react", "open", "unicode-segmentation", "unicode-width"]
1818
trash-move = ["trash"]
1919

2020
[dependencies]
@@ -32,6 +32,7 @@ chrono = { version = "0.4.31", default-features = false, features = ["std"] }
3232

3333
# 'tui' related
3434
unicode-segmentation = { version = "1.3.0", optional = true }
35+
unicode-width = { version = "0.1.5", optional = true }
3536
crosstermion = { version = "0.12.0", default-features = false, optional = true }
3637
tui = { package = "ratatui", version = "0.24.0", optional = true, default-features = false }
3738
tui-react = { version = "0.21.0", optional = true }
@@ -40,6 +41,9 @@ wild = "2.0.4"
4041
owo-colors = "3.5.0"
4142
human_format = "1.0.3"
4243
once_cell = "1.19"
44+
gix-glob = "0.14.1"
45+
gix-path = "0.10.1"
46+
bstr = "1.8.0"
4347

4448
[[bin]]
4549
name="dua"
@@ -53,7 +57,7 @@ panic = 'abort'
5357
incremental = false
5458
overflow-checks = false
5559
lto = "fat"
56-
codegen-units = 1
60+
#codegen-units = 1
5761
build-override = { opt-level = 3 }
5862

5963
[dev-dependencies]

src/interactive/app/common.rs

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::interactive::path_of;
2-
use dua::traverse::{EntryData, Tree, TreeIndex};
2+
use dua::traverse::{Tree, TreeIndex};
33
use itertools::Itertools;
44
use petgraph::Direction;
5-
use std::cmp::Ordering;
5+
use std::time::SystemTime;
6+
use std::{cmp::Ordering, path::PathBuf};
67
use unicode_segmentation::UnicodeSegmentation;
78

89
#[derive(Default, Debug, Copy, Clone, PartialOrd, PartialEq, Eq)]
@@ -47,37 +48,61 @@ impl SortMode {
4748

4849
pub struct EntryDataBundle {
4950
pub index: TreeIndex,
50-
pub data: EntryData,
51+
pub name: PathBuf,
52+
pub size: u128,
53+
pub mtime: SystemTime,
54+
pub entry_count: Option<u64>,
5155
pub is_dir: bool,
5256
pub exists: bool,
5357
}
5458

55-
pub fn sorted_entries(tree: &Tree, node_idx: TreeIndex, sorting: SortMode) -> Vec<EntryDataBundle> {
59+
/// Note that with `glob_root` present, we will not obtain metadata anymore as we might be seeing
60+
/// a lot of entries. That way, displaying 250k entries is no problem.
61+
pub fn sorted_entries(
62+
tree: &Tree,
63+
node_idx: TreeIndex,
64+
sorting: SortMode,
65+
glob_root: Option<TreeIndex>,
66+
) -> Vec<EntryDataBundle> {
5667
use SortMode::*;
5768
fn cmp_count(l: &EntryDataBundle, r: &EntryDataBundle) -> Ordering {
58-
l.data
59-
.entry_count
60-
.cmp(&r.data.entry_count)
61-
.then_with(|| l.data.name.cmp(&r.data.name))
69+
l.entry_count
70+
.cmp(&r.entry_count)
71+
.then_with(|| l.name.cmp(&r.name))
6272
}
6373
tree.neighbors_directed(node_idx, Direction::Outgoing)
6474
.filter_map(|idx| {
65-
tree.node_weight(idx).map(|w| {
66-
let p = path_of(tree, idx);
67-
let pm = p.symlink_metadata();
75+
tree.node_weight(idx).map(|entry| {
76+
let use_glob_path = glob_root.map_or(false, |glob_root| glob_root == node_idx);
77+
let (path, exists, is_dir) = {
78+
let path = path_of(tree, idx, glob_root);
79+
if glob_root.is_some() {
80+
(path, true, entry.is_dir)
81+
} else {
82+
let meta = path.symlink_metadata();
83+
(path, meta.is_ok(), meta.ok().map_or(false, |m| m.is_dir()))
84+
}
85+
};
6886
EntryDataBundle {
6987
index: idx,
70-
data: w.clone(),
71-
exists: pm.is_ok(),
72-
is_dir: pm.ok().map_or(false, |m| m.is_dir()),
88+
name: if use_glob_path {
89+
path
90+
} else {
91+
entry.name.clone()
92+
},
93+
size: entry.size,
94+
mtime: entry.mtime,
95+
entry_count: entry.entry_count,
96+
exists,
97+
is_dir,
7398
}
7499
})
75100
})
76101
.sorted_by(|l, r| match sorting {
77-
SizeDescending => r.data.size.cmp(&l.data.size),
78-
SizeAscending => l.data.size.cmp(&r.data.size),
79-
MTimeAscending => l.data.mtime.cmp(&r.data.mtime),
80-
MTimeDescending => r.data.mtime.cmp(&l.data.mtime),
102+
SizeDescending => r.size.cmp(&l.size),
103+
SizeAscending => l.size.cmp(&r.size),
104+
MTimeAscending => l.mtime.cmp(&r.mtime),
105+
MTimeDescending => r.mtime.cmp(&l.mtime),
81106
CountAscending => cmp_count(l, r),
82107
CountDescending => cmp_count(l, r).reverse(),
83108
})

0 commit comments

Comments
 (0)