summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraristocratos <gnmjpl@gmail.com>2022-01-16 13:39:50 +0100
committeraristocratos <gnmjpl@gmail.com>2022-01-16 13:39:50 +0100
commit989427ff3a3f5be9f628da4bfa76c71f4b8a1021 (patch)
tree0290a6eacf2ac6e894946bbde27816a37b663946
parentf46989ad35803103e1554063194cf2f6c1969e49 (diff)
Added: Option for base 10 bytes/bits
-rw-r--r--src/btop_config.cpp3
-rw-r--r--src/btop_menu.cpp11
-rw-r--r--src/btop_tools.cpp36
3 files changed, 40 insertions, 10 deletions
diff --git a/src/btop_config.cpp b/src/btop_config.cpp
index 37e7d9c..1883dfa 100644
--- a/src/btop_config.cpp
+++ b/src/btop_config.cpp
@@ -123,6 +123,8 @@ namespace Config {
{"temp_scale", "#* Which temperature scale to use, available values: \"celsius\", \"fahrenheit\", \"kelvin\" and \"rankine\"."},
+ {"base_10_sizes", "#* Use base 10 for bits/bytes sizes, KB = 1000 instead of KiB = 1024."},
+
{"show_cpu_freq", "#* Show CPU frequency."},
{"clock_format", "#* Draw a clock at top of screen, formatting according to strftime, empty string to disable.\n"
@@ -233,6 +235,7 @@ namespace Config {
{"use_fstab", true},
{"show_io_stat", true},
{"io_mode", false},
+ {"base_10_sizes", false},
{"io_graph_combined", false},
{"net_auto", true},
{"net_sync", false},
diff --git a/src/btop_menu.cpp b/src/btop_menu.cpp
index c526521..3fb24bf 100644
--- a/src/btop_menu.cpp
+++ b/src/btop_menu.cpp
@@ -257,6 +257,14 @@ namespace Menu {
"\"%H\" = 24h hour, \"%I\" = 12h hour",
"\"%M\" = minute, \"%S\" = second",
"\"%d\" = day, \"%m\" = month, \"%y\" = year"},
+ {"base_10_sizes",
+ "Use base 10 for bits and bytes sizes.",
+ "",
+ "Uses KB = 1000 instead of KiB = 1024,",
+ "MB = 1000KB instead of MiB = 1024KiB,",
+ "and so on.",
+ "",
+ "True or False."},
{"background_update",
"Update main ui when menus are showing.",
"",
@@ -1134,6 +1142,9 @@ namespace Menu {
else if (option == "background_update") {
Runner::pause_output = false;
}
+ else if (option == "base_10_sizes") {
+ recollect = true;
+ }
}
else if (selPred.test(isBrowseable)) {
auto& optList = optionsList.at(option).get();
diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp
index b7e80da..1f0f49b 100644
--- a/src/btop_tools.cpp
+++ b/src/btop_tools.cpp
@@ -32,6 +32,7 @@ tab-size = 4
#include <btop_shared.hpp>
#include <btop_tools.hpp>
+#include <btop_config.hpp>
using std::string_view, std::max, std::floor, std::to_string, std::cin, std::cout, std::flush, robin_hood::unordered_flat_map;
namespace fs = std::filesystem;
@@ -288,23 +289,38 @@ namespace Tools {
string floating_humanizer(uint64_t value, const bool shorten, size_t start, const bool bit, const bool per_second) {
string out;
const size_t mult = (bit) ? 8 : 1;
- static const array<string, 11> Units_bit = {"bit", "Kib", "Mib", "Gib", "Tib", "Pib", "Eib", "Zib", "Yib", "Bib", "GEb"};
- static const array<string, 11> Units_byte = {"Byte", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "BiB", "GEB"};
- const auto& units = (bit) ? Units_bit : Units_byte;
+ const bool mega = Config::getB("base_10_sizes");
+ static const array<string, 11> mebiUnits_bit = {"bit", "Kib", "Mib", "Gib", "Tib", "Pib", "Eib", "Zib", "Yib", "Bib", "GEb"};
+ static const array<string, 11> mebiUnits_byte = {"Byte", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "BiB", "GEB"};
+ static const array<string, 11> megaUnits_bit = {"bit", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb", "Bb", "Gb"};
+ static const array<string, 11> megaUnits_byte = {"Byte", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "BB", "GB"};
+ const auto& units = (bit) ? ( mega ? megaUnits_bit : mebiUnits_bit) : ( mega ? megaUnits_byte : mebiUnits_byte);
value *= 100 * mult;
- while (value >= 102400) {
- value >>= 10;
- if (value < 100) {
- out = to_string(value);
- break;
+ if (mega) {
+ while (value >= 100000) {
+ value /= 1000;
+ if (value < 100) {
+ out = to_string(value);
+ break;
+ }
+ start++;
+ }
+ }
+ else {
+ while (value >= 102400) {
+ value >>= 10;
+ if (value < 100) {
+ out = to_string(value);
+ break;
+ }
+ start++;
}
- start++;
}
if (out.empty()) {
out = to_string(value);
- if (out.size() == 4 and start > 0) { out.pop_back(); out.insert(2, ".");}
+ if (not mega and out.size() == 4 and start > 0) { out.pop_back(); out.insert(2, ".");}
else if (out.size() == 3 and start > 0) out.insert(1, ".");
else if (out.size() >= 2) out.resize(out.size() - 2);
}