feat: use humansize crate and which crate for program lookup

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-12 16:23:11 -03:00
parent 465e4c40ab
commit 6e4b690bd8
4 changed files with 9 additions and 139 deletions

View File

@@ -29,34 +29,9 @@ pub fn get_meta_from_env() -> HashMap<String, String> {
meta_env
}
pub fn format_size_human_readable(size: u64) -> String {
const UNITS: &[&str] = &["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei"];
const THRESHOLD: u64 = 1024;
if size == 0 {
return "0".to_string();
}
let mut size_f = size as f64;
let mut unit_index = 0;
while size_f >= THRESHOLD as f64 && unit_index < UNITS.len() - 1 {
size_f /= THRESHOLD as f64;
unit_index += 1;
}
if unit_index == 0 {
format!("{}", size)
} else if size_f.fract() == 0.0 {
format!("{}{}", size_f as u64, UNITS[unit_index])
} else {
format!("{:.1}{}", size_f, UNITS[unit_index])
}
}
pub fn format_size(size: u64, human_readable: bool) -> String {
match human_readable {
true => format_size_human_readable(size),
true => humansize::format_size(size, humansize::DECIMAL),
false => size.to_string(),
}
}