feat: Netzwerk-Traffic in Mbit/s anzeigen
Dezimale Megabit pro Sekunde statt KiB/s, damit sich die Anzeige direkt mit der Bandbreite des Internetanschlusses vergleichen lässt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+9
-6
@@ -110,10 +110,13 @@ fn read_net_bytes() -> (u64, u64) {
|
||||
(down, up)
|
||||
}
|
||||
|
||||
// Fixed-width, fixed-unit (KiB/s) formatting so the bar doesn't change size
|
||||
// as traffic fluctuates.
|
||||
fn format_net(down_rate: u64, up_rate: u64) -> String {
|
||||
format!("net:↓{down_rate:>5} ↑{up_rate:>5} KiB/s")
|
||||
// Fixed-width, fixed-unit (Mbit/s, decimal like ISP rates) formatting so the
|
||||
// bar doesn't change size as traffic fluctuates.
|
||||
fn format_net(down_bytes_per_sec: u64, up_bytes_per_sec: u64) -> String {
|
||||
let to_mbps = |b: u64| b as f64 * 8.0 / 1_000_000.0;
|
||||
let down = to_mbps(down_bytes_per_sec);
|
||||
let up = to_mbps(up_bytes_per_sec);
|
||||
format!("net:↓{down:>5.1} ↑{up:>5.1} Mbit/s")
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -157,8 +160,8 @@ fn main() {
|
||||
loop {
|
||||
std::thread::sleep(INTERVAL);
|
||||
let (down, up) = read_net_bytes();
|
||||
let down_rate = down.saturating_sub(prev_down) / INTERVAL.as_secs() / 1024;
|
||||
let up_rate = up.saturating_sub(prev_up) / INTERVAL.as_secs() / 1024;
|
||||
let down_rate = down.saturating_sub(prev_down) / INTERVAL.as_secs();
|
||||
let up_rate = up.saturating_sub(prev_up) / INTERVAL.as_secs();
|
||||
tx.send(Update::Net(format_net(down_rate, up_rate))).unwrap();
|
||||
prev_down = down;
|
||||
prev_up = up;
|
||||
|
||||
Reference in New Issue
Block a user