mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
more: add next-line and prev-line command.
This commit is contained in:
parent
c7f7a222b9
commit
d2095edf6c
1 changed files with 35 additions and 0 deletions
|
@ -255,6 +255,22 @@ fn more(buff: &str, stdout: &mut Stdout, next_file: Option<&str>, silent: bool)
|
|||
}) => {
|
||||
pager.page_up();
|
||||
}
|
||||
Event::Key(KeyEvent {
|
||||
code: KeyCode::Char('j'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
}) => {
|
||||
if pager.should_close() {
|
||||
return;
|
||||
} else {
|
||||
pager.next_line();
|
||||
}
|
||||
}
|
||||
Event::Key(KeyEvent {
|
||||
code: KeyCode::Char('k'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
}) => {
|
||||
pager.prev_line();
|
||||
}
|
||||
Event::Resize(col, row) => {
|
||||
pager.page_resize(col, row);
|
||||
}
|
||||
|
@ -301,6 +317,17 @@ impl<'a> Pager<'a> {
|
|||
}
|
||||
|
||||
fn page_down(&mut self) {
|
||||
// If the next page down position __after redraw__ is greater than the total line count,
|
||||
// the upper mark must not grow past top of the screen at the end of the open file.
|
||||
if self
|
||||
.upper_mark
|
||||
.saturating_add(self.content_rows as usize * 2)
|
||||
.ge(&self.line_count)
|
||||
{
|
||||
self.upper_mark = self.line_count - self.content_rows as usize;
|
||||
return;
|
||||
}
|
||||
|
||||
self.upper_mark = self.upper_mark.saturating_add(self.content_rows.into());
|
||||
}
|
||||
|
||||
|
@ -308,6 +335,14 @@ impl<'a> Pager<'a> {
|
|||
self.upper_mark = self.upper_mark.saturating_sub(self.content_rows.into());
|
||||
}
|
||||
|
||||
fn next_line(&mut self) {
|
||||
self.upper_mark = self.upper_mark.saturating_add(1);
|
||||
}
|
||||
|
||||
fn prev_line(&mut self) {
|
||||
self.upper_mark = self.upper_mark.saturating_sub(1);
|
||||
}
|
||||
|
||||
// TODO: Deal with column size changes.
|
||||
fn page_resize(&mut self, _: u16, row: u16) {
|
||||
self.content_rows = row.saturating_sub(1);
|
||||
|
|
Loading…
Reference in a new issue