summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorRupert Rutledge <eosis2 [at] gmail.com>2020-05-19 21:24:03 +0100
committerRupert Rutledge <eosis2 [at] gmail.com>2020-05-19 21:26:25 +0100
commitd897e14eae9c39c0bd64a775acbc6c5dedfbdbdc (patch)
treea5f934775f6a4978f89d33498946030754d38bf9 /src/main.rs
parent098af1f7befaabb5f129a4bd70a070daa411ce86 (diff)
Use correct elapsed time when resizing the terminal
- Split the logic for determining the elapsed time into a function as it was called in different placed in main.rs.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 62c9621..a52642c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,7 +6,7 @@ mod os;
#[cfg(test)]
mod tests;
-use display::{RawTerminalBackend, Ui};
+use display::{elapsed_time, RawTerminalBackend, Ui};
use network::{
dns::{self, IpTable},
Connection, LocalSocket, Sniffer, Utilization,
@@ -147,14 +147,21 @@ where
.spawn({
let ui = ui.clone();
let paused = paused.clone();
+ let cumulative_time = cumulative_time.clone();
+ let last_start_time = last_start_time.clone();
move || {
on_winch({
Box::new(move || {
let mut ui = ui.lock().unwrap();
+ let paused = paused.load(Ordering::SeqCst);
ui.draw(
- paused.load(Ordering::SeqCst),
+ paused,
dns_shown,
- std::time::Duration::new(131, 0),
+ elapsed_time(
+ *last_start_time.read().unwrap(),
+ *cumulative_time.read().unwrap(),
+ paused,
+ ),
);
})
});
@@ -198,12 +205,11 @@ where
if !paused {
ui.update_state(sockets_to_procs, utilization, ip_to_host);
}
- let elapsed_time = if paused {
- *cumulative_time.read().unwrap()
- } else {
- *cumulative_time.read().unwrap()
- + last_start_time.read().unwrap().elapsed()
- };
+ let elapsed_time = elapsed_time(
+ *last_start_time.read().unwrap(),
+ *cumulative_time.read().unwrap(),
+ paused,
+ );
if raw_mode {
ui.output_text(&mut write_to_stdout);