diff options
author | ilyes-ced <109927235+ilyes-ced@users.noreply.github.com> | 2023-12-08 08:33:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-08 16:33:10 +0800 |
commit | 5648be6f11bd93a772cc6b4a04915c095577ea3d (patch) | |
tree | bc5e4ada9bb3ae9f3d07ea5f18e0c52e30383504 | |
parent | 0a89c5aba518294b1fdcaa77bdbc15c314b1651d (diff) |
Show interface names (#340)
* added interface names
* some fixes
* Set interface name in UI only once
* Code style
* Add changelog entry
---------
Co-authored-by: cyqsimon <28627918+cyqsimon@users.noreply.github.com>
39 files changed, 84 insertions, 79 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d6ca92e..b390556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Added +* Show interface names #340 - @ilyes-ced * CI: ensure a changelog entry exists for each PR #331 - @cyqsimon ## [0.21.1] - 2023-10-16 diff --git a/src/display/components/header_details.rs b/src/display/components/header_details.rs index 234ad1e..b532f7b 100644 --- a/src/display/components/header_details.rs +++ b/src/display/components/header_details.rs @@ -73,6 +73,7 @@ impl<'a> HeaderDetails<'a> { } fn bandwidth_string(&self) -> String { + let intrf = self.state.interface_name.as_deref().unwrap_or("all"); let t = if self.state.cumulative_mode { "Data" } else { @@ -88,7 +89,7 @@ impl<'a> HeaderDetails<'a> { unit_family, }; let paused = if self.paused { " [PAUSED]" } else { "" }; - format!(" Total {t} (Up / Down): {up} / {down}{paused}") + format!("IF: {intrf} | Total {t} (Up / Down): {up} / {down}{paused}") } fn render_elapsed_time(&self, frame: &mut Frame, rect: Rect, elapsed_time: &str, color: Color) { diff --git a/src/display/ui.rs b/src/display/ui.rs index df0978f..4b6d716 100644 --- a/src/display/ui.rs +++ b/src/display/ui.rs @@ -4,7 +4,7 @@ use chrono::prelude::*; use ratatui::{backend::Backend, Terminal}; use crate::{ - cli::RenderOpts, + cli::{Opt, RenderOpts}, display::{ components::{HeaderDetails, HelpText, Layout, Table}, UIState, @@ -26,21 +26,22 @@ impl<B> Ui<B> where B: Backend, { - pub fn new(terminal_backend: B, opts: RenderOpts) -> Self { + pub fn new(terminal_backend: B, opts: &Opt) -> Self { let mut terminal = Terminal::new(terminal_backend).unwrap(); terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); let state = { let mut state = UIState::default(); - state.unit_family = opts.unit_family; - state.cumulative_mode = opts.total_utilization; + state.interface_name = opts.interface.clone(); + state.unit_family = opts.render_opts.unit_family; + state.cumulative_mode = opts.render_opts.total_utilization; state }; Ui { terminal, state, ip_to_host: Default::default(), - opts, + opts: opts.render_opts, } } pub fn output_text(&mut self, write_to_stdout: &mut (dyn FnMut(String) + Send)) { diff --git a/src/display/ui_state.rs b/src/display/ui_state.rs index 1295ef9..37ff639 100644 --- a/src/display/ui_state.rs +++ b/src/display/ui_state.rs @@ -79,6 +79,8 @@ pub struct UtilizationData { #[derive(Default)] pub struct UIState { + /// The interface name in single-interface mode. `None` means all interfaces. + pub interface_name: Option<String>, pub processes: Vec<(String, NetworkData)>, pub remote_addresses: Vec<(IpAddr, NetworkData)>, pub connections: Vec<(Connection, ConnectionData)>, diff --git a/src/main.rs b/src/main.rs index 8f765f4..a6a00d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,7 +121,7 @@ where let raw_mode = opts.raw; let network_utilization = Arc::new(Mutex::new(Utilization::new())); - let ui = Arc::new(Mutex::new(Ui::new(terminal_backend, opts.render_opts))); + let ui = Arc::new(Mutex::new(Ui::new(terminal_backend, &opts))); let display_handler = thread::Builder::new() .name("display_handler".to_string()) diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_addresses.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_addresses.snap index cbb9496..60c0728 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_addresses.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_addresses.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by remote address───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │Remote Address Connections Rate (Up / Down) │ │ │ diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_connections.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_connections.snap index 61bdb23..80532cf 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_connections.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_connections.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by connection───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │Connection Process Rate (Up / Down) │ │ │ diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_processes.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_processes.snap index 6ea91e9..1910f6a 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_processes.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_processes.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by process name─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │Process Connections Rate (Up / Down) │ │ │ diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_processes_with_dns_queries.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_processes_with_dns_queries.snap index 905f34a..7fea434 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_processes_with_dns_queries.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_processes_with_dns_queries.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by process name─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │Process Connections Rate (Up / Down) │ │ │ diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_startup.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_startup.snap index f1056c8..f8c72d4 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_startup.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_startup.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by process name──────────────────────────────────────────────────────────────────┐┌Utilization by remote address────────────────────────────────────────────────────────────────┐ │Process Connections Rate (Up / Down) ││Remote Address Connections Rate (Up / Down) │ │ ││ │ diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__bi_directional_traffic.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__bi_directional_traffic.snap index de1acbe..68295bf 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__bi_directional_traffic.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__bi_directional_traffic.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by process name──────────────────────────────────────────────────────────────────┐┌Utilization by remote address────────────────────────────────────────────────────────────────┐ │Process Connections Rate (Up / Down) ││Remote Address Connections Rate (Up / Down) │ │ ││ │ @@ -54,7 +54,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR Press <SPACE> to pause. Use <TAB> to rearrange tables. (DNS queries hidden). --- SECTION SEPARATOR --- - 24. 0B / 25.00B + 24. 0B / 25.00B 1 1 24.00B / 25.00B 1.1.1.1 1 24.00B / 25.00B diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-full-width-under-30-height-draw_events.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-full-width-under-30-height-draw_events.snap index c00c367..809920d 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-full-width-under-30-height-draw_events.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-full-width-under-30-height-draw_events.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by process name──────────────────────────────────────────────────────────────────┐┌Utilization by remote address────────────────────────────────────────────────────────────────┐ │Process Connections Rate (Up / Down) ││Remote Address Connections Rate (Up / Down) │ │ ││ │ @@ -33,7 +33,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR Press <SPACE> to pause. Use <TAB> to rearrange tables. (DNS queries hidden). --- SECTION SEPARATOR --- - 98. 0B + 98. 0B 5 1 0.00B / 28.00B 3.3.3.3 1 0.00B / 28.00B diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-full-height-draw_events.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-full-height-draw_events.snap index 4a9c967..9a49d50 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-full-height-draw_events.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-full-height-draw_events.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by process name──────────────────────────────────────────────────────────────────────────────────────────┐ │Process Connections Rate (Up / Down) │ │ │ @@ -54,7 +54,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR Press <SPACE> to pause. Use <TAB> to rearrange tables. (DNS queries hidden). --- SECTION SEPARATOR --- - 98. 0B + 98. 0B 5 1 0.00B / 28.00B diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-under-30-height-draw_events.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-under-30-height-draw_events.snap index a13bf3a..bbd6326 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-under-30-height-draw_events.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-under-30-height-draw_events.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by process name──────────────────────────────────────────────────────────────────────────────────────────┐ │Process Connections Rate (Up / Down) │ │ │ @@ -33,7 +33,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR Press <SPACE> to pause. Use <TAB> to rearrange tables. (DNS queries hidden). --- SECTION SEPARATOR --- - 98. 0B + 98. 0B 5 1 0.00B / 28.00B diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-50-width-under-50-height-draw_events.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-50-width-under-50-height-draw_events.snap index ecb59a4..39c158e 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-50-width-under-50-height-draw_events.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-50-width-under-50-height-draw_events.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B ┌Utilization by process name─────────────────────┐ │Process Rate (Up / Down) │ │ │ @@ -54,7 +54,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR Press <SPACE> to pause. --- SECTION SEPARATOR --- - 98. 0B + 5 0.00B / 28.00B diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-70-width-under-30-height-draw_events.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-70-width-under-30-height-draw_events.snap index 2231375..7f38470 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-70-width-under-30-height-draw_events.snap +++ b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-70-width-under-30-height-draw_events.snap @@ -2,7 +2,7 @@ source: src/tests/cases/ui.rs expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR) --- - Total Rate (Up / Down): 0.00B / 0.00B +IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B ┌Utilization by process name────────────────────────────────────────┐ │Process Connections Rate (Up / Down) │ │ │ @@ -33,7 +33,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR Press <SPACE> to pause. Use <TAB> to rearrange tables. --- SECTION SEPARATOR --- - 98. 0B + 98. 0B 5 1 0.00B / 28.00B diff --git a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__multiple_connections_from_remote_address.snap b/src/tests/cases/snapshots/bandwhich__tests__cases__ui__multiple_connections_from_remote_address.snap index 378c61a..93a42d3 100644 --- a/src/tests/cases/snapshots/bandwhich__tests__cases__ui__multiple_connections_from_remote_address.snap +++ b/ |