Skip to content

Commit

Permalink
token statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurk committed Jan 12, 2025
1 parent 21528b7 commit 4a31070
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions utils/src/commands/token_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

0 comments on commit 4a31070

Please sign in to comment.