diff --git a/src/display/components/layout.rs b/src/display/components/layout.rs index 1f20f68..e5ca069 100644 --- a/src/display/components/layout.rs +++ b/src/display/components/layout.rs @@ -25,16 +25,18 @@ pub struct Layout<'a> { impl<'a> Layout<'a> { fn progressive_split(&self, rect: Rect, splits: Vec) -> Vec { - splits.into_iter().fold(vec![rect], |mut layout, direction| { - let last_rect = layout.pop().unwrap(); - let mut halves = ::tui::layout::Layout::default() - .direction(direction) - .margin(0) - .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) - .split(last_rect); - layout.append(&mut halves); - layout - }) + splits + .into_iter() + .fold(vec![rect], |mut layout, direction| { + let last_rect = layout.pop().unwrap(); + let mut halves = ::tui::layout::Layout::default() + .direction(direction) + .margin(0) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .split(last_rect); + layout.append(&mut halves); + layout + }) } fn build_layout(&self, rect: Rect) -> Vec { if rect.height < FIRST_HEIGHT_BREAKPOINT && rect.width < FIRST_WIDTH_BREAKPOINT { diff --git a/src/main.rs b/src/main.rs index 3921a66..efa1fad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ fn try_main() -> Result<(), failure::Error> { "Sorry, no implementations for platforms other than linux yet :( - PRs welcome!" ); - use os::{get_input}; + use os::get_input; let opt = Opt::from_args(); let os_input = get_input(opt)?; let stdout = match io::stdout().into_raw_mode() { @@ -66,7 +66,7 @@ pub struct OsInput { pub get_open_sockets: fn() -> HashMap, pub keyboard_events: Box + Send>, pub lookup_addr: Box Option + Send>, - pub on_winch: Box)+ Send>, + pub on_winch: Box) + Send>, pub cleanup: Box, } diff --git a/src/os/linux.rs b/src/os/linux.rs index cc2d883..f231d12 100644 --- a/src/os/linux.rs +++ b/src/os/linux.rs @@ -9,8 +9,8 @@ use ::std::collections::HashMap; use ::std::net::IpAddr; use ::std::time; -use signal_hook::iterator::Signals; use ::procfs::FDTarget; +use signal_hook::iterator::Signals; use crate::network::{Connection, Protocol}; use crate::{Opt, OsInput}; @@ -27,16 +27,15 @@ impl Iterator for KeyboardEvents { } } -fn get_datalink_channel(interface: &NetworkInterface) -> Result, failure::Error> { +fn get_datalink_channel( + interface: &NetworkInterface, +) -> Result, failure::Error> { let mut config = Config::default(); config.read_timeout = Some(time::Duration::new(0, 1)); match datalink::channel(interface, config) { Ok(Ethernet(_tx, rx)) => Ok(rx), Ok(_) => failure::bail!("Unknown interface type"), - Err(e) => failure::bail!( - "Failed to listen to network interface: {}", - e - ), + Err(e) => failure::bail!("Failed to listen to network interface: {}", e), } } @@ -90,7 +89,7 @@ fn lookup_addr(ip: &IpAddr) -> Option { ::dns_lookup::lookup_addr(ip).ok() } -fn sigwinch () -> (Box) + Send>, Box) { +fn sigwinch() -> (Box) + Send>, Box) { let signals = Signals::new(&[signal_hook::SIGWINCH]).unwrap(); let on_winch = { let signals = signals.clone(); @@ -110,7 +109,6 @@ fn sigwinch () -> (Box) + Send>, Box) { } pub fn get_input(opt: Opt) -> Result { - let keyboard_events = Box::new(KeyboardEvents); let network_interface = match get_interface(&opt.interface) { Some(interface) => interface, diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs index 1cd5fa4..831d4fb 100644 --- a/src/tests/fakes/fake_input.rs +++ b/src/tests/fakes/fake_input.rs @@ -22,15 +22,13 @@ impl Iterator for KeyboardEvents { type Item = Event; fn next(&mut self) -> Option { match self.events.pop() { - Some(ev) => { - match ev { - Some(ev) => Some(ev), - None => { - thread::sleep(time::Duration::from_secs(1)); - self.next() - } + Some(ev) => match ev { + Some(ev) => Some(ev), + None => { + thread::sleep(time::Duration::from_secs(1)); + self.next() } - } + }, None => None, } } @@ -61,23 +59,18 @@ impl DataLinkReceiver for NetworkFrames { // this is so the tests pass consistently thread::sleep(time::Duration::from_millis(500)); } - match self.current_index < self.packets.len() { - true => { - let action = self.next_packet(); - match action { - Some(packet) => { - Ok(&packet[..]) - } - None => { - thread::sleep(time::Duration::from_secs(1)); - Ok(&[][..]) - } + if self.current_index < self.packets.len() { + let action = self.next_packet(); + match action { + Some(packet) => Ok(&packet[..]), + None => { + thread::sleep(time::Duration::from_secs(1)); + Ok(&[][..]) } } - false => { - thread::sleep(time::Duration::from_secs(1)); - Ok(&[][..]) - } + } else { + thread::sleep(time::Duration::from_secs(1)); + Ok(&[][..]) } } }