@@ -2,7 +2,7 @@ use super::theme::Theme;
22use crate :: net:: { self , IfStats , NetRate } ;
33use crate :: stat:: { self , PortStat } ;
44use std:: collections:: VecDeque ;
5- use std:: time:: Instant ;
5+ use std:: time:: { Duration , Instant } ;
66
77use std:: collections:: HashMap ;
88
@@ -77,6 +77,13 @@ impl TableColumn {
7777
7878pub const BAR_WIDTH : usize = 12 ;
7979
80+ /// Stats refresh interval bounds (seconds). Floor matches the 200ms event-poll
81+ /// so input stays responsive even at the fastest setting.
82+ pub const REFRESH_DEFAULT_SECS : f64 = 1.0 ;
83+ const REFRESH_MIN_SECS : f64 = 0.2 ;
84+ const REFRESH_MAX_SECS : f64 = 10.0 ;
85+ const REFRESH_STEP_SECS : f64 = 0.5 ;
86+
8087/// All counter names that can be added as extra columns.
8188pub const EXTRA_COUNTERS : & [ & str ] = & [
8289 "send_bytes" ,
@@ -274,7 +281,6 @@ pub struct App {
274281 prev_stats : Vec < PortStat > ,
275282 prev_ifstats : Vec < IfStats > ,
276283 prev_time : Instant ,
277- pub elapsed : f64 ,
278284 pub rolling_avg : RollingAvgState ,
279285 pub show_rolling_avg : bool ,
280286 pub show_window_input : bool ,
@@ -285,6 +291,7 @@ pub struct App {
285291 pub h_scroll : usize ,
286292 pub h_scroll_max : usize ,
287293 pub table_offset : usize ,
294+ pub refresh_interval : Duration ,
288295 cached_display : Vec < PortThroughput > ,
289296}
290297
@@ -346,7 +353,6 @@ impl App {
346353 prev_stats : stats,
347354 prev_ifstats : ifstats,
348355 prev_time : Instant :: now ( ) ,
349- elapsed : 1.0 ,
350356 rolling_avg : RollingAvgState :: new ( ROLLING_AVG_DEFAULT_WINDOW ) ,
351357 show_rolling_avg : false ,
352358 show_window_input : false ,
@@ -357,6 +363,7 @@ impl App {
357363 h_scroll : 0 ,
358364 h_scroll_max : 0 ,
359365 table_offset : 0 ,
366+ refresh_interval : Duration :: from_secs_f64 ( REFRESH_DEFAULT_SECS ) ,
360367 cached_display : Vec :: new ( ) ,
361368 }
362369 }
@@ -370,7 +377,6 @@ impl App {
370377 if elapsed < 0.1 {
371378 return ;
372379 }
373- self . elapsed = elapsed;
374380 self . throughputs = compute_throughputs ( & self . prev_stats , & curr, elapsed) ;
375381 self . prev_stats = curr;
376382
@@ -474,6 +480,18 @@ impl App {
474480 }
475481 }
476482
483+ /// Slow the refresh by one step (longer interval), clamped to the max.
484+ pub fn increase_refresh_interval ( & mut self ) {
485+ let secs = ( self . refresh_interval . as_secs_f64 ( ) + REFRESH_STEP_SECS ) . min ( REFRESH_MAX_SECS ) ;
486+ self . refresh_interval = Duration :: from_secs_f64 ( secs) ;
487+ }
488+
489+ /// Speed the refresh up by one step (shorter interval), clamped to the min.
490+ pub fn decrease_refresh_interval ( & mut self ) {
491+ let secs = ( self . refresh_interval . as_secs_f64 ( ) - REFRESH_STEP_SECS ) . max ( REFRESH_MIN_SECS ) ;
492+ self . refresh_interval = Duration :: from_secs_f64 ( secs) ;
493+ }
494+
477495 pub fn open_window_input ( & mut self ) {
478496 self . window_input_buf = self . rolling_avg . window_secs . to_string ( ) ;
479497 self . show_window_input = true ;
0 commit comments