mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Run format, introduce new function.
strip_end_slash_including_root will remove end slashes including the root directory. The root directory has been a long running problem because if we strip the final slash we will run dust on no directory instead of the root.
This commit is contained in:
+23
-14
@@ -3,7 +3,7 @@ extern crate ansi_term;
|
||||
use self::ansi_term::Colour::Fixed;
|
||||
use self::ansi_term::Style;
|
||||
use std::collections::HashSet;
|
||||
use utils::{ensure_end_slash, strip_end_slash};
|
||||
use utils::{ensure_end_slash, strip_end_slash_including_root};
|
||||
|
||||
static UNITS: [char; 4] = ['T', 'G', 'M', 'K'];
|
||||
|
||||
@@ -58,8 +58,21 @@ fn display_node(
|
||||
match get_size(to_display, node_to_print) {
|
||||
None => println!("Can not find path: {}", node_to_print),
|
||||
Some(size) => {
|
||||
print_this_node(node_to_print, size, is_biggest, short_paths, indentation_str);
|
||||
fan_out(node_to_print, found, to_display, short_paths, new_depth, indentation_str);
|
||||
print_this_node(
|
||||
node_to_print,
|
||||
size,
|
||||
is_biggest,
|
||||
short_paths,
|
||||
indentation_str,
|
||||
);
|
||||
fan_out(
|
||||
node_to_print,
|
||||
found,
|
||||
to_display,
|
||||
short_paths,
|
||||
new_depth,
|
||||
indentation_str,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,22 +86,18 @@ fn fan_out(
|
||||
indentation_str: &str,
|
||||
) {
|
||||
let new_indent = clean_indentation_string(indentation_str);
|
||||
let ntp_with_slash = strip_end_slash(node_to_print);
|
||||
let num_slashes = strip_end_slash_including_root(node_to_print)
|
||||
.matches('/')
|
||||
.count();
|
||||
|
||||
// Annoying edge case for when run on root directory
|
||||
let num_slashes = if ntp_with_slash == "/" {
|
||||
1
|
||||
} else {
|
||||
ntp_with_slash.matches('/').count() + 1
|
||||
};
|
||||
let mut num_siblings = count_siblings(to_display, num_slashes - 1, node_to_print);
|
||||
let mut num_siblings = count_siblings(to_display, num_slashes, node_to_print);
|
||||
let max_siblings = num_siblings;
|
||||
|
||||
for &(ref k, _) in to_display.iter() {
|
||||
let temp = String::from(ensure_end_slash(node_to_print));
|
||||
if k.starts_with(temp.as_str()) && k.matches('/').count() == num_slashes {
|
||||
if k.starts_with(temp.as_str()) && k.matches('/').count() == num_slashes + 1 {
|
||||
num_siblings -= 1;
|
||||
let has_children = has_children(to_display, new_depth, k, num_slashes);
|
||||
let has_children = has_children(to_display, new_depth, k, num_slashes + 1);
|
||||
display_node(
|
||||
k,
|
||||
found,
|
||||
@@ -103,7 +112,7 @@ fn fan_out(
|
||||
}
|
||||
|
||||
fn clean_indentation_string(s: &str) -> String {
|
||||
let mut is :String = s.into();
|
||||
let mut is: String = s.into();
|
||||
is = is.replace("└─┬", " ");
|
||||
is = is.replace("└──", " ");
|
||||
is = is.replace("├──", "│ ");
|
||||
|
||||
@@ -64,6 +64,14 @@ pub fn strip_end_slash(s: &str) -> String {
|
||||
new_name
|
||||
}
|
||||
|
||||
pub fn strip_end_slash_including_root(s: &str) -> String {
|
||||
let mut new_name = String::from(s);
|
||||
while new_name.ends_with('/') || new_name.ends_with("/.") {
|
||||
new_name.pop();
|
||||
}
|
||||
new_name
|
||||
}
|
||||
|
||||
fn examine_dir(
|
||||
top_dir: &str,
|
||||
apparent_size: bool,
|
||||
|
||||
Reference in New Issue
Block a user