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:
parent
101e55702c
commit
40ee9023e8
1 changed files with 19 additions and 23 deletions
|
@ -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,37 +250,31 @@ 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));
|
||||||
lines_left = line_count.saturating_sub(upper_mark + rows);
|
|
||||||
draw(
|
|
||||||
&mut upper_mark,
|
|
||||||
rows,
|
|
||||||
&mut stdout,
|
|
||||||
lines.clone(),
|
|
||||||
line_count,
|
|
||||||
);
|
|
||||||
|
|
||||||
if lines_left == 0 {
|
|
||||||
if to_be_done || is_last {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
to_be_done = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Event::Key(KeyEvent {
|
Event::Key(KeyEvent {
|
||||||
code: KeyCode::Up,
|
code: KeyCode::Up,
|
||||||
modifiers: KeyModifiers::NONE,
|
modifiers: KeyModifiers::NONE,
|
||||||
}) => {
|
}) => {
|
||||||
upper_mark = upper_mark.saturating_sub(rows.saturating_sub(1));
|
upper_mark = upper_mark.saturating_sub(rows.saturating_sub(1));
|
||||||
draw(
|
|
||||||
&mut upper_mark,
|
|
||||||
rows,
|
|
||||||
&mut stdout,
|
|
||||||
lines.clone(),
|
|
||||||
line_count,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
|
lines_left = line_count.saturating_sub(upper_mark + rows);
|
||||||
|
draw(
|
||||||
|
&mut upper_mark,
|
||||||
|
rows,
|
||||||
|
&mut stdout,
|
||||||
|
lines.clone(),
|
||||||
|
line_count,
|
||||||
|
);
|
||||||
|
|
||||||
|
if lines_left == 0 {
|
||||||
|
if to_be_done || is_last {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
to_be_done = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue