Refactor: Simplify get_pretty_size

Remove the constant '5' used in format. Now all paths use
num_chars_needed_on_left_most instead.
This commit is contained in:
andy.boot
2022-08-18 15:03:37 +01:00
parent a7120b949c
commit a7fbcb8156
+4 -5
View File
@@ -344,13 +344,12 @@ fn get_name_percent(
fn get_pretty_size(node: &DisplayNode, is_biggest: bool, display_data: &DisplayData) -> String { fn get_pretty_size(node: &DisplayNode, is_biggest: bool, display_data: &DisplayData) -> String {
let output = if display_data.by_filecount { let output = if display_data.by_filecount {
let size_as_str = node.size.separate_with_commas(); node.size.separate_with_commas()
let spaces_to_add =
display_data.num_chars_needed_on_left_most - size_as_str.chars().count();
size_as_str + " ".repeat(spaces_to_add).as_str()
} else { } else {
format!("{:>5}", human_readable_number(node.size, display_data.iso)) 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();
if is_biggest && display_data.colors_on { if is_biggest && display_data.colors_on {
format!("{}", Red.paint(output)) format!("{}", Red.paint(output))