Skip to content

Commit

Permalink
change: Add decimal to disk values larger than 1GB (#451)
Browse files Browse the repository at this point in the history
A bit of a followup to #449, this adds decimal places for values over 1GB in regards to disk usage. This affects the disk widget (for the read/write per second) and process widgets (total read, total write, read/write per second).
  • Loading branch information
ClementTsang authored Apr 9, 2021
1 parent 8c7e85b commit cc03d57
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [#450](https://github.com/ClementTsang/bottom/pull/450): Tweak `default-light` colour scheme to look less terrible on white terminals.

- [#451](https://github.com/ClementTsang/bottom/pull/451): Add decimal place to disk values larger than 1GB for total read/write in process widgets, and read/write per second in process widgets and disk widgets.

## Bug Fixes

- [#416](https://github.com/ClementTsang/bottom/pull/416): Fixes grouped vs ungrouped modes in the processes widget having inconsistent spacing.
Expand Down
14 changes: 11 additions & 3 deletions src/app/data_farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{time::Instant, vec::Vec};
use crate::app::data_harvester::load_avg::LoadAvgHarvest;
use crate::{
data_harvester::{batteries, cpu, disks, load_avg, mem, network, processes, temperature, Data},
utils::gen_util::get_decimal_bytes,
utils::gen_util::{get_decimal_bytes, GIGA_LIMIT},
};
use regex::Regex;

Expand Down Expand Up @@ -296,8 +296,16 @@ impl DataCollection {
let converted_read = get_decimal_bytes(r_rate);
let converted_write = get_decimal_bytes(w_rate);
*io_labels = (
format!("{:.*}{}/s", 0, converted_read.0, converted_read.1),
format!("{:.*}{}/s", 0, converted_write.0, converted_write.1),
if r_rate >= GIGA_LIMIT {
format!("{:.*}{}/s", 1, converted_read.0, converted_read.1)
} else {
format!("{:.*}{}/s", 0, converted_read.0, converted_read.1)
},
if w_rate >= GIGA_LIMIT {
format!("{:.*}{}/s", 1, converted_write.0, converted_write.1)
} else {
format!("{:.*}{}/s", 0, converted_write.0, converted_write.1)
},
);
}
}
Expand Down
33 changes: 26 additions & 7 deletions src/data_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,32 @@ fn get_disk_io_strings(
let converted_total_write = get_decimal_bytes(total_write);

(
format!("{:.*}{}/s", 0, converted_rps.0, converted_rps.1),
format!("{:.*}{}/s", 0, converted_wps.0, converted_wps.1),
format!("{:.*}{}", 0, converted_total_read.0, converted_total_read.1),
format!(
"{:.*}{}",
0, converted_total_write.0, converted_total_write.1
),
if rps >= GIGA_LIMIT {
format!("{:.*}{}/s", 1, converted_rps.0, converted_rps.1)
} else {
format!("{:.*}{}/s", 0, converted_rps.0, converted_rps.1)
},
if wps >= GIGA_LIMIT {
format!("{:.*}{}/s", 1, converted_wps.0, converted_wps.1)
} else {
format!("{:.*}{}/s", 0, converted_wps.0, converted_wps.1)
},
if total_read >= GIGA_LIMIT {
format!("{:.*}{}", 1, converted_total_read.0, converted_total_read.1)
} else {
format!("{:.*}{}", 0, converted_total_read.0, converted_total_read.1)
},
if total_write >= GIGA_LIMIT {
format!(
"{:.*}{}",
1, converted_total_write.0, converted_total_write.1
)
} else {
format!(
"{:.*}{}",
0, converted_total_write.0, converted_total_write.1
)
},
)
}

Expand Down

0 comments on commit cc03d57

Please sign in to comment.