From 49508f140a1b35bef80993cc929905ac13ff3e26 Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:51:24 +0800 Subject: [PATCH] Rename `ui_offset` -> `table_cycle_offset` --- src/display/components/layout.rs | 7 +++++-- src/display/ui.rs | 4 ++-- src/main.rs | 14 +++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/display/components/layout.rs b/src/display/components/layout.rs index e282bba1..7fa68013 100644 --- a/src/display/components/layout.rs +++ b/src/display/components/layout.rs @@ -99,12 +99,15 @@ impl Layout<'_> { } } - pub fn render(&self, frame: &mut Frame, rect: Rect, ui_offset: usize) { + pub fn render(&self, frame: &mut Frame, rect: Rect, table_cycle_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 + ui_offset) % self.children.len()) { + if let Some(child) = self + .children + .get((i + table_cycle_offset) % self.children.len()) + { child.render(frame, *rect); } } diff --git a/src/display/ui.rs b/src/display/ui.rs index 9b533410..0f94cb67 100644 --- a/src/display/ui.rs +++ b/src/display/ui.rs @@ -127,7 +127,7 @@ where write_to_stdout(""); } - pub fn draw(&mut self, paused: bool, elapsed_time: Duration, ui_offset: usize) { + pub fn draw(&mut self, paused: bool, elapsed_time: Duration, table_cycle_offset: usize) { let layout = Layout { header: HeaderDetails { state: &self.state, @@ -141,7 +141,7 @@ where }, }; self.terminal - .draw(|frame| layout.render(frame, frame.area(), ui_offset)) + .draw(|frame| layout.render(frame, frame.area(), table_cycle_offset)) .unwrap(); } diff --git a/src/main.rs b/src/main.rs index c407cc63..cbac481d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,7 @@ where let paused = Arc::new(AtomicBool::new(false)); let last_start_time = Arc::new(RwLock::new(Instant::now())); let cumulative_time = Arc::new(RwLock::new(Duration::new(0, 0))); - let ui_offset = Arc::new(AtomicUsize::new(0)); + let table_cycle_offset = Arc::new(AtomicUsize::new(0)); let mut active_threads = vec![]; @@ -112,7 +112,7 @@ where .spawn({ let running = running.clone(); let paused = paused.clone(); - let ui_offset = ui_offset.clone(); + let table_cycle_offset = table_cycle_offset.clone(); let network_utilization = network_utilization.clone(); let last_start_time = last_start_time.clone(); @@ -139,7 +139,7 @@ where let mut ui = ui.lock().unwrap(); let paused = paused.load(Ordering::SeqCst); - let ui_offset = ui_offset.load(Ordering::SeqCst); + let table_cycle_offset = table_cycle_offset.load(Ordering::SeqCst); if !paused { ui.update_state(sockets_to_procs, utilization, ip_to_host); } @@ -152,7 +152,7 @@ where if raw_mode { ui.output_text(&mut write_to_stdout); } else { - ui.draw(paused, elapsed_time, ui_offset); + ui.draw(paused, elapsed_time, table_cycle_offset); } let render_duration = render_start_time.elapsed(); @@ -188,7 +188,7 @@ where *cumulative_time.read().unwrap(), paused, ), - ui_offset.load(Ordering::SeqCst), + table_cycle_offset.load(Ordering::SeqCst), ); } Event::Key(KeyEvent { @@ -249,8 +249,8 @@ where paused, ); let table_count = ui.get_table_count(); - let new = ui_offset.load(Ordering::SeqCst) + 1 % table_count; - ui_offset.store(new, Ordering::SeqCst); + let new = table_cycle_offset.load(Ordering::SeqCst) + 1 % table_count; + table_cycle_offset.store(new, Ordering::SeqCst); ui.draw(paused, elapsed_time, new); } _ => (),