summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandy.boot <bootandy@gmail.com>2022-08-18 12:21:24 +0100
committerandy.boot <bootandy@gmail.com>2022-08-18 15:22:10 +0100
commit812e1e3c535fc08abf45f2aab1049a8f0c669e96 (patch)
tree449a92af457632c3786795b9aadb37fe59fb0403
parent4eb3f295657d056106de0c3e280a178c8c7657e5 (diff)
Feature: Add skip-total flag
Flag to not include the last line containing totals of the output tree
-rw-r--r--src/display.rs27
-rw-r--r--src/main.rs6
2 files changed, 30 insertions, 3 deletions
diff --git a/src/display.rs b/src/display.rs
index ac64675..7ac7a8a 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -116,9 +116,18 @@ pub fn draw_it(
by_filecount: bool,
root_node: DisplayNode,
iso: bool,
+ skip_total: bool,
) {
+ let biggest = if skip_total {
+ root_node
+ .get_children_from_node(false)
+ .next()
+ .unwrap_or_else(|| root_node.clone())
+ } else {
+ root_node.clone()
+ };
let num_chars_needed_on_left_most = if by_filecount {
- let max_size = root_node.size;
+ let max_size = biggest.size;
max_size.separate_with_commas().chars().count()
} else {
5 // Under normal usage we need 5 chars to display the size of a directory
@@ -148,7 +157,7 @@ pub fn draw_it(
colors_on: !no_colors,
by_filecount,
num_chars_needed_on_left_most,
- base_size: root_node.size,
+ base_size: biggest.size,
longest_string_length,
ls_colors: LsColors::from_env().unwrap_or_default(),
iso,
@@ -158,7 +167,19 @@ pub fn draw_it(
percent_bar: first_size_bar,
display_data: &display_data,
};
- display_node(root_node, &draw_data, true, true);
+
+ if !skip_total {
+ display_node(root_node, &draw_data, true, true);
+ } else {
+ for (count, c) in root_node
+ .get_children_from_node(draw_data.display_data.is_reversed)
+ .enumerate()
+ {
+ let is_biggest = display_data.is_biggest(count, root_node.num_siblings());
+ let was_i_last = display_data.is_last(count, root_node.num_siblings());
+ display_node(c, &draw_data, is_biggest, was_i_last);
+ }
+ }
}
fn find_longest_dir_name(
diff --git a/src/main.rs b/src/main.rs
index f0f179f..c11106c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -164,6 +164,11 @@ fn main() {
.help("No percent bars or percentages will be displayed"),
)
.arg(
+ Arg::new("skip_total")
+ .long("skip-total")
+ .help("No total row will be displayed"),
+ )
+ .arg(
Arg::new("by_filecount")
.short('f')
.long("filecount")
@@ -330,6 +335,7 @@ fn main() {
by_filecount,
root_node,
options.is_present("iso"),
+ options.is_present("skip_total"),
),
}
}