mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-12-12 16:03:50 +00:00
cleanup
This commit is contained in:
parent
6dafa776d2
commit
0e4b2d2ac1
4 changed files with 67 additions and 24 deletions
|
|
@ -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})"
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue