From 9802c8e7401cf79843c7ce96e98e794d93a0f497 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Thu, 26 Oct 2023 11:40:20 +0200 Subject: [PATCH] Fix bad rendering of border --- src/tile.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/tile.rs b/src/tile.rs index 0e2a76b..015327e 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -289,7 +289,7 @@ impl Tile { } // Autoscroll whene content arrives on stdout - self.scroll = self.stdout.len() as isize - 1 - (self.inner_size.1 as isize); + self.scroll = self.stdout.len() as isize - 2 - (self.inner_size.1 as isize); if self.scroll < 0 { self.scroll = 0; } @@ -499,15 +499,17 @@ impl Tile { } } - let mut spaces = format!( - "{}", - cursor::Goto(x + max_char_index, y + last_line_index as u16 - scroll) - ); + if last_line_index <= h { + let mut spaces = format!( + "{}", + cursor::Goto(x + max_char_index, y + last_line_index as u16 - scroll) + ); - for _ in max_char_index..w { - spaces.push(DELETE_CHAR); + for _ in max_char_index..w { + spaces.push(DELETE_CHAR); + } + buffer.push(spaces); } - buffer.push(spaces); buffer.push(format!("{}", style::Reset)); buffer.join("") @@ -522,7 +524,7 @@ impl Tile { /// Scrolls down one line. pub fn scroll_down(&mut self) { - if self.scroll + (self.inner_size.1 as isize) < self.stdout.len() as isize - 1 { + if self.scroll + (self.inner_size.1 as isize) < self.stdout.len() as isize - 2 { self.scroll += 1; } } @@ -534,7 +536,7 @@ impl Tile { /// Scrolls down one line. pub fn scroll_full_down(&mut self) { - self.scroll = self.stdout.len() as isize - self.inner_size.1 as isize - 1; + self.scroll = self.stdout.len() as isize - self.inner_size.1 as isize - 2; if self.scroll < 0 { self.scroll = 0; }