diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 8c91731..e327be5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use os::OnSigWinch; use ::pnet::datalink::{DataLinkReceiver, NetworkInterface}; use ::std::collections::HashMap; -use ::std::sync::atomic::{AtomicBool, Ordering}; +use ::std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use ::std::sync::{Arc, Mutex}; use ::std::thread::park_timeout; use ::std::{thread, time}; @@ -121,6 +121,7 @@ where { let running = Arc::new(AtomicBool::new(true)); let paused = Arc::new(AtomicBool::new(false)); + let ui_offset = Arc::new(AtomicUsize::new(0)); let dns_shown = opts.show_dns; let mut active_threads = vec![]; @@ -144,11 +145,17 @@ where .spawn({ let ui = ui.clone(); let paused = paused.clone(); + let ui_offset = ui_offset.clone(); + move || { on_winch({ Box::new(move || { let mut ui = ui.lock().unwrap(); - ui.draw(paused.load(Ordering::SeqCst), dns_shown); + ui.draw( + paused.load(Ordering::SeqCst), + dns_shown, + ui_offset.load(Ordering::SeqCst), + ); }) }); } @@ -162,7 +169,11 @@ where .spawn({ let running = running.clone(); let paused = paused.clone(); + let ui_offset = ui_offset.clone(); + let network_utilization = network_utilization.clone(); + let ui = ui.clone(); + move || { while running.load(Ordering::Acquire) { let render_start_time = Instant::now(); @@ -185,13 +196,14 @@ where { let mut ui = ui.lock().unwrap(); let paused = paused.load(Ordering::SeqCst); + let ui_offset = ui_offset.load(Ordering::SeqCst); if !paused { ui.update_state(sockets_to_procs, utilization, ip_to_host); } if raw_mode { ui.output_text(&mut write_to_stdout); } else { - ui.draw(paused, dns_shown); + ui.draw(paused, dns_shown, ui_offset); } } let render_duration = render_start_time.elapsed(); @@ -213,8 +225,11 @@ where .spawn({ let running = running.clone(); let display_handler = display_handler.thread().clone(); + move || { for evt in keyboard_events { + let mut ui = ui.lock().unwrap(); + match evt { Event::Key(Key::Ctrl('c')) | Event::Key(Key::Char('q')) => { running.store(false, Ordering::Release); @@ -226,6 +241,12 @@ where paused.fetch_xor(true, Ordering::SeqCst); display_handler.unpark(); } + Event::Key(Key::Char('\t')) => { + let table_count = ui.get_table_count(); + let new = ui_offset.load(Ordering::SeqCst) + 1 % table_count; + ui_offset.store(new, Ordering::SeqCst); + ui.draw(paused.load(Ordering::SeqCst), dns_shown, new); + } _ => (), }; } |