Merge pull request #187 from mitchellh/clear-at-prompt

clear_screen uses FF (0x0C) if cursor is at prompt
This commit is contained in:
Mitchell Hashimoto
2023-07-05 14:21:27 -07:00
committed by GitHub

View File

@ -258,6 +258,7 @@ pub fn resize(
/// Clear the screen. /// Clear the screen.
pub fn clearScreen(self: *Exec, history: bool) !void { pub fn clearScreen(self: *Exec, history: bool) !void {
{
self.renderer_state.mutex.lock(); self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock(); defer self.renderer_state.mutex.unlock();
@ -270,8 +271,21 @@ pub fn clearScreen(self: *Exec, history: bool) !void {
// Clear our scrollback // Clear our scrollback
if (history) try self.terminal.screen.clear(.history); if (history) try self.terminal.screen.clear(.history);
// 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 // Clear above the cursor
try self.terminal.screen.clear(.above_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 { pub inline fn queueWrite(self: *Exec, data: []const u8) !void {