summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRupert Rutledge <eosis2 [at] gmail.com>2020-04-26 19:36:02 +0100
committerRupert Rutledge <eosis2 [at] gmail.com>2020-04-26 19:36:02 +0100
commit8a2469f4ec340cb6104db6ef488438649f0c1d27 (patch)
treed383e1d5530da3521813f2a916782caf7c7b59da
parent5cb0c7690a098c40400f7d3ca18db789eadaeb5f (diff)
Split Header rendering into different sections
- Rename Bandwidth to HeaderDetails to indicate the added information it now contains. - Split the rendering function for the header into its constituent parts
-rw-r--r--src/display/components/layout.rs4
-rw-r--r--src/display/components/total_bandwidth.rs23
-rw-r--r--src/display/ui.rs4
3 files changed, 19 insertions, 12 deletions
diff --git a/src/display/components/layout.rs b/src/display/components/layout.rs
index c047774..c86211a 100644
--- a/src/display/components/layout.rs
+++ b/src/display/components/layout.rs
@@ -4,7 +4,7 @@ use ::tui::terminal::Frame;
use super::HelpText;
use super::Table;
-use super::TotalBandwidth;
+use super::HeaderDetails;
const FIRST_HEIGHT_BREAKPOINT: u16 = 30;
const FIRST_WIDTH_BREAKPOINT: u16 = 120;
@@ -26,7 +26,7 @@ fn top_app_and_bottom_split(rect: Rect) -> (Rect, Rect, Rect) {
}
pub struct Layout<'a> {
- pub header: TotalBandwidth<'a>,
+ pub header: HeaderDetails<'a>,
pub children: Vec<Table<'a>>,
pub footer: HelpText,
}
diff --git a/src/display/components/total_bandwidth.rs b/src/display/components/total_bandwidth.rs
index 844fb2a..a1968e5 100644
--- a/src/display/components/total_bandwidth.rs
+++ b/src/display/components/total_bandwidth.rs
@@ -6,14 +6,19 @@ use ::tui::widgets::{Paragraph, Text, Widget};
use crate::display::{DisplayBandwidth, UIState};
-pub struct TotalBandwidth<'a> {
+pub struct HeaderDetails<'a> {
pub state: &'a UIState,
pub elapsed_time: std::time::Duration,
pub paused: bool,
}
-impl<'a> TotalBandwidth<'a> {
+impl<'a> HeaderDetails<'a> {
pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) {
+ self.render_bandwidth(frame, rect);
+ self.render_elapsed_time(frame, rect);
+ }
+
+ fn render_bandwidth(&self, frame: &mut Frame<impl Backend>, rect: Rect) {
let c_mode = self.state.cumulative_mode;
let title_text = {
let paused_str = if self.paused { "[PAUSED]" } else { "" };
@@ -41,9 +46,11 @@ impl<'a> TotalBandwidth<'a> {
};
Paragraph::new(title_text.iter())
- .alignment(Alignment::Left)
- .render(frame, rect);
+ .alignment(Alignment::Left)
+ .render(frame, rect);
+ }
+ fn render_elapsed_time(&self, frame: &mut Frame<impl Backend>, rect: Rect) {
let elapsed_time_text = [Text::styled(
format!(
"Total Elapsed Time: {:02}:{:02}:{:02}",
@@ -52,11 +59,11 @@ impl<'a> TotalBandwidth<'a> {
self.elapsed_time.as_secs() % 60
),
Style::default()
- .fg(Color::LightBlue)
- .modifier(Modifier::BOLD),
+ .fg(Color::LightBlue)
+ .modifier(Modifier::BOLD),
)];
Paragraph::new(elapsed_time_text.iter())
- .alignment(Alignment::Right)
- .render(frame, rect);
+ .alignment(Alignment::Right)
+ .render(frame, rect);
}
}
diff --git a/src/display/ui.rs b/src/display/ui.rs
index cd87786..21ae49d 100644
--- a/src/display/ui.rs
+++ b/src/display/ui.rs
@@ -3,7 +3,7 @@ use ::std::collections::HashMap;
use ::tui::backend::Backend;
use ::tui::Terminal;
-use crate::display::components::{HelpText, Layout, Table, TotalBandwidth};
+use crate::display::components::{HelpText, Layout, Table, HeaderDetails};
use crate::display::UIState;
use crate::network::{display_connection_string, display_ip_or_host, LocalSocket, Utilization};
@@ -85,7 +85,7 @@ where
self.terminal
.draw(|mut frame| {
let size = frame.size();
- let total_bandwidth = TotalBandwidth {
+ let total_bandwidth = HeaderDetails {
state: &state,
elapsed_time,
paused,