diff --git a/src/app.rs b/src/app.rs index 3cef51f..9f088e8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -38,7 +38,7 @@ pub fn setup_app<'a, 'b>( None }, Some(DiskWidget::new(colorscheme)), - Some(NetWidget::new(colorscheme, &args.interface)), + Some(NetWidget::new(colorscheme, &args.interface, args.bits)), Some(TempWidget::new(colorscheme, args.fahrenheit)), ) }; diff --git a/src/args.rs b/src/args.rs index 7b79f6f..f342859 100644 --- a/src/args.rs +++ b/src/args.rs @@ -51,4 +51,8 @@ pub struct Args { /// Show a statusbar with the time. #[structopt(short = "s", long = "statusbar")] pub statusbar: bool, + + /// Show Network speed in bits per second + #[structopt(short = "B", long = "bits")] + pub bits: bool, } diff --git a/src/widgets/net.rs b/src/widgets/net.rs index 1a05ffc..d16ca3a 100644 --- a/src/widgets/net.rs +++ b/src/widgets/net.rs @@ -18,6 +18,7 @@ pub struct NetWidget<'a, 'b> { colorscheme: &'a Colorscheme, interface: &'b str, + show_bits: bool, bytes_recv: Vec, bytes_sent: Vec, @@ -29,7 +30,11 @@ pub struct NetWidget<'a, 'b> { } impl NetWidget<'_, '_> { - pub fn new<'a, 'b>(colorscheme: &'a Colorscheme, interface: &'b str) -> NetWidget<'a, 'b> { + pub fn new<'a, 'b>( + colorscheme: &'a Colorscheme, + interface: &'b str, + show_bits: bool, + ) -> NetWidget<'a, 'b> { NetWidget { title: if interface == "all" { " Network Usage ".to_string() @@ -48,6 +53,7 @@ impl NetWidget<'_, '_> { total_bytes_sent: 0, collector: network::NetIoCountersCollector::default(), + show_bits, } } } @@ -139,10 +145,17 @@ impl Widget for NetWidget<'_, '_> { buf.set_string( top_half.x + 1, top_half.y + 2, - format!( - "Rx/s: {}/s", - Size::Bytes(self.bytes_recv.last().unwrap().to_owned()) - ), + if self.show_bits { + format!( + "Rx/s: {} bits/s", + self.bytes_recv.last().unwrap().to_owned() * 8 + ) + } else { + format!( + "Rx/s: {}/s", + Size::Bytes(self.bytes_recv.last().unwrap().to_owned()) + ) + }, self.colorscheme.text.modifier(Modifier::BOLD), ); @@ -176,10 +189,17 @@ impl Widget for NetWidget<'_, '_> { buf.set_string( bottom_half.x + 1, bottom_half.y + 2, - format!( - "Tx/s: {}/s", - Size::Bytes(self.bytes_sent.last().unwrap().to_owned()) - ), + if self.show_bits { + format!( + "Tx/s: {} bits/s", + self.bytes_sent.last().unwrap().to_owned() * 8 + ) + } else { + format!( + "Rx/s: {}/s", + Size::Bytes(self.bytes_sent.last().unwrap().to_owned()) + ) + }, self.colorscheme.text.modifier(Modifier::BOLD), );