diff options
author | Aram Drevekenin <aram@poor.dev> | 2019-10-14 17:35:25 +0200 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2019-10-14 17:35:25 +0200 |
commit | d1a5ef1836ab80fc3dc69b936afe94dd2b1bf329 (patch) | |
tree | 1dab7ca7a60548d98debd88af0e086d93769d76d /src | |
parent | e6e31e6d4eabd49fe42da74a6eb2f9cdaaf88444 (diff) |
style(formatting): rustfmt
Diffstat (limited to 'src')
-rw-r--r-- | src/display/components/mod.rs | 8 | ||||
-rw-r--r-- | src/display/components/table.rs | 24 | ||||
-rw-r--r-- | src/display/components/total_bandwidth.rs | 2 | ||||
-rw-r--r-- | src/display/mod.rs | 4 | ||||
-rw-r--r-- | src/display/ui.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 18 | ||||
-rw-r--r-- | src/os/linux.rs | 9 | ||||
-rw-r--r-- | src/tests/fakes/fake_input.rs | 4 | ||||
-rw-r--r-- | src/tests/mod.rs | 4 |
9 files changed, 45 insertions, 30 deletions
diff --git a/src/display/components/mod.rs b/src/display/components/mod.rs index 1be5a33..a0e226d 100644 --- a/src/display/components/mod.rs +++ b/src/display/components/mod.rs @@ -1,9 +1,9 @@ -mod table; +mod display_bandwidth; mod layout; +mod table; mod total_bandwidth; -mod display_bandwidth; -pub use table::*; +pub use display_bandwidth::*; pub use layout::*; +pub use table::*; pub use total_bandwidth::*; -pub use display_bandwidth::*; diff --git a/src/display/components/table.rs b/src/display/components/table.rs index 6cfc2d7..6f22ea5 100644 --- a/src/display/components/table.rs +++ b/src/display/components/table.rs @@ -6,7 +6,7 @@ use ::tui::style::{Color, Style}; use ::tui::terminal::Frame; use ::tui::widgets::{Block, Borders, Row, Widget}; -use crate::display::{DisplayBandwidth, Bandwidth, UIState}; +use crate::display::{Bandwidth, DisplayBandwidth, UIState}; use crate::network::Connection; use ::std::net::Ipv4Addr; @@ -20,7 +20,6 @@ const FIRST_COLUMN_WIDTHS: [u16; 4] = [20, 30, 40, 50]; const SECOND_COLUMN_WIDTHS: [u16; 1] = [20]; const THIRD_COLUMN_WIDTHS: [u16; 4] = [10, 20, 20, 20]; - fn display_upload_and_download(bandwidth: &impl Bandwidth) -> String { format!( "{}/{}", @@ -74,8 +73,11 @@ pub struct Table<'a> { rows: Vec<Vec<String>>, } -impl <'a>Table<'a> { - pub fn create_connections_table(state: &UIState, ip_to_host: &HashMap<Ipv4Addr, String>) -> Self { +impl<'a> Table<'a> { + pub fn create_connections_table( + state: &UIState, + ip_to_host: &HashMap<Ipv4Addr, String>, + ) -> Self { let mut connections_list = Vec::from_iter(&state.connections); sort_by_bandwidth(&mut connections_list); let connections_rows = connections_list @@ -117,7 +119,10 @@ impl <'a>Table<'a> { rows: processes_rows, } } - pub fn create_remote_ips_table(state: &UIState, ip_to_host: &HashMap<Ipv4Addr, String>) -> Self { + pub fn create_remote_ips_table( + state: &UIState, + ip_to_host: &HashMap<Ipv4Addr, String>, + ) -> Self { let mut remote_ips_list = Vec::from_iter(&state.remote_ips); sort_by_bandwidth(&mut remote_ips_list); let remote_ips_rows = remote_ips_list @@ -132,8 +137,7 @@ impl <'a>Table<'a> { }) .collect(); let remote_ips_title = "Utilization by remote ip"; - let remote_ips_column_names = - &["Remote Address", "Connection Count", "Rate Up/Down"]; + let remote_ips_column_names = &["Remote Address", "Connection Count", "Rate Up/Down"]; Table { title: remote_ips_title, column_names: remote_ips_column_names, @@ -150,7 +154,11 @@ impl <'a>Table<'a> { } else if rect.width < THIRD_WIDTH_BREAKPOINT { vec![FIRST_COLUMN_WIDTHS[2], THIRD_COLUMN_WIDTHS[2]] } else { - vec![FIRST_COLUMN_WIDTHS[3], SECOND_COLUMN_WIDTHS[0], THIRD_COLUMN_WIDTHS[2]] + vec![ + FIRST_COLUMN_WIDTHS[3], + SECOND_COLUMN_WIDTHS[0], + THIRD_COLUMN_WIDTHS[2], + ] }; let column_names = if rect.width < THIRD_WIDTH_BREAKPOINT { diff --git a/src/display/components/total_bandwidth.rs b/src/display/components/total_bandwidth.rs index 823b972..fd3d9c6 100644 --- a/src/display/components/total_bandwidth.rs +++ b/src/display/components/total_bandwidth.rs @@ -10,7 +10,7 @@ pub struct TotalBandwidth<'a> { pub state: &'a UIState, } -impl<'a>TotalBandwidth<'a> { +impl<'a> TotalBandwidth<'a> { pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) { let title_text = [Text::styled( format!( diff --git a/src/display/mod.rs b/src/display/mod.rs index 73b3a9c..8d24159 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -1,7 +1,7 @@ +mod components; mod ui; mod ui_state; -mod components; +pub use components::*; pub use ui::*; pub use ui_state::*; -pub use components::*; diff --git a/src/display/ui.rs b/src/display/ui.rs index 8832de7..b31f8ea 100644 --- a/src/display/ui.rs +++ b/src/display/ui.rs @@ -3,9 +3,9 @@ use ::std::collections::HashMap; use ::tui::backend::Backend; use ::tui::Terminal; +use crate::display::components::{Layout, Table, TotalBandwidth}; use crate::display::UIState; use crate::network::{Connection, Utilization}; -use crate::display::components::{Table, Layout, TotalBandwidth}; use ::std::net::Ipv4Addr; use ::std::sync::atomic::{AtomicBool, Ordering}; diff --git a/src/main.rs b/src/main.rs index d8d84ce..8d21884 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,7 +54,9 @@ fn try_main() -> Result<(), failure::Error> { let opt = Opt::from_args(); let stdout = match io::stdout().into_raw_mode() { Ok(stdout) => stdout, - Err(_) => failure::bail!("Failed to get stdout: what does not (yet) support piping, is it being piped?") + Err(_) => failure::bail!( + "Failed to get stdout: what does not (yet) support piping, is it being piped?" + ), }; let terminal_backend = TermionBackend::new(stdout); @@ -97,7 +99,7 @@ where { let running = Arc::new(AtomicBool::new(true)); - let keyboard_events = os_input.keyboard_events; // TODO: as methods in os_interface + let keyboard_events = os_input.keyboard_events; let get_open_sockets = os_input.get_open_sockets; let lookup_addr = os_input.lookup_addr; let on_winch = os_input.on_winch; @@ -123,12 +125,12 @@ where let resize_handler = thread::spawn({ let ui = ui.clone(); move || { - on_winch({ - Box::new(move || { - let mut ui = ui.lock().unwrap(); - ui.draw(); - }) - }); + on_winch({ + Box::new(move || { + let mut ui = ui.lock().unwrap(); + ui.draw(); + }) + }); } }); diff --git a/src/os/linux.rs b/src/os/linux.rs index d54ffac..fd8905a 100644 --- a/src/os/linux.rs +++ b/src/os/linux.rs @@ -90,8 +90,11 @@ pub fn lookup_addr(ip: &IpAddr) -> Option<String> { ::dns_lookup::lookup_addr(ip).ok() } -pub fn on_winch <F>(cb: F ) -where F: Fn() + Send + Sync + 'static +pub fn on_winch<F>(cb: F) +where + F: Fn() + Send + Sync + 'static, { - unsafe { signal_hook::register(signal_hook::SIGWINCH, cb).unwrap();} + unsafe { + signal_hook::register(signal_hook::SIGWINCH, cb).unwrap(); + } } diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs index 11d2a2a..cb2710a 100644 --- a/src/tests/fakes/fake_input.rs +++ b/src/tests/fakes/fake_input.rs @@ -151,7 +151,9 @@ pub fn create_fake_lookup_addr( }) } -pub fn create_fake_on_winch(should_send_winch_event: bool) -> Box<Fn(Box<Fn() + Send + Sync + 'static>) + Send + Sync + 'static> { +pub fn create_fake_on_winch( + should_send_winch_event: bool, +) -> Box<Fn(Box<Fn() + Send + Sync + 'static>) + Send + Sync + 'static> { Box::new(move |cb| { if should_send_winch_event { thread::sleep(time::Duration::from_secs(1)); diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 2470cfa..bf1bc1e 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -2,8 +2,8 @@ mod fakes; use fakes::TerminalEvent::*; use fakes::{ - create_fake_lookup_addr, create_fake_on_winch, get_interface, get_open_sockets, - KeyboardEvents, NetworkFrames, TestBackend, + create_fake_lookup_addr, create_fake_on_winch, get_interface, get_open_sockets, KeyboardEvents, + NetworkFrames, TestBackend, }; use ::insta::assert_snapshot; |