summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorLouis Lesage <31346705+Louis-Lesage@users.noreply.github.com>2020-05-17 16:40:04 -0400
committerGitHub <noreply@github.com>2020-05-17 22:40:04 +0200
commit55e8885302172ccf0a79bc9829d339acfdc3564d (patch)
treec0c96671526c7623d9d036877cd9f123e7167e9c /src/display
parente6bb39a5e992498e00bc3af47d92352865e3223d (diff)
feat(layout): 'Window' ordering ability (#118)
* Window ordering ability Added ability to change display order of the windows using tab. Added a help tooltip. * fix redundant clone * fix fmt check * cargo fmt fix 2 * Fixed help layout and added tests * Fix fmt check
Diffstat (limited to 'src/display')
-rw-r--r--src/display/components/help_text.rs20
-rw-r--r--src/display/components/layout.rs4
-rw-r--r--src/display/ui.rs11
3 files changed, 26 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 c047774..79186cd 100644
--- a/src/display/components/layout.rs
+++ b/src/display/components/layout.rs
@@ -99,12 +99,12 @@ impl<'a> Layout<'a> {
self.build_three_children_layout(rect)
}
}
- 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 68f133a..600a6db 100644
--- a/src/display/ui.rs
+++ b/src/display/ui.rs
@@ -61,7 +61,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,
@@ -79,7 +79,7 @@ where
));
}
}
- pub fn draw(&mut self, paused: bool, show_dns: bool) {
+ pub fn draw(&mut self, paused: bool, show_dns: bool, ui_offset: usize) {
let state = &self.state;
let children = self.get_tables_to_display();
self.terminal
@@ -95,7 +95,7 @@ where
children,
footer: help_text,
};
- layout.render(&mut frame, size);
+ layout.render(&mut frame, size, ui_offset);
})
.unwrap();
}
@@ -127,6 +127,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>,