This commit is contained in:
raf 2024-08-04 00:05:57 +03:00
commit 0e4b2d2ac1
Signed by: NotAShelf
GPG key ID: AF26552424E53993
4 changed files with 67 additions and 24 deletions

View file

@ -16,7 +16,7 @@ pub fn get_username_and_hostname() -> Result<String, io::Error> {
Ok(format!("{YELLOW}{username}{RED}@{GREEN}{hostname}"))
}
pub fn get_root_disk_usage() -> Result<String, Box<dyn std::error::Error>> {
pub fn get_root_disk_usage() -> Result<String, io::Error> {
let vfs = statvfs("/")?;
let block_size = vfs.block_size() as u64;
let total_blocks = vfs.blocks();
@ -25,12 +25,12 @@ pub fn get_root_disk_usage() -> Result<String, Box<dyn std::error::Error>> {
let total_size = block_size * total_blocks;
let used_size = total_size - (block_size * available_blocks);
let total_size_gib = total_size as f64 / (1024.0 * 1024.0 * 1024.0);
let used_size_gib = used_size as f64 / (1024.0 * 1024.0 * 1024.0);
let usage_percentage = (used_size as f64 / total_size as f64) * 100.0;
let total_size = total_size as f64 / (1024.0 * 1024.0 * 1024.0);
let used_size = used_size as f64 / (1024.0 * 1024.0 * 1024.0);
let usage = (used_size as f64 / total_size as f64) * 100.0;
Ok(format!(
"{used_size_gib:.2} GiB / {total_size_gib:.2} GiB ({CYAN}{usage_percentage:.0}%{RESET})"
"{used_size:.2} GiB / {total_size:.2} GiB ({CYAN}{usage:.0}%{RESET})"
))
}