feat(network): Configurable min width for up/down speed

This commit is contained in:
Michael Carlberg 2016-10-11 14:07:59 +02:00
parent 55a5c5d896
commit 790059243b
4 changed files with 21 additions and 11 deletions

View File

@ -873,6 +873,10 @@ See [the bspwm module](#module-internalbspwm) for details on `label-dimmed`.
; - which would test the connection approx. every 10th sec.
; Default: 0
;ping_interval = 3
; Minimum output width of upload/download rate
; Default: 3
;udspeed_minwidth = 0
~~~
##### Extra formatting (example)
@ -897,9 +901,11 @@ See [the bspwm module](#module-internalbspwm) for details on `label-dimmed`.
; %local_ip% [wireless+wired]
; %essid% [wireless]
; %signal% [wireless]
; %upspeed% [wireless+wired]
; %downspeed% [wireless+wired]
; %linkspeed% [wired]
; Default: %ifname% %local_ip%
label-connected = %essid%
label-connected = %essid% %downspeed%
label-connected-foreground = #eefafafa
; Available tokens:

1
TODO
View File

@ -1,4 +1,3 @@
task: sandbox modules
task: rewrite README for 2.0
task: rewrite i3 module
task: improve test coverage

View File

@ -166,7 +166,7 @@ namespace net {
return m_linkdata.ip_address;
}
string downspeed() {
string downspeed(int minwidth = 3) {
if (!query_interface())
throw network_error("Failed to query interface");
@ -185,12 +185,12 @@ namespace net {
speed /= 1000;
}
return string_util::from_stream(stringstream() << std::setw(3) << std::setfill(' ')
return string_util::from_stream(stringstream() << std::setw(minwidth) << std::setfill(' ')
<< std::setprecision(0) << std::fixed << speed
<< " " << suffixes[suffix_n] << "/s");
}
string upspeed() {
string upspeed(int minwidth = 3) {
if (!query_interface())
throw network_error("Failed to query interface");
@ -209,7 +209,7 @@ namespace net {
speed /= 1000;
}
return string_util::from_stream(stringstream() << std::setw(3) << std::setfill(' ')
return string_util::from_stream(stringstream() << std::setw(minwidth) << std::setfill(' ')
<< std::setprecision(0) << std::fixed << speed
<< " " << suffixes[suffix_n] << "/s");
}

View File

@ -27,6 +27,7 @@ namespace modules {
m_interface = m_conf.get<string>(name(), "interface");
m_interval = chrono::duration<double>(m_conf.get<float>(name(), "interval", 1));
m_ping_nth_update = m_conf.get<int>(name(), "ping_interval", 0);
m_udspeed_minwidth = m_conf.get<int>(name(), "udspeed_minwidth", m_udspeed_minwidth);
// Add formats
m_formatter->add(
@ -75,6 +76,7 @@ namespace modules {
std::exit(EXIT_FAILURE);
}
}
void start() {
timer_module::start();
@ -138,8 +140,11 @@ namespace modules {
label->replace_token("%signal%", to_string(signal_quality) + "%");
}
label->replace_token("%upspeed%", network->upspeed());
label->replace_token("%downspeed%", network->downspeed());
auto upspeed = network->upspeed(m_udspeed_minwidth);
auto downspeed = network->downspeed(m_udspeed_minwidth);
label->replace_token("%upspeed%", upspeed);
label->replace_token("%downspeed%", downspeed);
};
if (m_label_connected) {
@ -220,14 +225,14 @@ namespace modules {
label_t m_label_packetloss;
label_t m_label_packetloss_tokenized;
string m_interface;
stateflag m_connected{false};
stateflag m_conseq_packetloss{false};
int m_signal_quality;
string m_interface;
int m_signal_quality;
int m_ping_nth_update;
int m_counter = -1; // -1 to ignore the first run
int m_udspeed_minwidth = 3;
};
}