summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2022-07-07 05:45:30 -0400
committerGitHub <noreply@github.com>2022-07-07 05:45:30 -0400
commit121632760d30b6c985e7c28a66fba777a7c606a8 (patch)
treee9d5b280db1acc554ef51953142ed48e458bdd54 /src
parentd3a187b52984152f48ee85bab0bc19c4f8d2ca48 (diff)
bug: fix total read/write units having /s (#763)
Fixes the total read/write columns in processes using the wrong unit (having /s).
Diffstat (limited to 'src')
-rw-r--r--src/app/widgets/process_table_widget.rs8
-rw-r--r--src/data_conversion.rs11
2 files changed, 16 insertions, 3 deletions
diff --git a/src/app/widgets/process_table_widget.rs b/src/app/widgets/process_table_widget.rs
index ed5226cb..7dfc3f12 100644
--- a/src/app/widgets/process_table_widget.rs
+++ b/src/app/widgets/process_table_widget.rs
@@ -9,7 +9,9 @@ use crate::{
CellContent, SortOrder, SortableState, TableComponentColumn, TableComponentHeader,
TableComponentState, WidthBounds,
},
- data_conversion::{binary_byte_string, dec_bytes_per_second_string, TableData, TableRow},
+ data_conversion::{
+ binary_byte_string, dec_bytes_per_second_string, dec_bytes_per_string, TableData, TableRow,
+ },
utils::gen_util::sort_partial_fn,
Pid,
};
@@ -788,10 +790,10 @@ impl ProcWidget {
dec_bytes_per_second_string(process.write_bytes_per_sec).into()
}
ProcWidgetColumn::TotalRead => {
- dec_bytes_per_second_string(process.total_read_bytes).into()
+ dec_bytes_per_string(process.total_read_bytes).into()
}
ProcWidgetColumn::TotalWrite => {
- dec_bytes_per_second_string(process.total_write_bytes).into()
+ dec_bytes_per_string(process.total_write_bytes).into()
}
ProcWidgetColumn::State => CellContent::HasAlt {
main: process.process_state.0.clone().into(),
diff --git a/src/data_conversion.rs b/src/data_conversion.rs
index 688e4b03..96e7bdfa 100644
--- a/src/data_conversion.rs
+++ b/src/data_conversion.rs
@@ -583,6 +583,17 @@ pub fn binary_byte_string(value: u64) -> String {
}
}
+/// Returns a string given a value that is converted to the closest SI-variant.
+/// If the value is greater than a giga-X, then it will return a decimal place.
+pub fn dec_bytes_per_string(value: u64) -> String {
+ let converted_values = get_decimal_bytes(value);
+ if value >= GIGA_LIMIT {
+ format!("{:.*}{}", 1, converted_values.0, converted_values.1)
+ } else {
+ format!("{:.*}{}", 0, converted_values.0, converted_values.1)
+ }
+}
+
/// Returns a string given a value that is converted to the closest SI-variant, per second.
/// If the value is greater than a giga-X, then it will return a decimal place.
pub fn dec_bytes_per_second_string(value: u64) -> String {