diff options
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/components/help_text.rs | 20 | ||||
-rw-r--r-- | src/display/components/layout.rs | 4 | ||||
-rw-r--r-- | src/display/ui.rs | 12 |
3 files changed, 27 insertions, 9 deletions
diff --git a/src/display/components/help_text.rs b/src/display/components/help_text.rs index 2b49551..7d66ad8 100644 --- a/src/display/components/help_text.rs +++ b/src/display/components/help_text.rs @@ -9,10 +9,14 @@ pub struct HelpText { pub show_dns: bool, } -const TEXT_WHEN_PAUSED: &str = " Press <SPACE> to resume"; -const TEXT_WHEN_NOT_PAUSED: &str = " Press <SPACE> to pause"; +const FIRST_WIDTH_BREAKPOINT: u16 = 76; +const SECOND_WIDTH_BREAKPOINT: u16 = 54; + +const TEXT_WHEN_PAUSED: &str = " Press <SPACE> to resume."; +const TEXT_WHEN_NOT_PAUSED: &str = " Press <SPACE> to pause."; const TEXT_WHEN_DNS_NOT_SHOWN: &str = " (DNS queries hidden)."; const TEXT_WHEN_DNS_SHOWN: &str = " (DNS queries shown)."; +const TEXT_TAB_TIP: &str = " Use <TAB> to rearrange tables."; impl HelpText { pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) { @@ -23,14 +27,22 @@ impl HelpText { TEXT_WHEN_NOT_PAUSED }; - let dns_content = if self.show_dns { + let dns_content = if rect.width <= FIRST_WIDTH_BREAKPOINT { + "" + } else if self.show_dns { TEXT_WHEN_DNS_SHOWN } else { TEXT_WHEN_DNS_NOT_SHOWN }; + let tab_text = if rect.width <= SECOND_WIDTH_BREAKPOINT { + "" + } else { + TEXT_TAB_TIP + }; + [Text::styled( - format!("{}{}", pause_content, dns_content), + format!("{}{}{}", pause_content, tab_text, dns_content), Style::default().modifier(Modifier::BOLD), )] }; diff --git a/src/display/components/layout.rs b/src/display/components/layout.rs index d3edb81..51c0175 100644 --- a/src/display/components/layout.rs +++ b/src/display/components/layout.rs @@ -100,12 +100,12 @@ impl<'a> Layout<'a> { } } - pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) { + pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect, ui_offset: usize) { let (top, app, bottom) = top_app_and_bottom_split(rect); let layout_slots = self.build_layout(app); for i in 0..layout_slots.len() { if let Some(rect) = layout_slots.get(i) { - if let Some(child) = self.children.get(i) { + if let Some(child) = self.children.get((i + ui_offset) % self.children.len()) { child.render(frame, *rect); } } diff --git a/src/display/ui.rs b/src/display/ui.rs index 54db7fb..6361a7f 100644 --- a/src/display/ui.rs +++ b/src/display/ui.rs @@ -11,6 +11,7 @@ use ::std::net::IpAddr; use crate::RenderOpts; use chrono::prelude::*; +use std::time::Duration; pub struct Ui<B> where @@ -61,7 +62,7 @@ where display_connection_string( connection, ip_to_host, - &connection_network_data.interface_name + &connection_network_data.interface_name, ), connection_network_data.total_bytes_uploaded, connection_network_data.total_bytes_downloaded, @@ -80,7 +81,7 @@ where } } - pub fn draw(&mut self, paused: bool, show_dns: bool, elapsed_time: std::time::Duration) { + pub fn draw(&mut self, paused: bool, show_dns: bool, elapsed_time: Duration, ui_offset: usize) { let state = &self.state; let children = self.get_tables_to_display(); self.terminal @@ -97,7 +98,7 @@ where children, footer: help_text, }; - layout.render(&mut frame, size); + layout.render(&mut frame, size, ui_offset); }) .unwrap(); } @@ -129,6 +130,11 @@ where } children } + + pub fn get_table_count(&self) -> usize { + self.get_tables_to_display().len() + } + pub fn update_state( &mut self, connections_to_procs: HashMap<LocalSocket, String>, |