From 810242b4720bf1ba243276dcf4e049220a1c73df Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 30 Nov 2023 12:32:35 -0800 Subject: [PATCH] termio: clear_screen binding does not trigger scrollback preservation Fixes #970 --- src/termio/Exec.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 73a34d0ed..9b4631a22 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -451,22 +451,24 @@ pub fn clearScreen(self: *Exec, history: bool) !void { if (self.terminal.active_screen == .alternate) return; // Clear our scrollback - if (history) try self.terminal.screen.clear(.history); + if (history) self.terminal.eraseDisplay(self.alloc, .scrollback, false); - // If we're not at a prompt, we clear the screen manually using - // the terminal screen state. If we are at a prompt, we send - // form-feed so that the shell can repaint the entire screen. + // If we're not at a prompt, we just delete above the cursor. if (!self.terminal.cursorIsAtPrompt()) { - // Clear above the cursor try self.terminal.screen.clear(.above_cursor); - - // Exit return; } + + // At a prompt, we want to first fully clear the screen, and then after + // send a FF (0x0C) to the shell so that it can repaint the screen. + // Mark the current row as a not a prompt so we can properly + // clear the full screen in the next eraseDisplay call. + self.terminal.markSemanticPrompt(.command); + assert(!self.terminal.cursorIsAtPrompt()); + self.terminal.eraseDisplay(self.alloc, .complete, false); } // If we reached here it means we're at a prompt, so we send a form-feed. - assert(self.terminal.cursorIsAtPrompt()); try self.queueWrite(&[_]u8{0x0C}, false); }