vt: ghostty_terminal_reset

This commit is contained in:
Mitchell Hashimoto
2026-03-13 19:55:42 -07:00
parent fe6e7fbc6b
commit aa3e6e23a2
4 changed files with 45 additions and 0 deletions

View File

@@ -118,6 +118,19 @@ GhosttyResult ghostty_terminal_new(const GhosttyAllocator* allocator,
*/
void ghostty_terminal_free(GhosttyTerminal terminal);
/**
* Perform a full reset of the terminal (RIS).
*
* Resets all terminal state back to its initial configuration, including
* modes, scrollback, scrolling region, and screen contents. The terminal
* dimensions are preserved.
*
* @param terminal The terminal handle (may be NULL, in which case this is a no-op)
*
* @ingroup terminal
*/
void ghostty_terminal_reset(GhosttyTerminal terminal);
/**
* Resize the terminal to the given dimensions.
*

View File

@@ -145,6 +145,7 @@ comptime {
@export(&c.sgr_attribute_value, .{ .name = "ghostty_sgr_attribute_value" });
@export(&c.terminal_new, .{ .name = "ghostty_terminal_new" });
@export(&c.terminal_free, .{ .name = "ghostty_terminal_free" });
@export(&c.terminal_reset, .{ .name = "ghostty_terminal_reset" });
@export(&c.terminal_resize, .{ .name = "ghostty_terminal_resize" });
@export(&c.terminal_vt_write, .{ .name = "ghostty_terminal_vt_write" });
@export(&c.terminal_scroll_viewport, .{ .name = "ghostty_terminal_scroll_viewport" });

View File

@@ -55,6 +55,7 @@ pub const paste_is_safe = paste.is_safe;
pub const terminal_new = terminal.new;
pub const terminal_free = terminal.free;
pub const terminal_reset = terminal.reset;
pub const terminal_resize = terminal.resize;
pub const terminal_vt_write = terminal.vt_write;
pub const terminal_scroll_viewport = terminal.scroll_viewport;

View File

@@ -93,6 +93,11 @@ pub fn resize(
return .success;
}
pub fn reset(terminal_: Terminal) callconv(.c) void {
const t = terminal_ orelse return;
t.fullReset();
}
pub fn free(terminal_: Terminal) callconv(.c) void {
const t = terminal_ orelse return;
@@ -203,6 +208,31 @@ test "scroll_viewport null" {
scroll_viewport(null, .{ .tag = .top, .value = undefined });
}
test "reset" {
var t: Terminal = null;
try testing.expectEqual(Result.success, new(
&lib_alloc.test_allocator,
&t,
.{
.cols = 80,
.rows = 24,
.max_scrollback = 10_000,
},
));
defer free(t);
vt_write(t, "Hello", 5);
reset(t);
const str = try t.?.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("", str);
}
test "reset null" {
reset(null);
}
test "resize" {
var t: Terminal = null;
try testing.expectEqual(Result.success, new(