aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/terminal/c/terminal.zig
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-05-07 18:29:21 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-05-07 18:29:21 +0300
commitdcfe11a7588fcd42471159453810abc9b7720a57 (patch)
treec32a77266028e73ca2382b96c96f8438a5fcd621 /vendor/libghostty-vt/src/terminal/c/terminal.zig
parent2dfed860103c4e4505ac7f25def9fe37da1e1e6a (diff)
build: update libghostty-vt vendor
vendor ghostty 063ac3e and remove the musl libc++ link workaround. expose the new selection formatter and hyperlink uri apis for follow-up rendering work. add manual artifact validation for static linux builds.
Diffstat (limited to 'vendor/libghostty-vt/src/terminal/c/terminal.zig')
-rw-r--r--vendor/libghostty-vt/src/terminal/c/terminal.zig346
1 files changed, 290 insertions, 56 deletions
diff --git a/vendor/libghostty-vt/src/terminal/c/terminal.zig b/vendor/libghostty-vt/src/terminal/c/terminal.zig
index fa421f21..d3293f3b 100644
--- a/vendor/libghostty-vt/src/terminal/c/terminal.zig
+++ b/vendor/libghostty-vt/src/terminal/c/terminal.zig
@@ -1,20 +1,21 @@
const std = @import("std");
const testing = std.testing;
+const build_options = @import("terminal_options");
const lib = @import("../lib.zig");
const CAllocator = lib.alloc.Allocator;
const ZigTerminal = @import("../Terminal.zig");
const Stream = @import("../stream_terminal.zig").Stream;
const ScreenSet = @import("../ScreenSet.zig");
const PageList = @import("../PageList.zig");
+const apc = @import("../apc.zig");
const kitty = @import("../kitty/key.zig");
+const kitty_gfx_c = @import("kitty_graphics.zig");
const modes = @import("../modes.zig");
const point = @import("../point.zig");
const size = @import("../size.zig");
const device_attributes = @import("../device_attributes.zig");
const device_status = @import("../device_status.zig");
const size_report = @import("../size_report.zig");
-const formatterpkg = @import("../formatter.zig");
-const selectionpkg = @import("../Selection.zig");
const cell_c = @import("cell.zig");
const row_c = @import("row.zig");
const grid_ref_c = @import("grid_ref.zig");
@@ -306,6 +307,12 @@ pub const Option = enum(c_int) {
color_background = 12,
color_cursor = 13,
color_palette = 14,
+ kitty_image_storage_limit = 15,
+ kitty_image_medium_file = 16,
+ kitty_image_medium_temp_file = 17,
+ kitty_image_medium_shared_mem = 18,
+ apc_max_bytes = 19,
+ apc_max_bytes_kitty = 20,
/// Input type expected for setting the option.
pub fn InType(comptime self: Option) type {
@@ -322,6 +329,12 @@ pub const Option = enum(c_int) {
.title, .pwd => ?*const lib.String,
.color_foreground, .color_background, .color_cursor => ?*const color.RGB.C,
.color_palette => ?*const color.PaletteC,
+ .kitty_image_storage_limit => ?*const u64,
+ .kitty_image_medium_file,
+ .kitty_image_medium_temp_file,
+ .kitty_image_medium_shared_mem,
+ => ?*const bool,
+ .apc_max_bytes, .apc_max_bytes_kitty => ?*const usize,
};
}
};
@@ -390,6 +403,45 @@ fn setTyped(
);
wrapper.terminal.flags.dirty.palette = true;
},
+ .kitty_image_storage_limit => {
+ if (comptime !build_options.kitty_graphics) return .success;
+ const limit: usize = if (value) |v| @intCast(v.*) else 0;
+ var it = wrapper.terminal.screens.all.iterator();
+ while (it.next()) |entry| {
+ const screen = entry.value.*;
+ screen.kitty_images.setLimit(screen.alloc, screen, limit) catch return .out_of_memory;
+ }
+ },
+ .kitty_image_medium_file,
+ .kitty_image_medium_temp_file,
+ .kitty_image_medium_shared_mem,
+ => {
+ if (comptime !build_options.kitty_graphics) return .success;
+ const val = (value orelse return .success).*;
+ var it = wrapper.terminal.screens.all.iterator();
+ while (it.next()) |entry| {
+ const screen = entry.value.*;
+ switch (option) {
+ .kitty_image_medium_file => screen.kitty_images.image_limits.file = val,
+ .kitty_image_medium_temp_file => screen.kitty_images.image_limits.temporary_file = val,
+ .kitty_image_medium_shared_mem => screen.kitty_images.image_limits.shared_memory = val,
+ else => unreachable,
+ }
+ }
+ },
+ .apc_max_bytes => {
+ wrapper.stream.handler.apc_handler.max_bytes = if (value) |ptr|
+ .initFull(ptr.*)
+ else
+ .{};
+ },
+ .apc_max_bytes_kitty => {
+ if (value) |ptr| {
+ wrapper.stream.handler.apc_handler.max_bytes.put(.kitty, ptr.*);
+ } else {
+ wrapper.stream.handler.apc_handler.max_bytes.remove(.kitty);
+ }
+ },
}
return .success;
}
@@ -400,21 +452,6 @@ pub const DeviceAttributes = Effects.CDeviceAttributes;
/// C: GhosttyTerminalScrollViewport
pub const ScrollViewport = ZigTerminal.ScrollViewport.C;
-/// C: GhosttyTerminalSelection
-pub const Selection = extern struct {
- start: point.Point.C,
- end: point.Point.C,
- rectangle: bool,
-
- fn toZig(self: Selection, terminal: *const ZigTerminal) ?selectionpkg {
- return selectionpkg.init(
- pinFromPoint(terminal, self.start) orelse return null,
- pinFromPoint(terminal, self.end) orelse return null,
- self.rectangle,
- );
- }
-};
-
pub fn scroll_viewport(
terminal_: Terminal,
behavior: ScrollViewport,
@@ -496,6 +533,9 @@ pub fn mode_set(
return .success;
}
+/// C: GhosttyKittyGraphics
+pub const KittyGraphics = kitty_gfx_c.KittyGraphics;
+
/// C: GhosttyTerminalScreen
pub const TerminalScreen = ScreenSet.Key;
@@ -530,6 +570,11 @@ pub const TerminalData = enum(c_int) {
color_background_default = 23,
color_cursor_default = 24,
color_palette_default = 25,
+ kitty_image_storage_limit = 26,
+ kitty_image_medium_file = 27,
+ kitty_image_medium_temp_file = 28,
+ kitty_image_medium_shared_mem = 29,
+ kitty_graphics = 30,
/// Output type expected for querying the data of the given kind.
pub fn OutType(comptime self: TerminalData) type {
@@ -552,6 +597,12 @@ pub const TerminalData = enum(c_int) {
.color_cursor_default,
=> color.RGB.C,
.color_palette, .color_palette_default => color.PaletteC,
+ .kitty_image_storage_limit => u64,
+ .kitty_image_medium_file,
+ .kitty_image_medium_temp_file,
+ .kitty_image_medium_shared_mem,
+ => bool,
+ .kitty_graphics => KittyGraphics,
};
}
};
@@ -578,6 +629,27 @@ pub fn get(
};
}
+pub fn get_multi(
+ terminal_: Terminal,
+ count: usize,
+ keys: ?[*]const TerminalData,
+ values: ?[*]?*anyopaque,
+ out_written: ?*usize,
+) callconv(lib.calling_conv) Result {
+ const k = keys orelse return .invalid_value;
+ const v = values orelse return .invalid_value;
+
+ for (0..count) |i| {
+ const result = get(terminal_, k[i], v[i]);
+ if (result != .success) {
+ if (out_written) |w| w.* = i;
+ return result;
+ }
+ }
+ if (out_written) |w| w.* = count;
+ return .success;
+}
+
fn getTyped(
terminal_: Terminal,
comptime data: TerminalData,
@@ -620,63 +692,60 @@ fn getTyped(
.color_cursor_default => out.* = (t.colors.cursor.default orelse return .no_value).cval(),
.color_palette => out.* = color.paletteCval(&t.colors.palette.current),
.color_palette_default => out.* = color.paletteCval(&t.colors.palette.original),
+ .kitty_image_storage_limit => {
+ if (comptime !build_options.kitty_graphics) return .no_value;
+ out.* = @intCast(t.screens.active.kitty_images.total_limit);
+ },
+ .kitty_image_medium_file => {
+ if (comptime !build_options.kitty_graphics) return .no_value;
+ out.* = t.screens.active.kitty_images.image_limits.file;
+ },
+ .kitty_image_medium_temp_file => {
+ if (comptime !build_options.kitty_graphics) return .no_value;
+ out.* = t.screens.active.kitty_images.image_limits.temporary_file;
+ },
+ .kitty_image_medium_shared_mem => {
+ if (comptime !build_options.kitty_graphics) return .no_value;
+ out.* = t.screens.active.kitty_images.image_limits.shared_memory;
+ },
+ .kitty_graphics => {
+ if (comptime !build_options.kitty_graphics) return .no_value;
+ out.* = &t.screens.active.kitty_images;
+ },
}
return .success;
}
-fn pointToZig(pt: point.Point.C) point.Point {
- return switch (pt.tag) {
- .active => .{ .active = pt.value.active },
- .viewport => .{ .viewport = pt.value.viewport },
- .screen => .{ .screen = pt.value.screen },
- .history => .{ .history = pt.value.history },
- };
-}
-
-fn pinFromPoint(terminal: *const ZigTerminal, pt: point.Point.C) ?PageList.Pin {
- return terminal.screens.active.pages.pin(pointToZig(pt));
-}
-
pub fn grid_ref(
terminal_: Terminal,
pt: point.Point.C,
out_ref: ?*grid_ref_c.CGridRef,
) callconv(lib.calling_conv) Result {
const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal;
- const p = pinFromPoint(t, pt) orelse return .invalid_value;
+ const zig_pt: point.Point = switch (pt.tag) {
+ .active => .{ .active = pt.value.active },
+ .viewport => .{ .viewport = pt.value.viewport },
+ .screen => .{ .screen = pt.value.screen },
+ .history => .{ .history = pt.value.history },
+ };
+ const p = t.screens.active.pages.pin(zig_pt) orelse
+ return .invalid_value;
if (out_ref) |out| out.* = grid_ref_c.CGridRef.fromPin(p);
return .success;
}
-pub fn read_text(
+pub fn point_from_grid_ref(
terminal_: Terminal,
- selection: Selection,
- alloc_: ?*const CAllocator,
- out_ptr: *?[*]u8,
- out_len: *usize,
+ ref: *const grid_ref_c.CGridRef,
+ tag: point.Tag,
+ out: ?*point.Coordinate,
) callconv(lib.calling_conv) Result {
- out_ptr.* = null;
- out_len.* = 0;
-
const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal;
- const alloc = lib.alloc.default(alloc_);
- const sel = selection.toZig(t) orelse return .invalid_value;
-
- var formatter: formatterpkg.ScreenFormatter = .init(t.screens.active, .{
- .emit = .plain,
- .unwrap = true,
- .trim = true,
- });
- formatter.content = .{ .selection = sel };
-
- var aw: std.Io.Writer.Allocating = .init(alloc);
- defer aw.deinit();
- formatter.format(&aw.writer) catch return .out_of_memory;
-
- const buf = aw.toOwnedSlice() catch return .out_of_memory;
- out_ptr.* = buf.ptr;
- out_len.* = buf.len;
+ const p = ref.toPin() orelse return .invalid_value;
+ const pt = t.screens.active.pages.pointFromPin(tag, p) orelse
+ return .no_value;
+ if (out) |o| o.* = pt.coord();
return .success;
}
@@ -983,6 +1052,29 @@ test "vt_write split escape sequence" {
try testing.expectEqualStrings("Hello Bold", str);
}
+test "vt_write split combining mark after base at right edge" {
+ var t: Terminal = null;
+ try testing.expectEqual(Result.success, new(
+ &lib.alloc.test_allocator,
+ &t,
+ .{
+ .cols = 2,
+ .rows = 2,
+ .max_scrollback = 0,
+ },
+ ));
+ defer free(t);
+
+ // Put "å" in the final column, then send its combining low line in a
+ // separate write so the mark arrives while the cursor has a pending wrap.
+ vt_write(t, "xå", 3);
+ vt_write(t, "\xcc\xb2", 2);
+
+ const str = try t.?.terminal.plainString(testing.allocator);
+ defer testing.allocator.free(str);
+ try testing.expectEqualStrings("xå̲", str);
+}
+
test "get cols and rows" {
var t: Terminal = null;
try testing.expectEqual(Result.success, new(
@@ -1244,6 +1336,102 @@ test "grid_ref null terminal" {
}, &out_ref));
}
+test "point_from_grid_ref roundtrip active" {
+ 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);
+
+ // Get a grid ref at (2, 0) in active coords
+ var ref: grid_ref_c.CGridRef = .{};
+ try testing.expectEqual(Result.success, grid_ref(t, .{
+ .tag = .active,
+ .value = .{ .active = .{ .x = 2, .y = 0 } },
+ }, &ref));
+
+ // Convert back to active coords
+ var coord: point.Coordinate = undefined;
+ try testing.expectEqual(Result.success, point_from_grid_ref(t, &ref, .active, &coord));
+ try testing.expectEqual(@as(size.CellCountInt, 2), coord.x);
+ try testing.expectEqual(@as(u32, 0), coord.y);
+}
+
+test "point_from_grid_ref roundtrip viewport" {
+ 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);
+
+ var ref: grid_ref_c.CGridRef = .{};
+ try testing.expectEqual(Result.success, grid_ref(t, .{
+ .tag = .viewport,
+ .value = .{ .viewport = .{ .x = 0, .y = 0 } },
+ }, &ref));
+
+ var coord: point.Coordinate = undefined;
+ try testing.expectEqual(Result.success, point_from_grid_ref(t, &ref, .viewport, &coord));
+ try testing.expectEqual(@as(size.CellCountInt, 0), coord.x);
+ try testing.expectEqual(@as(u32, 0), coord.y);
+}
+
+test "point_from_grid_ref history ref to active returns no_value" {
+ var t: Terminal = null;
+ try testing.expectEqual(Result.success, new(
+ &lib.alloc.test_allocator,
+ &t,
+ .{ .cols = 80, .rows = 4, .max_scrollback = 10_000 },
+ ));
+ defer free(t);
+
+ // Write enough lines to push content into scrollback
+ for (0..10) |_| {
+ vt_write(t, "line\n", 5);
+ }
+
+ // Get a ref to the first line (now in scrollback)
+ var ref: grid_ref_c.CGridRef = .{};
+ try testing.expectEqual(Result.success, grid_ref(t, .{
+ .tag = .screen,
+ .value = .{ .screen = .{ .x = 0, .y = 0 } },
+ }, &ref));
+
+ // Should succeed for screen coords
+ var coord: point.Coordinate = undefined;
+ try testing.expectEqual(Result.success, point_from_grid_ref(t, &ref, .screen, &coord));
+ try testing.expectEqual(@as(u32, 0), coord.y);
+
+ // Should fail for active coords (it's in scrollback)
+ try testing.expectEqual(Result.no_value, point_from_grid_ref(t, &ref, .active, &coord));
+}
+
+test "point_from_grid_ref null terminal" {
+ var ref: grid_ref_c.CGridRef = .{};
+ try testing.expectEqual(Result.invalid_value, point_from_grid_ref(null, &ref, .active, null));
+}
+
+test "point_from_grid_ref null node" {
+ var t: Terminal = null;
+ try testing.expectEqual(Result.success, new(
+ &lib.alloc.test_allocator,
+ &t,
+ .{ .cols = 80, .rows = 24, .max_scrollback = 0 },
+ ));
+ defer free(t);
+
+ const ref: grid_ref_c.CGridRef = .{};
+ try testing.expectEqual(Result.invalid_value, point_from_grid_ref(t, &ref, .active, null));
+}
+
test "set write_pty callback" {
var t: Terminal = null;
try testing.expectEqual(Result.success, new(
@@ -2410,3 +2598,49 @@ test "set color sets dirty flag" {
try testing.expectEqual(Result.success, set(t, .color_foreground, @ptrCast(&fg)));
try testing.expect(zt.flags.dirty.palette);
}
+
+test "get_multi success" {
+ var t: Terminal = null;
+ try testing.expectEqual(Result.success, new(
+ &lib.alloc.test_allocator,
+ &t,
+ .{ .cols = 80, .rows = 24, .max_scrollback = 0 },
+ ));
+ defer free(t);
+
+ var cols: u16 = 0;
+ var rows: u16 = 0;
+ var written: usize = 0;
+
+ const keys = [_]TerminalData{ .cols, .rows };
+ var values = [_]?*anyopaque{ @ptrCast(&cols), @ptrCast(&rows) };
+ try testing.expectEqual(Result.success, get_multi(t, keys.len, &keys, &values, &written));
+ try testing.expectEqual(keys.len, written);
+ try testing.expectEqual(80, cols);
+ try testing.expectEqual(24, rows);
+}
+
+test "get_multi error sets out_written" {
+ var t: Terminal = null;
+ try testing.expectEqual(Result.success, new(
+ &lib.alloc.test_allocator,
+ &t,
+ .{ .cols = 80, .rows = 24, .max_scrollback = 0 },
+ ));
+ defer free(t);
+
+ var cols: u16 = 0;
+ var written: usize = 99;
+
+ const keys = [_]TerminalData{ .cols, .invalid };
+ var values = [_]?*anyopaque{ @ptrCast(&cols), @ptrCast(&cols) };
+ try testing.expectEqual(Result.invalid_value, get_multi(t, keys.len, &keys, &values, &written));
+ try testing.expectEqual(1, written);
+ try testing.expectEqual(80, cols);
+}
+
+test "get_multi null keys returns invalid_value" {
+ var cols: u16 = 0;
+ var values = [_]?*anyopaque{@ptrCast(&cols)};
+ try testing.expectEqual(Result.invalid_value, get_multi(null, 1, null, &values, null));
+}