Skip to content

Commit 2cea747

Browse files
committed
add line rendering fallback
1 parent a390fd0 commit 2cea747

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/uu/more/src/more.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ impl<'a> Pager<'a> {
631631
}
632632

633633
// TODO: Deal with column size changes.
634-
fn page_resize(&mut self, _: u16, row: u16, option_line: Option<u16>) {
634+
fn page_resize(&mut self, _col: u16, row: u16, option_line: Option<u16>) {
635635
if option_line.is_none() {
636636
self.content_rows = row.saturating_sub(1) as usize;
637637
};
@@ -654,19 +654,20 @@ impl<'a> Pager<'a> {
654654
// Ensure we have enough lines loaded for display
655655
self.read_until_line(self.upper_mark + self.content_rows)?;
656656

657+
// Display lines until we've filled the screen
657658
let mut visible_lines = 0;
658659
let mut index = self.upper_mark;
659-
660-
// Display lines until we've filled the screen or run out of lines
661-
while visible_lines < self.content_rows && index < self.lines.len() {
660+
let fallback = "~\n".to_string();
661+
while visible_lines < self.content_rows {
662662
// Skip this line if it should be squeezed
663663
if self.should_squeeze_line(index) {
664664
self.lines_squeezed += 1;
665665
index += 1;
666666
continue;
667667
}
668-
// Display the line and move to next
669-
stdout.write_all(format!("\r{}", self.lines[index]).as_bytes())?;
668+
// Display the line
669+
let line = self.lines.get(index).unwrap_or(&fallback);
670+
stdout.write_all(format!("\r{}", line).as_bytes())?;
670671
visible_lines += 1;
671672
index += 1;
672673
}
@@ -692,7 +693,7 @@ impl<'a> Pager<'a> {
692693
/// with appropriate progress information and user feedback
693694
fn draw_prompt(&mut self, stdout: &mut impl Write, wrong_key: Option<char>) {
694695
// Calculate the index of the last visible line
695-
let lower_mark = (self.upper_mark + self.content_rows).min(self.lines.len());
696+
let lower_mark = (self.upper_mark + self.content_rows).min(self.lines.len() - 1);
696697

697698
// Determine progress information to display
698699
// - Show next file name when at EOF and there is a next file

0 commit comments

Comments
 (0)