From 2f935d2c5c5c33ca6a779c46a8d36fb2b96c7c38 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 5 Jul 2023 14:16:34 -0700 Subject: [PATCH] clear_screen uses FF (0x0C) if cursor is at prompt --- src/termio/Exec.zig | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 300ef2869..9c735fb2d 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -258,20 +258,34 @@ pub fn resize( /// Clear the screen. pub fn clearScreen(self: *Exec, history: bool) !void { - self.renderer_state.mutex.lock(); - defer self.renderer_state.mutex.unlock(); + { + self.renderer_state.mutex.lock(); + defer self.renderer_state.mutex.unlock(); - // If we're on the alternate screen, we do not clear. Since this is an - // emulator-level screen clear, this messes up the running programs - // knowledge of where the cursor is and causes rendering issues. So, - // for alt screen, we do nothing. - if (self.terminal.active_screen == .alternate) return; + // If we're on the alternate screen, we do not clear. Since this is an + // emulator-level screen clear, this messes up the running programs + // knowledge of where the cursor is and causes rendering issues. So, + // for alt screen, we do nothing. + if (self.terminal.active_screen == .alternate) return; - // Clear our scrollback - if (history) try self.terminal.screen.clear(.history); + // Clear our scrollback + if (history) try self.terminal.screen.clear(.history); - // Clear above the cursor - try self.terminal.screen.clear(.above_cursor); + // 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 (!self.terminal.cursorIsAtPrompt()) { + // Clear above the cursor + try self.terminal.screen.clear(.above_cursor); + + // Exit + return; + } + } + + // 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}); } pub inline fn queueWrite(self: *Exec, data: []const u8) !void {