diff --git a/utils/src/commands/token_stat.rs b/utils/src/commands/token_stat.rs index 8e505e6..09ab1e0 100644 --- a/utils/src/commands/token_stat.rs +++ b/utils/src/commands/token_stat.rs @@ -19,15 +19,26 @@ pub fn token_stat(path: PathBuf) { .map(|(kind, count)| (format!("{:?}", kind), *count)) .collect(); - println!("\nToken statistics for: {:?}\n", path); - println!("Total token count: {total}\n"); + println!( + "\n{}\n", + tab( + "Token statistics for", + path.to_str().expect("path to be valid unicode") + ) + ); + println!("{}\n", tab("Total token count", total.to_string().as_str())); table.sort_by(|(_, left), (_, right)| right.cmp(left)); table .iter() - .for_each(|(kind, count)| println!("{}:{}{}", kind, tab(kind.as_ref()), count)); + .for_each(|(kind, count)| println!("{}", tab(kind.as_ref(), count.to_string().as_str()))); } -fn tab(str: &str) -> String { - " ".repeat(20_usize.checked_sub(str.len()).unwrap_or(1)) +fn tab(left: &str, right: &str) -> String { + format!( + "{}:{}{}", + left, + " ".repeat(21_usize.checked_sub(left.len()).unwrap_or(1)), + right + ) }