mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
Merge pull request #187 from mitchellh/clear-at-prompt
clear_screen uses FF (0x0C) if cursor is at prompt
This commit is contained in:
@ -258,20 +258,34 @@ 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();
|
{
|
||||||
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
|
// 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
|
// emulator-level screen clear, this messes up the running programs
|
||||||
// knowledge of where the cursor is and causes rendering issues. So,
|
// knowledge of where the cursor is and causes rendering issues. So,
|
||||||
// for alt screen, we do nothing.
|
// for alt screen, we do nothing.
|
||||||
if (self.terminal.active_screen == .alternate) return;
|
if (self.terminal.active_screen == .alternate) return;
|
||||||
|
|
||||||
// Clear our scrollback
|
// Clear our scrollback
|
||||||
if (history) try self.terminal.screen.clear(.history);
|
if (history) try self.terminal.screen.clear(.history);
|
||||||
|
|
||||||
// Clear above the cursor
|
// If we're not at a prompt, we clear the screen manually using
|
||||||
try self.terminal.screen.clear(.above_cursor);
|
// 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 {
|
pub inline fn queueWrite(self: *Exec, data: []const u8) !void {
|
||||||
|
Reference in New Issue
Block a user