Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow dirs-first flag to work regardless of order #67

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/render/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub enum SortType {

/// Sort entries by size largest to smallest, bottom to top
SizeRev,

/// Do not sort entries
None,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -56,6 +59,7 @@ impl SortType {
Self::Name => Some(Box::new(Self::name_comparator)),
Self::Size => Some(Box::new(Self::size_comparator)),
Self::SizeRev => Some(Box::new(Self::size_rev_comparator)),
Self::None => None,
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/render/tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::render::{context::Context, disk_usage::FileSize, order::Order};
use crate::render::{
context::Context,
disk_usage::FileSize,
order::{Order, SortType},
};
use crossbeam::channel::{self, Sender};
use error::Error;
use ignore::{WalkBuilder, WalkParallel, WalkState};
Expand Down Expand Up @@ -172,6 +176,10 @@ impl Tree {
if let Some(ordr) = ctx.sort().map(|s| Order::from((s, ctx.dirs_first()))) {
ordr.comparator()
.map(|func| current_node.sort_children(func));
} else if ctx.dirs_first() {
Order::from((SortType::None, true))
.comparator()
.map(|func| current_node.sort_children(func));
}
fawni marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down