mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Neaten code
This commit is contained in:
+6
-12
@@ -114,14 +114,9 @@ pub fn draw_it(
|
|||||||
no_percents: bool,
|
no_percents: bool,
|
||||||
terminal_width: usize,
|
terminal_width: usize,
|
||||||
by_filecount: bool,
|
by_filecount: bool,
|
||||||
option_root_node: Option<DisplayNode>,
|
root_node: DisplayNode,
|
||||||
iso: bool,
|
iso: bool,
|
||||||
) {
|
) {
|
||||||
if option_root_node.is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let root_node = option_root_node.unwrap();
|
|
||||||
|
|
||||||
let num_chars_needed_on_left_most = if by_filecount {
|
let num_chars_needed_on_left_most = if by_filecount {
|
||||||
let max_size = root_node.size;
|
let max_size = root_node.size;
|
||||||
max_size.separate_with_commas().chars().count()
|
max_size.separate_with_commas().chars().count()
|
||||||
@@ -134,15 +129,15 @@ pub fn draw_it(
|
|||||||
"Not enough terminal width"
|
"Not enough terminal width"
|
||||||
);
|
);
|
||||||
|
|
||||||
let t = terminal_width - num_chars_needed_on_left_most - 2;
|
let allowed_width = terminal_width - num_chars_needed_on_left_most - 2;
|
||||||
let num_indent_chars = 3;
|
let num_indent_chars = 3;
|
||||||
let longest_string_length =
|
let longest_string_length =
|
||||||
find_longest_dir_name(&root_node, num_indent_chars, t, !use_full_path);
|
find_longest_dir_name(&root_node, num_indent_chars, allowed_width, !use_full_path);
|
||||||
|
|
||||||
let max_bar_length = if no_percents || longest_string_length + 7 >= t as usize {
|
let max_bar_length = if no_percents || longest_string_length + 7 >= allowed_width as usize {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
t as usize - longest_string_length - 7
|
allowed_width as usize - longest_string_length - 7
|
||||||
};
|
};
|
||||||
|
|
||||||
let first_size_bar = repeat(BLOCKS[0]).take(max_bar_length).collect::<String>();
|
let first_size_bar = repeat(BLOCKS[0]).take(max_bar_length).collect::<String>();
|
||||||
@@ -273,7 +268,7 @@ fn pad_or_trim_filename(node: &DisplayNode, indent: &str, display_data: &Display
|
|||||||
// Add spaces after the filename so we can draw the % used bar chart.
|
// Add spaces after the filename so we can draw the % used bar chart.
|
||||||
let name_and_padding = name
|
let name_and_padding = name
|
||||||
+ " "
|
+ " "
|
||||||
.repeat((display_data.longest_string_length) - (width))
|
.repeat(display_data.longest_string_length - width)
|
||||||
.as_str();
|
.as_str();
|
||||||
|
|
||||||
name_and_padding
|
name_and_padding
|
||||||
@@ -286,7 +281,6 @@ fn maybe_trim_filename(name_in: String, indent: &str, display_data: &DisplayData
|
|||||||
"Terminal width not wide enough to draw directory tree"
|
"Terminal width not wide enough to draw directory tree"
|
||||||
);
|
);
|
||||||
|
|
||||||
// println!("{} : {} : {}", UnicodeWidthStr::width(&*name_in) ,display_data.longest_string_length, indent_length);
|
|
||||||
let max_size = display_data.longest_string_length - indent_length;
|
let max_size = display_data.longest_string_length - indent_length;
|
||||||
if UnicodeWidthStr::width(&*name_in) > max_size {
|
if UnicodeWidthStr::width(&*name_in) > max_size {
|
||||||
let name = name_in.chars().take(max_size - 2).collect::<String>();
|
let name = name_in.chars().take(max_size - 2).collect::<String>();
|
||||||
|
|||||||
+6
-3
@@ -312,14 +312,17 @@ fn main() {
|
|||||||
if has_errors {
|
if has_errors {
|
||||||
eprintln!("Did not have permissions for all directories");
|
eprintln!("Did not have permissions for all directories");
|
||||||
}
|
}
|
||||||
draw_it(
|
match tree {
|
||||||
|
None => {}
|
||||||
|
Some(root_node) => draw_it(
|
||||||
options.is_present("display_full_paths"),
|
options.is_present("display_full_paths"),
|
||||||
!options.is_present("reverse"),
|
!options.is_present("reverse"),
|
||||||
no_colors,
|
no_colors,
|
||||||
options.is_present("no_bars"),
|
options.is_present("no_bars"),
|
||||||
terminal_width,
|
terminal_width,
|
||||||
by_filecount,
|
by_filecount,
|
||||||
tree,
|
root_node,
|
||||||
options.is_present("iso"),
|
options.is_present("iso"),
|
||||||
);
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user