1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 21:47:46 +00:00

more: simplify main loop

This commit is contained in:
Terts Diepraam 2021-05-29 12:42:46 +02:00
parent 101e55702c
commit 40ee9023e8

View file

@ -215,6 +215,9 @@ fn more(buff: &str, mut stdout: &mut Stdout, is_last: bool) {
line_count, line_count,
); );
// Specifies whether we have reached the end of the file and should
// return on the next keypress. However, we immediately return when
// this is the last file.
let mut to_be_done = false; let mut to_be_done = false;
if lines_left == 0 && is_last { if lines_left == 0 && is_last {
if is_last { if is_last {
@ -224,7 +227,6 @@ fn more(buff: &str, mut stdout: &mut Stdout, is_last: bool) {
} }
} }
loop { loop {
if event::poll(Duration::from_millis(10)).unwrap() { if event::poll(Duration::from_millis(10)).unwrap() {
match event::read().unwrap() { match event::read().unwrap() {
@ -248,6 +250,16 @@ fn more(buff: &str, mut stdout: &mut Stdout, is_last: bool) {
modifiers: KeyModifiers::NONE, modifiers: KeyModifiers::NONE,
}) => { }) => {
upper_mark = upper_mark.saturating_add(rows.saturating_sub(1)); upper_mark = upper_mark.saturating_add(rows.saturating_sub(1));
}
Event::Key(KeyEvent {
code: KeyCode::Up,
modifiers: KeyModifiers::NONE,
}) => {
upper_mark = upper_mark.saturating_sub(rows.saturating_sub(1));
}
_ => continue,
}
lines_left = line_count.saturating_sub(upper_mark + rows); lines_left = line_count.saturating_sub(upper_mark + rows);
draw( draw(
&mut upper_mark, &mut upper_mark,
@ -264,22 +276,6 @@ fn more(buff: &str, mut stdout: &mut Stdout, is_last: bool) {
to_be_done = true; to_be_done = true;
} }
} }
Event::Key(KeyEvent {
code: KeyCode::Up,
modifiers: KeyModifiers::NONE,
}) => {
upper_mark = upper_mark.saturating_sub(rows.saturating_sub(1));
draw(
&mut upper_mark,
rows,
&mut stdout,
lines.clone(),
line_count,
);
}
_ => continue,
}
}
} }
} }