Fix: Remove first space char

Before we assumed 5 chars for printing the size of a node. This change
allows us to check if we need 5 chars or if we can manage with 4 which
may save us a character.

(1023B = 5 chars, 1.2K = 4 chars)

Note: Mac test runners create very long filenames in tmp directories. To
fix this we must either
1) Tell the terminal it has a very wide width
2) Duplicate the code to reduce the size of the filename (add .. at the
   end).

This commit changes from (2) to (1)
This commit is contained in:
andy.boot
2022-08-18 15:19:26 +01:00
parent a7fbcb8156
commit b62f35291d
4 changed files with 63 additions and 75 deletions
+10 -2
View File
@@ -130,7 +130,7 @@ pub fn draw_it(
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
find_biggest_size_str(&root_node, iso)
};
assert!(
@@ -182,6 +182,14 @@ pub fn draw_it(
}
}
fn find_biggest_size_str(node: &DisplayNode, iso: bool) -> usize {
let mut mx = human_readable_number(node.size, iso).chars().count();
for n in node.children.iter() {
mx = max(mx, find_biggest_size_str(n, iso));
}
mx
}
fn find_longest_dir_name(
node: &DisplayNode,
indent: usize,
@@ -349,7 +357,7 @@ fn get_pretty_size(node: &DisplayNode, is_biggest: bool, display_data: &DisplayD
human_readable_number(node.size, display_data.iso)
};
let spaces_to_add = display_data.num_chars_needed_on_left_most - output.chars().count();
let output = output + " ".repeat(spaces_to_add).as_str();
let output = " ".repeat(spaces_to_add) + output.as_str();
if is_biggest && display_data.colors_on {
format!("{}", Red.paint(output))