mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #2771 from E3uka/next_prev
more: add next-line and prev-line command.
This commit is contained in:
commit
5bcc53ecde
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();
|
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) => {
|
Event::Resize(col, row) => {
|
||||||
pager.page_resize(col, row);
|
pager.page_resize(col, row);
|
||||||
}
|
}
|
||||||
|
@ -301,6 +317,17 @@ impl<'a> Pager<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn page_down(&mut self) {
|
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());
|
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());
|
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.
|
// TODO: Deal with column size changes.
|
||||||
fn page_resize(&mut self, _: u16, row: u16) {
|
fn page_resize(&mut self, _: u16, row: u16) {
|
||||||
self.content_rows = row.saturating_sub(1);
|
self.content_rows = row.saturating_sub(1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue