mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Bring back the reverse flag
Following the large refactor on the previous commit, this commit fixes the reverse functionality. Depth detection moved into the tree building instead of being calculated when drawing the tree to screen
This commit is contained in:
+13
-15
@@ -5,10 +5,7 @@ extern crate walkdir;
|
||||
|
||||
use self::display::draw_it;
|
||||
use clap::{App, AppSettings, Arg};
|
||||
use utils::{
|
||||
compare_tuple_smallest_first, find_big_ones, get_dir_tree, simplify_dir_names, sort,
|
||||
trim_deep_ones, Node,
|
||||
};
|
||||
use utils::{find_big_ones, get_dir_tree, simplify_dir_names, sort, trim_deep_ones, Node};
|
||||
|
||||
mod display;
|
||||
mod utils;
|
||||
@@ -94,28 +91,24 @@ fn main() {
|
||||
let simplified_dirs = simplify_dir_names(target_dirs);
|
||||
let (permissions, nodes) = get_dir_tree(&simplified_dirs, use_apparent_size);
|
||||
let sorted_data = sort(nodes);
|
||||
let mut biggest_ones = {
|
||||
let biggest_ones = {
|
||||
match depth {
|
||||
None => find_big_ones(sorted_data, number_of_lines + simplified_dirs.len()),
|
||||
Some(d) => trim_deep_ones(sorted_data, d, &simplified_dirs),
|
||||
}
|
||||
};
|
||||
if options.is_present("reverse") {
|
||||
biggest_ones.sort_by(compare_tuple_smallest_first);
|
||||
}
|
||||
let tree = build_tree(&biggest_ones);
|
||||
let tree = build_tree(biggest_ones, depth);
|
||||
//println!("{:?}", tree);
|
||||
|
||||
draw_it(
|
||||
permissions,
|
||||
depth,
|
||||
use_full_path,
|
||||
options.is_present("reverse"),
|
||||
tree,
|
||||
);
|
||||
}
|
||||
|
||||
fn build_tree(biggest_ones: &Vec<(String, u64)>) -> Node {
|
||||
fn build_tree(biggest_ones: Vec<(String, u64)>, depth: Option<u64>) -> Node {
|
||||
let mut top_parent = Node {
|
||||
name: "".to_string(),
|
||||
size: 0,
|
||||
@@ -123,21 +116,26 @@ fn build_tree(biggest_ones: &Vec<(String, u64)>) -> Node {
|
||||
};
|
||||
|
||||
// assume sorted order
|
||||
for b in biggest_ones.clone() {
|
||||
for b in biggest_ones {
|
||||
let n = Node {
|
||||
name: b.0,
|
||||
size: b.1,
|
||||
children: vec![],
|
||||
};
|
||||
recursively_build_tree(&mut top_parent, n)
|
||||
recursively_build_tree(&mut top_parent, n, depth)
|
||||
}
|
||||
top_parent
|
||||
}
|
||||
|
||||
fn recursively_build_tree(parent_node: &mut Node, new_node: Node) {
|
||||
fn recursively_build_tree(parent_node: &mut Node, new_node: Node, depth: Option<u64>) {
|
||||
let new_depth = match depth {
|
||||
None => None,
|
||||
Some(0) => return,
|
||||
Some(d) => Some(d - 1),
|
||||
};
|
||||
for c in parent_node.children.iter_mut() {
|
||||
if new_node.name.starts_with(&c.name) {
|
||||
return recursively_build_tree(&mut *c, new_node);
|
||||
return recursively_build_tree(&mut *c, new_node, new_depth);
|
||||
}
|
||||
}
|
||||
let temp = Box::<Node>::new(new_node);
|
||||
|
||||
Reference in New Issue
Block a user