From 9e88cc58c3dd4f9537c87dea75c9055c038940dc Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 22 Apr 2024 09:32:06 +0000 Subject: [PATCH] fix: unexpected spaces after large buffer input close #297 --- src/painting/painter.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/painting/painter.rs b/src/painting/painter.rs index 4986a961..4d95ca88 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -55,7 +55,7 @@ pub struct Painter { stdout: W, prompt_start_row: u16, terminal_size: (u16, u16), - last_required_lines: u16, + after_cursor_lines: Option, large_buffer: bool, } @@ -65,7 +65,7 @@ impl Painter { stdout, prompt_start_row: 0, terminal_size: (0, 0), - last_required_lines: 0, + after_cursor_lines: None, large_buffer: false, } } @@ -181,9 +181,11 @@ impl Painter { self.print_small_buffer(prompt, lines, menu, use_ansi_coloring)?; } - // The last_required_lines is used to move the cursor at the end where stdout - // can print without overwriting the things written during the painting - self.last_required_lines = required_lines; + self.after_cursor_lines = if !lines.after_cursor.is_empty() { + Some(lines.after_cursor.to_string()) + } else { + None + }; self.stdout.queue(RestorePosition)?; @@ -474,18 +476,13 @@ impl Painter { } // The prompt is moved to the end of the buffer after the event was handled - // If the prompt is in the middle of a multiline buffer, then the output to stdout - // could overwrite the buffer writing pub(crate) fn move_cursor_to_end(&mut self) -> Result<()> { - let final_row = self.prompt_start_row + self.last_required_lines; - let scroll = final_row.saturating_sub(self.screen_height() - 1); - if scroll != 0 { - self.queue_universal_scroll(scroll)?; + if let Some(after_cursor) = &self.after_cursor_lines { + self.stdout + .queue(Clear(ClearType::FromCursorDown))? + .queue(Print(after_cursor))?; } - self.stdout - .queue(MoveTo(0, final_row.min(self.screen_height() - 1)))?; - - self.stdout.flush() + self.print_crlf() } /// Prints an external message