Skip to content

Commit

Permalink
feat: Added page up and page down.
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Willems <[email protected]>
  • Loading branch information
jw committed Mar 1, 2024
1 parent 83f706b commit 3f9c6f2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ impl App {
self.scrollbar_state = self.scrollbar_state.position(i);
}

pub fn next_page(&mut self) {
let i = match self.state.selected() {
Some(i) => {
if i >= self.processes.len() - 1 {
0
} else {
i + 20
}
}
None => 0,
};
self.state.select(Some(i));
self.scrollbar_state = self.scrollbar_state.position(i);
}

pub fn previous(&mut self) {
let i = match self.state.selected() {
Some(i) => {
Expand All @@ -84,6 +99,23 @@ impl App {
self.state.select(Some(i));
self.scrollbar_state = self.scrollbar_state.position(i);
}

pub fn previous_page(&mut self) {
let i = match self.state.selected() {
Some(i) =>
{
#[allow(clippy::absurd_extreme_comparisons)]
if i - 20 <= 0 {
self.processes.len() - 1
} else {
i - 20
}
}
None => 0,
};
self.state.select(Some(i));
self.scrollbar_state = self.scrollbar_state.position(i);
}
}

#[allow(dead_code)]
Expand Down Expand Up @@ -159,7 +191,9 @@ fn handle_events(_terminal: &mut Terminal, app: &mut App) -> Result<ControlFlow<
match key.code {
Char('q') | Esc => return Ok(ControlFlow::Break(())),
Char('j') | Down => app.next(),
PageDown => app.next_page(),
Char('k') | Up => app.previous(),
PageUp => app.previous_page(),
_ => {}
}
}
Expand Down

0 comments on commit 3f9c6f2

Please sign in to comment.