Skip to content

Commit

Permalink
Rename ui_offset -> table_cycle_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
cyqsimon committed Oct 9, 2024
1 parent 1e36beb commit 49508f1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/display/components/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/display/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
}

Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];

Expand All @@ -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();
Expand All @@ -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);
}
Expand All @@ -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();
Expand Down Expand Up @@ -188,7 +188,7 @@ where
*cumulative_time.read().unwrap(),
paused,
),
ui_offset.load(Ordering::SeqCst),
table_cycle_offset.load(Ordering::SeqCst),
);
}
Event::Key(KeyEvent {
Expand Down Expand Up @@ -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);
}
_ => (),
Expand Down

0 comments on commit 49508f1

Please sign in to comment.