vt: expose focus encoding in C and Zig APIs

Add focus event encoding (CSI I / CSI O) to the libghostty-vt public
API, following the same patterns as key and mouse encoding.

The focus Event enum uses lib.Enum for C ABI compatibility. The C API
provides ghostty_focus_encode() which writes into a caller-provided
buffer and returns GHOSTTY_OUT_OF_SPACE with the required size when
the buffer is too small.

Also update key and mouse encoders to return GHOSTTY_OUT_OF_SPACE
instead of GHOSTTY_OUT_OF_MEMORY for buffer-too-small errors,
reserving OUT_OF_MEMORY for actual allocation failures. Update all
corresponding header documentation.
This commit is contained in:
Mitchell Hashimoto
2026-03-16 14:23:15 -07:00
parent c1326c57f9
commit bed9d92f04
12 changed files with 226 additions and 16 deletions

View File

@@ -81,11 +81,17 @@ pub const input = struct {
// We have to be careful to only import targeted files within
// the input package because the full package brings in too many
// other dependencies.
const focus = terminal.focus;
const paste = @import("input/paste.zig");
const key = @import("input/key.zig");
const key_encode = @import("input/key_encode.zig");
const mouse_encode = @import("input/mouse_encode.zig");
// Focus-related APIs
pub const max_focus_encode_size = focus.max_encode_size;
pub const FocusEvent = focus.Event;
pub const encodeFocus = focus.encode;
// Paste-related APIs
pub const PasteError = paste.Error;
pub const PasteOptions = paste.Options;
@@ -158,6 +164,7 @@ comptime {
@export(&c.osc_end, .{ .name = "ghostty_osc_end" });
@export(&c.osc_command_type, .{ .name = "ghostty_osc_command_type" });
@export(&c.osc_command_data, .{ .name = "ghostty_osc_command_data" });
@export(&c.focus_encode, .{ .name = "ghostty_focus_encode" });
@export(&c.paste_is_safe, .{ .name = "ghostty_paste_is_safe" });
@export(&c.color_rgb_get, .{ .name = "ghostty_color_rgb_get" });
@export(&c.sgr_new, .{ .name = "ghostty_sgr_new" });