Skip to content

Commit 5648be6

Browse files
ilyes-cedcyqsimon
andauthored
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 <[email protected]>
1 parent 0a89c5a commit 5648be6

File tree

39 files changed

+84
-79
lines changed

39 files changed

+84
-79
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
88

99
### Added
1010

11+
* Show interface names #340 - @ilyes-ced
1112
* CI: ensure a changelog entry exists for each PR #331 - @cyqsimon
1213

1314
## [0.21.1] - 2023-10-16

src/display/components/header_details.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl<'a> HeaderDetails<'a> {
7373
}
7474

7575
fn bandwidth_string(&self) -> String {
76+
let intrf = self.state.interface_name.as_deref().unwrap_or("all");
7677
let t = if self.state.cumulative_mode {
7778
"Data"
7879
} else {
@@ -88,7 +89,7 @@ impl<'a> HeaderDetails<'a> {
8889
unit_family,
8990
};
9091
let paused = if self.paused { " [PAUSED]" } else { "" };
91-
format!(" Total {t} (Up / Down): {up} / {down}{paused}")
92+
format!("IF: {intrf} | Total {t} (Up / Down): {up} / {down}{paused}")
9293
}
9394

9495
fn render_elapsed_time(&self, frame: &mut Frame, rect: Rect, elapsed_time: &str, color: Color) {

src/display/ui.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use chrono::prelude::*;
44
use ratatui::{backend::Backend, Terminal};
55

66
use crate::{
7-
cli::RenderOpts,
7+
cli::{Opt, RenderOpts},
88
display::{
99
components::{HeaderDetails, HelpText, Layout, Table},
1010
UIState,
@@ -26,21 +26,22 @@ impl<B> Ui<B>
2626
where
2727
B: Backend,
2828
{
29-
pub fn new(terminal_backend: B, opts: RenderOpts) -> Self {
29+
pub fn new(terminal_backend: B, opts: &Opt) -> Self {
3030
let mut terminal = Terminal::new(terminal_backend).unwrap();
3131
terminal.clear().unwrap();
3232
terminal.hide_cursor().unwrap();
3333
let state = {
3434
let mut state = UIState::default();
35-
state.unit_family = opts.unit_family;
36-
state.cumulative_mode = opts.total_utilization;
35+
state.interface_name = opts.interface.clone();
36+
state.unit_family = opts.render_opts.unit_family;
37+
state.cumulative_mode = opts.render_opts.total_utilization;
3738
state
3839
};
3940
Ui {
4041
terminal,
4142
state,
4243
ip_to_host: Default::default(),
43-
opts,
44+
opts: opts.render_opts,
4445
}
4546
}
4647
pub fn output_text(&mut self, write_to_stdout: &mut (dyn FnMut(String) + Send)) {

src/display/ui_state.rs

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ pub struct UtilizationData {
7979

8080
#[derive(Default)]
8181
pub struct UIState {
82+
/// The interface name in single-interface mode. `None` means all interfaces.
83+
pub interface_name: Option<String>,
8284
pub processes: Vec<(String, NetworkData)>,
8385
pub remote_addresses: Vec<(IpAddr, NetworkData)>,
8486
pub connections: Vec<(Connection, ConnectionData)>,

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ where
121121
let raw_mode = opts.raw;
122122

123123
let network_utilization = Arc::new(Mutex::new(Utilization::new()));
124-
let ui = Arc::new(Mutex::new(Ui::new(terminal_backend, opts.render_opts)));
124+
let ui = Arc::new(Mutex::new(Ui::new(terminal_backend, &opts)));
125125

126126
let display_handler = thread::Builder::new()
127127
.name("display_handler".to_string())

src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_addresses.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by remote address───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
77
Remote Address Connections Rate (Up / Down) │
88
│ │

src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_connections.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by connection───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
77
Connection Process Rate (Up / Down) │
88
│ │

src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_only_processes.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by process name─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
77
Process Connections Rate (Up / Down) │
88
│ │

src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_processes_with_dns_queries.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by process name─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
77
Process Connections Rate (Up / Down) │
88
│ │

src/tests/cases/snapshots/bandwhich__tests__cases__ui__basic_startup.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by process name──────────────────────────────────────────────────────────────────┐┌Utilization by remote address────────────────────────────────────────────────────────────────┐
77
Process Connections Rate (Up / Down) ││Remote Address Connections Rate (Up / Down) │
88
│ ││ │

src/tests/cases/snapshots/bandwhich__tests__cases__ui__bi_directional_traffic.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by process name──────────────────────────────────────────────────────────────────┐┌Utilization by remote address────────────────────────────────────────────────────────────────┐
77
Process Connections Rate (Up / Down) ││Remote Address Connections Rate (Up / Down) │
88
│ ││ │
@@ -54,7 +54,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR
5454
Press <SPACE> to pause. Use <TAB> to rearrange tables. (DNS queries hidden).
5555

5656
--- SECTION SEPARATOR ---
57-
24. 0B / 25.00B
57+
24. 0B / 25.00B
5858

5959

6060
1 1 24.00B / 25.00B 1.1.1.1 1 24.00B / 25.00B

src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-full-width-under-30-height-draw_events.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by process name──────────────────────────────────────────────────────────────────┐┌Utilization by remote address────────────────────────────────────────────────────────────────┐
77
Process Connections Rate (Up / Down) ││Remote Address Connections Rate (Up / Down) │
88
│ ││ │
@@ -33,7 +33,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR
3333
Press <SPACE> to pause. Use <TAB> to rearrange tables. (DNS queries hidden).
3434

3535
--- SECTION SEPARATOR ---
36-
98. 0B
36+
98. 0B
3737

3838

3939
5 1 0.00B / 28.00B 3.3.3.3 1 0.00B / 28.00B

src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-full-height-draw_events.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by process name──────────────────────────────────────────────────────────────────────────────────────────┐
77
Process Connections Rate (Up / Down) │
88
│ │
@@ -54,7 +54,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR
5454
Press <SPACE> to pause. Use <TAB> to rearrange tables. (DNS queries hidden).
5555

5656
--- SECTION SEPARATOR ---
57-
98. 0B
57+
98. 0B
5858

5959

6060
5 1 0.00B / 28.00B

src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-120-width-under-30-height-draw_events.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B / 0.00B
66
Utilization by process name──────────────────────────────────────────────────────────────────────────────────────────┐
77
Process Connections Rate (Up / Down) │
88
│ │
@@ -33,7 +33,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR
3333
Press <SPACE> to pause. Use <TAB> to rearrange tables. (DNS queries hidden).
3434

3535
--- SECTION SEPARATOR ---
36-
98. 0B
36+
98. 0B
3737

3838

3939
5 1 0.00B / 28.00B

src/tests/cases/snapshots/bandwhich__tests__cases__ui__layout-under-50-width-under-50-height-draw_events.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: src/tests/cases/ui.rs
33
expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR)
44
---
5-
Total Rate (Up / Down): 0.00B / 0.00B
5+
IF: interface_name | Total Rate (Up / Down): 0.00B
66
Utilization by process name─────────────────────┐
77
Process Rate (Up / Down) │
88
│ │
@@ -54,7 +54,7 @@ expression: terminal_draw_events.lock().unwrap().join(SNAPSHOT_SECTION_SEPARATOR
5454
Press <SPACE> to pause.
5555

5656
--- SECTION SEPARATOR ---
57-
98. 0B
57+
5858

5959

6060
5 0.00B / 28.00B

0 commit comments

Comments
 (0)