Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions include/util/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

class pow_format {
public:
pow_format(long long val, std::string&& unit, bool binary = false)
: val_(val), unit_(unit), binary_(binary) {};
pow_format(long long val, std::string&& unit, bool binary = false, int min_pow_for_decimal = 0)
: val_(val), unit_(unit), binary_(binary), min_pow_for_decimal_(min_pow_for_decimal) {};

long long val_;
std::string unit_;
bool binary_;
int min_pow_for_decimal_;
};

namespace fmt {
Expand Down Expand Up @@ -74,7 +75,8 @@ struct formatter<pow_format> {
break;
case 0:
default:
format = "{coefficient:.1f}{prefix}{unit}";
format = pow < s.min_pow_for_decimal_ ? "{coefficient:.0f}{prefix}{unit}"
: "{coefficient:.1f}{prefix}{unit}";
break;
}
return fmt::format_to(
Expand Down
8 changes: 8 additions & 0 deletions src/modules/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ auto waybar::modules::Network::update() -> void {
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")),
fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")),
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")),
fmt::arg("bandwidthDownBytesCompact",
pow_format(bandwidth_down / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthUpBytesCompact",
pow_format(bandwidth_up / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthTotalBytes",
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s")));
if (text.compare(label_.get_label()) != 0) {
Expand Down Expand Up @@ -401,6 +405,10 @@ auto waybar::modules::Network::update() -> void {
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")),
fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")),
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")),
fmt::arg("bandwidthDownBytesCompact",
pow_format(bandwidth_down / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthUpBytesCompact",
pow_format(bandwidth_up / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthTotalBytes",
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s")));
if (label_.get_tooltip_text() != tooltip_text) {
Expand Down