From f50aa90ced49a05066fae4ee00071adb34dee6b5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Mar 2026 07:22:02 -0700 Subject: [PATCH 1/4] terminal: add lib.zig to centralize lib target and re-exports Previously every file in the terminal package independently imported build_options and ../lib/main.zig, then computed the same lib_target constant. This was repetitive and meant each file needed both imports just to get the target. Introduce src/terminal/lib.zig which computes the target once and re-exports the commonly used lib types (Enum, TaggedUnion, Struct, String, checkGhosttyHEnum, structSizedFieldFits). All terminal package files now import lib.zig and use lib.target instead of the local lib_target constant, removing the per-file boilerplate. --- src/terminal/ScreenSet.zig | 7 ++---- src/terminal/Terminal.zig | 8 +++---- src/terminal/ansi.zig | 10 ++++---- src/terminal/c/render.zig | 2 +- src/terminal/c/terminal.zig | 2 +- src/terminal/csi.zig | 6 ++--- src/terminal/device_attributes.zig | 6 ++--- src/terminal/device_status.zig | 6 ++--- src/terminal/focus.zig | 6 ++--- src/terminal/formatter.zig | 6 ++--- src/terminal/lib.zig | 23 +++++++++++++++++++ src/terminal/mouse.zig | 7 +++--- src/terminal/osc.zig | 6 ++--- .../osc/parsers/kitty_text_sizing.zig | 8 +++---- src/terminal/point.zig | 9 +++----- src/terminal/render.zig | 6 ++--- src/terminal/sgr.zig | 9 +++----- src/terminal/size_report.zig | 8 +++---- src/terminal/stream.zig | 12 ++++------ 19 files changed, 69 insertions(+), 78 deletions(-) create mode 100644 src/terminal/lib.zig diff --git a/src/terminal/ScreenSet.zig b/src/terminal/ScreenSet.zig index 6fe866f70..d0856da51 100644 --- a/src/terminal/ScreenSet.zig +++ b/src/terminal/ScreenSet.zig @@ -9,16 +9,13 @@ const ScreenSet = @This(); const std = @import("std"); const assert = @import("../quirks.zig").inlineAssert; -const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); +const lib = @import("lib.zig"); const testing = std.testing; const Allocator = std.mem.Allocator; const Screen = @import("Screen.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; - /// The possible keys for screens in the screen set. -pub const Key = lib.Enum(lib_target, &.{ +pub const Key = lib.Enum(lib.target, &.{ "primary", "alternate", }); diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 9c956ec92..c09eb9981 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -5,7 +5,7 @@ const Terminal = @This(); const std = @import("std"); const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); +const lib = @import("lib.zig"); const assert = @import("../quirks.zig").inlineAssert; const testing = std.testing; const Allocator = std.mem.Allocator; @@ -35,8 +35,6 @@ const Page = pagepkg.Page; const Cell = pagepkg.Cell; const Row = pagepkg.Row; -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; - const log = std.log.scoped(.terminal); /// Default tabstop interval @@ -1706,14 +1704,14 @@ pub const ScrollViewport = union(Tag) { /// Scroll by some delta amount, up is negative. delta: isize, - pub const Tag = lib.Enum(lib_target, &.{ + pub const Tag = lib.Enum(lib.target, &.{ "top", "bottom", "delta", }); const c_union = lib.TaggedUnion( - lib_target, + lib.target, @This(), // Padding: largest variant is isize (8 bytes on 64-bit). // Use [2]u64 (16 bytes) for future expansion. diff --git a/src/terminal/ansi.zig b/src/terminal/ansi.zig index 86b00c801..4e777b7c6 100644 --- a/src/terminal/ansi.zig +++ b/src/terminal/ansi.zig @@ -1,6 +1,4 @@ -const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); /// C0 (7-bit) control characters from ANSI. /// @@ -54,7 +52,7 @@ pub const RenditionAspect = enum(u16) { /// Possible cursor styles (ESC [ q) pub const CursorStyle = lib.Enum( - lib_target, + lib.target, &.{ "default", "blinking_block", @@ -78,7 +76,7 @@ pub const StatusLineType = enum(u16) { /// The display to target for status updates (DECSASD). pub const StatusDisplay = lib.Enum( - lib_target, + lib.target, &.{ "main", "status_line", @@ -88,7 +86,7 @@ pub const StatusDisplay = lib.Enum( /// The possible modify key formats to ESC[>{a};{b}m /// Note: this is not complete, we should add more as we support more pub const ModifyKeyFormat = lib.Enum( - lib_target, + lib.target, &.{ "legacy", "cursor_keys", diff --git a/src/terminal/c/render.zig b/src/terminal/c/render.zig index 020dbc202..e29dfd019 100644 --- a/src/terminal/c/render.zig +++ b/src/terminal/c/render.zig @@ -1,7 +1,7 @@ const std = @import("std"); const testing = std.testing; const Allocator = std.mem.Allocator; -const lib = @import("../../lib/main.zig"); +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const colorpkg = @import("../color.zig"); diff --git a/src/terminal/c/terminal.zig b/src/terminal/c/terminal.zig index 113e00b96..c01d1adab 100644 --- a/src/terminal/c/terminal.zig +++ b/src/terminal/c/terminal.zig @@ -1,6 +1,6 @@ const std = @import("std"); const testing = std.testing; -const lib = @import("../../lib/main.zig"); +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const ZigTerminal = @import("../Terminal.zig"); diff --git a/src/terminal/csi.zig b/src/terminal/csi.zig index d2f4bd6f8..2491a2341 100644 --- a/src/terminal/csi.zig +++ b/src/terminal/csi.zig @@ -1,6 +1,4 @@ -const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); /// Modes for the ED CSI command. pub const EraseDisplay = enum(u8) { @@ -38,7 +36,7 @@ pub const TabClear = enum(u8) { /// Style formats for terminal size reports. pub const SizeReportStyle = lib.Enum( - lib_target, + lib.target, &.{ // XTWINOPS "csi_14_t", diff --git a/src/terminal/device_attributes.zig b/src/terminal/device_attributes.zig index 3b99459d3..38d081175 100644 --- a/src/terminal/device_attributes.zig +++ b/src/terminal/device_attributes.zig @@ -1,11 +1,9 @@ const std = @import("std"); const testing = std.testing; -const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); /// The device attribute request type (CSI c). -pub const Req = lib.Enum(lib_target, &.{ +pub const Req = lib.Enum(lib.target, &.{ "primary", // Blank "secondary", // > "tertiary", // = diff --git a/src/terminal/device_status.zig b/src/terminal/device_status.zig index 61dd569f3..42b4bf01b 100644 --- a/src/terminal/device_status.zig +++ b/src/terminal/device_status.zig @@ -1,10 +1,8 @@ const std = @import("std"); -const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); /// The color scheme reported in response to a CSI ? 996 n query. -pub const ColorScheme = lib.Enum(lib_target, &.{ +pub const ColorScheme = lib.Enum(lib.target, &.{ "light", "dark", }); diff --git a/src/terminal/focus.zig b/src/terminal/focus.zig index 563c0871a..91c579e12 100644 --- a/src/terminal/focus.zig +++ b/src/terminal/focus.zig @@ -1,7 +1,5 @@ const std = @import("std"); -const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); /// Maximum number of bytes that `encode` will write. Any users of this /// should be resilient to this changing, so this is always a specific @@ -10,7 +8,7 @@ pub const max_encode_size = 3; /// A focus event that can be reported to the application running in the /// terminal when focus reporting mode (mode 1004) is enabled. -pub const Event = lib.Enum(lib_target, &.{ +pub const Event = lib.Enum(lib.target, &.{ "gained", "lost", }); diff --git a/src/terminal/formatter.zig b/src/terminal/formatter.zig index 4da7248e3..a375b4dd7 100644 --- a/src/terminal/formatter.zig +++ b/src/terminal/formatter.zig @@ -1,8 +1,6 @@ const std = @import("std"); -const build_options = @import("terminal_options"); const assert = @import("../quirks.zig").inlineAssert; -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); const Allocator = std.mem.Allocator; const color = @import("color.zig"); const size = @import("size.zig"); @@ -22,7 +20,7 @@ const Selection = @import("Selection.zig"); const Style = @import("style.zig").Style; /// Formats available. -pub const Format = lib.Enum(lib_target, &.{ +pub const Format = lib.Enum(lib.target, &.{ // Plain text. "plain", diff --git a/src/terminal/lib.zig b/src/terminal/lib.zig new file mode 100644 index 000000000..f68cd4356 --- /dev/null +++ b/src/terminal/lib.zig @@ -0,0 +1,23 @@ +const std = @import("std"); +const build_options = @import("terminal_options"); +const lib = @import("../lib/main.zig"); + +/// The target for the terminal lib in particular. +pub const target: lib.Target = if (build_options.c_abi) .c else .zig; + +/// The calling convention to use for C APIs. If we're not building for +/// C ABI then we use auto which allows our C APIs to be cleanly called +/// by Zig. This is required because we modify our struct layouts based +/// on C ABI too. +pub const calling_conv: std.builtin.CallingConvention = if (build_options.c_abi) + .c +else + .auto; + +/// Forwarded decls from lib that are used. +pub const Enum = lib.Enum; +pub const TaggedUnion = lib.TaggedUnion; +pub const Struct = lib.Struct; +pub const String = lib.String; +pub const checkGhosttyHEnum = lib.checkGhosttyHEnum; +pub const structSizedFieldFits = lib.structSizedFieldFits; diff --git a/src/terminal/mouse.zig b/src/terminal/mouse.zig index 5286ab856..2861ad1e0 100644 --- a/src/terminal/mouse.zig +++ b/src/terminal/mouse.zig @@ -1,11 +1,10 @@ const std = @import("std"); const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); /// The event types that can be reported for mouse-related activities. /// These are all mutually exclusive (hence in a single enum). -pub const Event = lib.Enum(lib_target, &.{ +pub const Event = lib.Enum(lib.target, &.{ "none", "x10", // 9 "normal", // 1000 @@ -20,7 +19,7 @@ pub fn eventSendsMotion(event: Event) bool { /// The format of mouse events when enabled. /// These are all mutually exclusive (hence in a single enum). -pub const Format = lib.Enum(lib_target, &.{ +pub const Format = lib.Enum(lib.target, &.{ "x10", "utf8", // 1005 "sgr", // 1006 diff --git a/src/terminal/osc.zig b/src/terminal/osc.zig index 920ce3f7e..44e97e2c7 100644 --- a/src/terminal/osc.zig +++ b/src/terminal/osc.zig @@ -11,11 +11,11 @@ const build_options = @import("terminal_options"); const mem = std.mem; const assert = @import("../quirks.zig").inlineAssert; const Allocator = mem.Allocator; -const LibEnum = @import("../lib/enum.zig").Enum; +const lib = @import("lib.zig"); +const LibEnum = lib.Enum; const kitty_color = @import("kitty/color.zig"); const parsers = @import("osc/parsers.zig"); const encoding = @import("osc/encoding.zig"); -const lib = @import("../lib/main.zig"); pub const color = parsers.color; pub const semantic_prompt = parsers.semantic_prompt; @@ -165,7 +165,7 @@ pub const Command = union(Key) { pub const KittyClipboardProtocol = parsers.kitty_clipboard_protocol.OSC; pub const Key = LibEnum( - if (build_options.c_abi) .c else .zig, + lib.target, // NOTE: Order matters, see LibEnum documentation. &.{ "invalid", diff --git a/src/terminal/osc/parsers/kitty_text_sizing.zig b/src/terminal/osc/parsers/kitty_text_sizing.zig index f0180cc8f..370e22a22 100644 --- a/src/terminal/osc/parsers/kitty_text_sizing.zig +++ b/src/terminal/osc/parsers/kitty_text_sizing.zig @@ -2,27 +2,25 @@ //! Specification: https://sw.kovidgoyal.net/kitty/text-sizing-protocol/ const std = @import("std"); -const build_options = @import("terminal_options"); const assert = @import("../../../quirks.zig").inlineAssert; const Parser = @import("../../osc.zig").Parser; const Command = @import("../../osc.zig").Command; const encoding = @import("../encoding.zig"); -const lib = @import("../../../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("../../lib.zig"); const log = std.log.scoped(.kitty_text_sizing); pub const max_payload_length = 4096; -pub const VAlign = lib.Enum(lib_target, &.{ +pub const VAlign = lib.Enum(lib.target, &.{ "top", "bottom", "center", }); -pub const HAlign = lib.Enum(lib_target, &.{ +pub const HAlign = lib.Enum(lib.target, &.{ "left", "right", "center", diff --git a/src/terminal/point.zig b/src/terminal/point.zig index db834732c..4297bf5b5 100644 --- a/src/terminal/point.zig +++ b/src/terminal/point.zig @@ -1,18 +1,15 @@ const std = @import("std"); const Allocator = std.mem.Allocator; -const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); +const lib = @import("lib.zig"); const size = @import("size.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; - /// The possible reference locations for a point. When someone says "(42, 80)" /// in the context of a terminal, that could mean multiple things: it is in the /// current visible viewport? the current active area of the screen where the /// cursor is? the entire scrollback history? etc. /// /// This tag is used to differentiate those cases. -pub const Tag = lib.Enum(lib_target, &.{ +pub const Tag = lib.Enum(lib.target, &.{ // Top-left is part of the active area where a running program can // jump the cursor and make changes. The active area is the "editable" // part of the screen. @@ -70,7 +67,7 @@ pub const Point = union(Tag) { } const c_union = lib.TaggedUnion( - lib_target, + lib.target, @This(), // Padding: largest variant is Coordinate (u16 + u32 = 6 bytes). // Use [2]u64 (16 bytes) for future expansion. diff --git a/src/terminal/render.zig b/src/terminal/render.zig index 09e0c6b93..98e142245 100644 --- a/src/terminal/render.zig +++ b/src/terminal/render.zig @@ -1,11 +1,9 @@ const std = @import("std"); -const build_options = @import("terminal_options"); const assert = @import("../quirks.zig").inlineAssert; const Allocator = std.mem.Allocator; const ArenaAllocator = std.heap.ArenaAllocator; const fastmem = @import("../fastmem.zig"); -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); const color = @import("color.zig"); const cursor = @import("cursor.zig"); const highlight = @import("highlight.zig"); @@ -226,7 +224,7 @@ pub const RenderState = struct { }; // Dirty state. - pub const Dirty = lib.Enum(lib_target, &.{ + pub const Dirty = lib.Enum(lib.target, &.{ // Not dirty at all. Can skip rendering if prior state was // already rendered. "false", diff --git a/src/terminal/sgr.zig b/src/terminal/sgr.zig index 314d60686..e9b9354c3 100644 --- a/src/terminal/sgr.zig +++ b/src/terminal/sgr.zig @@ -1,15 +1,12 @@ //! SGR (Select Graphic Rendition) attrinvbute parsing and types. const std = @import("std"); -const build_options = @import("terminal_options"); const assert = @import("../quirks.zig").inlineAssert; const testing = std.testing; -const lib = @import("../lib/main.zig"); +const lib = @import("lib.zig"); const color = @import("color.zig"); const SepList = @import("Parser.zig").Action.CSI.SepList; -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; - /// Attribute type for SGR pub const Attribute = union(Tag) { /// Unset all attributes @@ -81,7 +78,7 @@ pub const Attribute = union(Tag) { @"256_fg": u8, pub const Tag = lib.Enum( - lib_target, + lib.target, &.{ "unset", "unknown", @@ -158,7 +155,7 @@ pub const Attribute = union(Tag) { /// C ABI functions. const c_union = lib.TaggedUnion( - lib_target, + lib.target, @This(), // Padding size for C ABI compatibility. // Largest variant is Unknown.C: 2 pointers + 2 usize = 32 bytes on 64-bit. diff --git a/src/terminal/size_report.zig b/src/terminal/size_report.zig index d8089f96e..2ce89a937 100644 --- a/src/terminal/size_report.zig +++ b/src/terminal/size_report.zig @@ -1,11 +1,9 @@ const std = @import("std"); -const build_options = @import("terminal_options"); -const lib = @import("../lib/main.zig"); -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; +const lib = @import("lib.zig"); const CellCountInt = @import("size.zig").CellCountInt; /// Output formats for terminal size reports written to the PTY. -pub const Style = lib.Enum(lib_target, &.{ +pub const Style = lib.Enum(lib.target, &.{ // In-band size reports (mode 2048) "mode_2048", // XTWINOPS: report text area size in pixels @@ -17,7 +15,7 @@ pub const Style = lib.Enum(lib_target, &.{ }); /// Runtime size values used to encode terminal size reports. -pub const Size = lib.Struct(lib_target, struct { +pub const Size = lib.Struct(lib.target, struct { /// Terminal row count in cells. rows: CellCountInt, diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 04410e94c..9771334f9 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -5,7 +5,7 @@ const assert = @import("../quirks.zig").inlineAssert; const testing = std.testing; const Allocator = std.mem.Allocator; const simd = @import("../simd/main.zig"); -const lib = @import("../lib/main.zig"); +const lib = @import("lib.zig"); const Parser = @import("Parser.zig"); const ansi = @import("ansi.zig"); const charsets = @import("charsets.zig"); @@ -29,8 +29,6 @@ const log = std.log.scoped(.stream); /// do something else. const debug = false; -const lib_target: lib.Target = if (build_options.c_abi) .c else .zig; - /// The possible actions that can be emitted by the Stream /// function for handling. pub const Action = union(Key) { @@ -129,7 +127,7 @@ pub const Action = union(Key) { semantic_prompt: SemanticPrompt, pub const Key = lib.Enum( - lib_target, + lib.target, &.{ "print", "print_repeat", @@ -229,7 +227,7 @@ pub const Action = union(Key) { /// C ABI functions. const c_union = lib.TaggedUnion( - lib_target, + lib.target, @This(), // TODO: Before shipping an ABI-compatible libghostty, verify this. // This was just arbitrarily chosen for now. @@ -254,7 +252,7 @@ pub const Action = union(Key) { } }; - pub const InvokeCharset = lib.Struct(lib_target, struct { + pub const InvokeCharset = lib.Struct(lib.target, struct { bank: charsets.ActiveSlot, charset: charsets.Slots, locking: bool, @@ -384,7 +382,7 @@ pub const Action = union(Key) { } }; - pub const ConfigureCharset = lib.Struct(lib_target, struct { + pub const ConfigureCharset = lib.Struct(lib.target, struct { slot: charsets.Slots, charset: charsets.Charset, }); From 2f2f003aa5f807f2b5b3b3be5f83f46fa9825fce Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Mar 2026 07:26:22 -0700 Subject: [PATCH 2/4] terminal/c: use lib.calling_conv to allow Zig calling conv --- src/lib_vt.zig | 3 -- src/terminal/c/allocator.zig | 5 +- src/terminal/c/build_info.zig | 3 +- src/terminal/c/cell.zig | 3 +- src/terminal/c/color.zig | 3 +- src/terminal/c/focus.zig | 3 +- src/terminal/c/formatter.zig | 9 ++-- src/terminal/c/grid_ref.zig | 9 ++-- src/terminal/c/key_encode.zig | 11 +++-- src/terminal/c/key_event.zig | 33 ++++++------- src/terminal/c/modes.zig | 3 +- src/terminal/c/mouse_encode.zig | 13 +++--- src/terminal/c/mouse_event.zig | 23 ++++----- src/terminal/c/osc.zig | 15 +++--- src/terminal/c/paste.zig | 3 +- src/terminal/c/render.zig | 32 ++++++------- src/terminal/c/row.zig | 3 +- src/terminal/c/sgr.zig | 23 ++++----- src/terminal/c/size_report.zig | 3 +- src/terminal/c/style.zig | 5 +- src/terminal/c/terminal.zig | 82 ++++++++++++++++----------------- src/terminal/main.zig | 3 +- 22 files changed, 152 insertions(+), 138 deletions(-) diff --git a/src/lib_vt.zig b/src/lib_vt.zig index 0a749be87..a7d7171bc 100644 --- a/src/lib_vt.zig +++ b/src/lib_vt.zig @@ -264,7 +264,4 @@ test { _ = terminal; _ = @import("lib/main.zig"); @import("std").testing.refAllDecls(input); - if (comptime terminal.options.c_abi) { - _ = terminal.c_api; - } } diff --git a/src/terminal/c/allocator.zig b/src/terminal/c/allocator.zig index f16c7237f..5dc65aab1 100644 --- a/src/terminal/c/allocator.zig +++ b/src/terminal/c/allocator.zig @@ -1,5 +1,6 @@ const std = @import("std"); const testing = std.testing; +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; @@ -11,7 +12,7 @@ const CAllocator = lib_alloc.Allocator; pub fn alloc( alloc_: ?*const CAllocator, len: usize, -) callconv(.c) ?[*]u8 { +) callconv(lib.calling_conv) ?[*]u8 { const allocator = lib_alloc.default(alloc_); const buf = allocator.alloc(u8, len) catch return null; return buf.ptr; @@ -26,7 +27,7 @@ pub fn free( alloc_: ?*const CAllocator, ptr: ?[*]u8, len: usize, -) callconv(.c) void { +) callconv(lib.calling_conv) void { const mem = ptr orelse return; const allocator = lib_alloc.default(alloc_); allocator.free(mem[0..len]); diff --git a/src/terminal/c/build_info.zig b/src/terminal/c/build_info.zig index 312d94fec..5e55e50d5 100644 --- a/src/terminal/c/build_info.zig +++ b/src/terminal/c/build_info.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); +const lib = @import("../lib.zig"); const build_options = @import("terminal_options"); const Result = @import("result.zig").Result; @@ -34,7 +35,7 @@ pub const BuildInfo = enum(c_int) { pub fn get( data: BuildInfo, out: ?*anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(BuildInfo, @intFromEnum(data)) catch { log.warn("build_info invalid data value={d}", .{@intFromEnum(data)}); diff --git a/src/terminal/c/cell.zig b/src/terminal/c/cell.zig index 171867048..c9746da72 100644 --- a/src/terminal/c/cell.zig +++ b/src/terminal/c/cell.zig @@ -1,5 +1,6 @@ const std = @import("std"); const testing = std.testing; +const lib = @import("../lib.zig"); const page = @import("../page.zig"); const Cell = page.Cell; const color = @import("../color.zig"); @@ -102,7 +103,7 @@ pub fn get( cell_: CCell, data: CellData, out: ?*anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(CellData, @intFromEnum(data)) catch { return .invalid_value; diff --git a/src/terminal/c/color.zig b/src/terminal/c/color.zig index 199339706..3d244a19e 100644 --- a/src/terminal/c/color.zig +++ b/src/terminal/c/color.zig @@ -1,3 +1,4 @@ +const lib = @import("../lib.zig"); const color = @import("../color.zig"); pub fn rgb_get( @@ -5,7 +6,7 @@ pub fn rgb_get( r: *u8, g: *u8, b: *u8, -) callconv(.c) void { +) callconv(lib.calling_conv) void { r.* = c.r; g.* = c.g; b.* = c.b; diff --git a/src/terminal/c/focus.zig b/src/terminal/c/focus.zig index 05930c8f3..2c53191db 100644 --- a/src/terminal/c/focus.zig +++ b/src/terminal/c/focus.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const lib = @import("../lib.zig"); const terminal_focus = @import("../focus.zig"); const Result = @import("result.zig").Result; @@ -7,7 +8,7 @@ pub fn encode( out_: ?[*]u8, out_len: usize, out_written: *usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { var writer: std.Io.Writer = .fixed(if (out_) |out| out[0..out_len] else &.{}); terminal_focus.encode(&writer, event) catch |err| switch (err) { error.WriteFailed => { diff --git a/src/terminal/c/formatter.zig b/src/terminal/c/formatter.zig index a768287ad..dbaa0acc8 100644 --- a/src/terminal/c/formatter.zig +++ b/src/terminal/c/formatter.zig @@ -1,5 +1,6 @@ const std = @import("std"); const testing = std.testing; +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const terminal_c = @import("terminal.zig"); @@ -100,7 +101,7 @@ pub fn terminal_new( result: *Formatter, terminal_: terminal_c.Terminal, opts: TerminalOptions, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { result.* = terminal_new_( alloc_, terminal_, @@ -151,7 +152,7 @@ pub fn format_buf( out_: ?[*]u8, out_len: usize, out_written: *usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const wrapper = formatter_ orelse return .invalid_value; var writer: std.Io.Writer = .fixed(if (out_) |out| @@ -181,7 +182,7 @@ pub fn format_alloc( alloc_: ?*const CAllocator, out_ptr: *?[*]u8, out_len: *usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const wrapper = formatter_ orelse return .invalid_value; const alloc = lib_alloc.default(alloc_); @@ -198,7 +199,7 @@ pub fn format_alloc( return .success; } -pub fn free(formatter_: Formatter) callconv(.c) void { +pub fn free(formatter_: Formatter) callconv(lib.calling_conv) void { const wrapper = formatter_ orelse return; const alloc = wrapper.alloc; alloc.destroy(wrapper); diff --git a/src/terminal/c/grid_ref.zig b/src/terminal/c/grid_ref.zig index d6afb0c45..d029c5951 100644 --- a/src/terminal/c/grid_ref.zig +++ b/src/terminal/c/grid_ref.zig @@ -1,5 +1,6 @@ const std = @import("std"); const testing = std.testing; +const lib = @import("../lib.zig"); const page = @import("../page.zig"); const PageList = @import("../PageList.zig"); const size = @import("../size.zig"); @@ -40,7 +41,7 @@ pub const CGridRef = extern struct { pub fn grid_ref_cell( ref: *const CGridRef, out: ?*cell_c.CCell, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const p = ref.toPin() orelse return .invalid_value; if (out) |o| o.* = @bitCast(p.rowAndCell().cell.*); return .success; @@ -49,7 +50,7 @@ pub fn grid_ref_cell( pub fn grid_ref_row( ref: *const CGridRef, out: ?*row_c.CRow, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const p = ref.toPin() orelse return .invalid_value; if (out) |o| o.* = @bitCast(p.rowAndCell().row.*); return .success; @@ -60,7 +61,7 @@ pub fn grid_ref_graphemes( out_buf: ?[*]u32, buf_len: usize, out_len: *usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const p = ref.toPin() orelse return .invalid_value; const cell = p.rowAndCell().cell; @@ -91,7 +92,7 @@ pub fn grid_ref_graphemes( pub fn grid_ref_style( ref: *const CGridRef, out: ?*style_c.Style, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const p = ref.toPin() orelse return .invalid_value; if (out) |o| { const cell = p.rowAndCell().cell; diff --git a/src/terminal/c/key_encode.zig b/src/terminal/c/key_encode.zig index 616a438d9..2dbf71821 100644 --- a/src/terminal/c/key_encode.zig +++ b/src/terminal/c/key_encode.zig @@ -1,5 +1,6 @@ const std = @import("std"); const Allocator = std.mem.Allocator; +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const key_encode = @import("../../input/key_encode.zig"); @@ -25,7 +26,7 @@ pub const Encoder = ?*KeyEncoderWrapper; pub fn new( alloc_: ?*const CAllocator, result: *Encoder, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const alloc = lib_alloc.default(alloc_); const ptr = alloc.create(KeyEncoderWrapper) catch return .out_of_memory; @@ -37,7 +38,7 @@ pub fn new( return .success; } -pub fn free(encoder_: Encoder) callconv(.c) void { +pub fn free(encoder_: Encoder) callconv(lib.calling_conv) void { const wrapper = encoder_ orelse return; const alloc = wrapper.alloc; alloc.destroy(wrapper); @@ -72,7 +73,7 @@ pub fn setopt( encoder_: Encoder, option: Option, value: ?*const anyopaque, -) callconv(.c) void { +) callconv(lib.calling_conv) void { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(Option, @intFromEnum(option)) catch { log.warn("setopt invalid option value={d}", .{@intFromEnum(option)}); @@ -120,7 +121,7 @@ fn setoptTyped( pub fn setopt_from_terminal( encoder_: Encoder, terminal_: Terminal, -) callconv(.c) void { +) callconv(lib.calling_conv) void { const wrapper = encoder_ orelse return; const t: *ZigTerminal = (terminal_ orelse return).terminal; wrapper.opts = .fromTerminal(t); @@ -132,7 +133,7 @@ pub fn encode( out_: ?[*]u8, out_len: usize, out_written: *usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { // Attempt to write to this buffer var writer: std.Io.Writer = .fixed(if (out_) |out| out[0..out_len] else &.{}); key_encode.encode( diff --git a/src/terminal/c/key_event.zig b/src/terminal/c/key_event.zig index 748b8799c..d3fe298d4 100644 --- a/src/terminal/c/key_event.zig +++ b/src/terminal/c/key_event.zig @@ -1,5 +1,6 @@ const std = @import("std"); const Allocator = std.mem.Allocator; +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const key = @import("../../input/key.zig"); @@ -21,7 +22,7 @@ pub const Event = ?*KeyEventWrapper; pub fn new( alloc_: ?*const CAllocator, result: *Event, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const alloc = lib_alloc.default(alloc_); const ptr = alloc.create(KeyEventWrapper) catch return .out_of_memory; @@ -30,13 +31,13 @@ pub fn new( return .success; } -pub fn free(event_: Event) callconv(.c) void { +pub fn free(event_: Event) callconv(lib.calling_conv) void { const wrapper = event_ orelse return; const alloc = wrapper.alloc; alloc.destroy(wrapper); } -pub fn set_action(event_: Event, action: key.Action) callconv(.c) void { +pub fn set_action(event_: Event, action: key.Action) callconv(lib.calling_conv) void { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(key.Action, @intFromEnum(action)) catch { log.warn("set_action invalid action value={d}", .{@intFromEnum(action)}); @@ -48,12 +49,12 @@ pub fn set_action(event_: Event, action: key.Action) callconv(.c) void { event.action = action; } -pub fn get_action(event_: Event) callconv(.c) key.Action { +pub fn get_action(event_: Event) callconv(lib.calling_conv) key.Action { const event: *key.KeyEvent = &event_.?.event; return event.action; } -pub fn set_key(event_: Event, k: key.Key) callconv(.c) void { +pub fn set_key(event_: Event, k: key.Key) callconv(lib.calling_conv) void { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(key.Key, @intFromEnum(k)) catch { log.warn("set_key invalid key value={d}", .{@intFromEnum(k)}); @@ -65,58 +66,58 @@ pub fn set_key(event_: Event, k: key.Key) callconv(.c) void { event.key = k; } -pub fn get_key(event_: Event) callconv(.c) key.Key { +pub fn get_key(event_: Event) callconv(lib.calling_conv) key.Key { const event: *key.KeyEvent = &event_.?.event; return event.key; } -pub fn set_mods(event_: Event, mods: key.Mods) callconv(.c) void { +pub fn set_mods(event_: Event, mods: key.Mods) callconv(lib.calling_conv) void { const event: *key.KeyEvent = &event_.?.event; event.mods = mods; } -pub fn get_mods(event_: Event) callconv(.c) key.Mods { +pub fn get_mods(event_: Event) callconv(lib.calling_conv) key.Mods { const event: *key.KeyEvent = &event_.?.event; return event.mods; } -pub fn set_consumed_mods(event_: Event, consumed_mods: key.Mods) callconv(.c) void { +pub fn set_consumed_mods(event_: Event, consumed_mods: key.Mods) callconv(lib.calling_conv) void { const event: *key.KeyEvent = &event_.?.event; event.consumed_mods = consumed_mods; } -pub fn get_consumed_mods(event_: Event) callconv(.c) key.Mods { +pub fn get_consumed_mods(event_: Event) callconv(lib.calling_conv) key.Mods { const event: *key.KeyEvent = &event_.?.event; return event.consumed_mods; } -pub fn set_composing(event_: Event, composing: bool) callconv(.c) void { +pub fn set_composing(event_: Event, composing: bool) callconv(lib.calling_conv) void { const event: *key.KeyEvent = &event_.?.event; event.composing = composing; } -pub fn get_composing(event_: Event) callconv(.c) bool { +pub fn get_composing(event_: Event) callconv(lib.calling_conv) bool { const event: *key.KeyEvent = &event_.?.event; return event.composing; } -pub fn set_utf8(event_: Event, utf8: ?[*]const u8, len: usize) callconv(.c) void { +pub fn set_utf8(event_: Event, utf8: ?[*]const u8, len: usize) callconv(lib.calling_conv) void { const event: *key.KeyEvent = &event_.?.event; event.utf8 = if (utf8) |ptr| ptr[0..len] else ""; } -pub fn get_utf8(event_: Event, len: ?*usize) callconv(.c) ?[*]const u8 { +pub fn get_utf8(event_: Event, len: ?*usize) callconv(lib.calling_conv) ?[*]const u8 { const event: *key.KeyEvent = &event_.?.event; if (len) |l| l.* = event.utf8.len; return if (event.utf8.len == 0) null else event.utf8.ptr; } -pub fn set_unshifted_codepoint(event_: Event, codepoint: u32) callconv(.c) void { +pub fn set_unshifted_codepoint(event_: Event, codepoint: u32) callconv(lib.calling_conv) void { const event: *key.KeyEvent = &event_.?.event; event.unshifted_codepoint = @truncate(codepoint); } -pub fn get_unshifted_codepoint(event_: Event) callconv(.c) u32 { +pub fn get_unshifted_codepoint(event_: Event) callconv(lib.calling_conv) u32 { const event: *key.KeyEvent = &event_.?.event; return event.unshifted_codepoint; } diff --git a/src/terminal/c/modes.zig b/src/terminal/c/modes.zig index d0d5fedf0..449ce63e3 100644 --- a/src/terminal/c/modes.zig +++ b/src/terminal/c/modes.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const lib = @import("../lib.zig"); const modes = @import("../modes.zig"); const Result = @import("result.zig").Result; @@ -20,7 +21,7 @@ pub fn report_encode( out_: ?[*]u8, out_len: usize, out_written: *usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const mode_tag: modes.ModeTag = @bitCast(tag); const report: modes.Report = .{ .tag = mode_tag, diff --git a/src/terminal/c/mouse_encode.zig b/src/terminal/c/mouse_encode.zig index 224b64837..6f9eb79da 100644 --- a/src/terminal/c/mouse_encode.zig +++ b/src/terminal/c/mouse_encode.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const testing = std.testing; +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const input_mouse_encode = @import("../../input/mouse_encode.zig"); @@ -89,7 +90,7 @@ pub const Option = enum(c_int) { pub fn new( alloc_: ?*const CAllocator, result: *Encoder, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const alloc = lib_alloc.default(alloc_); const ptr = alloc.create(MouseEncoderWrapper) catch return .out_of_memory; @@ -101,7 +102,7 @@ pub fn new( return .success; } -pub fn free(encoder_: Encoder) callconv(.c) void { +pub fn free(encoder_: Encoder) callconv(lib.calling_conv) void { const wrapper = encoder_ orelse return; const alloc = wrapper.alloc; alloc.destroy(wrapper); @@ -111,7 +112,7 @@ pub fn setopt( encoder_: Encoder, option: Option, value: ?*const anyopaque, -) callconv(.c) void { +) callconv(lib.calling_conv) void { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(Option, @intFromEnum(option)) catch { log.warn("setopt invalid option value={d}", .{@intFromEnum(option)}); @@ -187,7 +188,7 @@ fn setoptTyped( pub fn setopt_from_terminal( encoder_: Encoder, terminal_: Terminal, -) callconv(.c) void { +) callconv(lib.calling_conv) void { const wrapper = encoder_ orelse return; const t: *ZigTerminal = (terminal_ orelse return).terminal; wrapper.opts.event = t.flags.mouse_event; @@ -195,7 +196,7 @@ pub fn setopt_from_terminal( wrapper.last_cell = null; } -pub fn reset(encoder_: Encoder) callconv(.c) void { +pub fn reset(encoder_: Encoder) callconv(lib.calling_conv) void { const wrapper = encoder_ orelse return; wrapper.last_cell = null; } @@ -206,7 +207,7 @@ pub fn encode( out_: ?[*]u8, out_len: usize, out_written: *usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const wrapper = encoder_ orelse return .invalid_value; const event = event_ orelse return .invalid_value; diff --git a/src/terminal/c/mouse_event.zig b/src/terminal/c/mouse_event.zig index 91f4e2126..0f634d4da 100644 --- a/src/terminal/c/mouse_event.zig +++ b/src/terminal/c/mouse_event.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const testing = std.testing; +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const key = @import("../../input/key.zig"); @@ -34,7 +35,7 @@ pub const Mods = key.Mods; pub fn new( alloc_: ?*const CAllocator, result: *Event, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const alloc = lib_alloc.default(alloc_); const ptr = alloc.create(MouseEventWrapper) catch return .out_of_memory; @@ -43,13 +44,13 @@ pub fn new( return .success; } -pub fn free(event_: Event) callconv(.c) void { +pub fn free(event_: Event) callconv(lib.calling_conv) void { const wrapper = event_ orelse return; const alloc = wrapper.alloc; alloc.destroy(wrapper); } -pub fn set_action(event_: Event, action: Action) callconv(.c) void { +pub fn set_action(event_: Event, action: Action) callconv(lib.calling_conv) void { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(Action, @intFromEnum(action)) catch { log.warn("set_action invalid action value={d}", .{@intFromEnum(action)}); @@ -60,11 +61,11 @@ pub fn set_action(event_: Event, action: Action) callconv(.c) void { event_.?.event.action = action; } -pub fn get_action(event_: Event) callconv(.c) Action { +pub fn get_action(event_: Event) callconv(lib.calling_conv) Action { return event_.?.event.action; } -pub fn set_button(event_: Event, button: Button) callconv(.c) void { +pub fn set_button(event_: Event, button: Button) callconv(lib.calling_conv) void { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(Button, @intFromEnum(button)) catch { log.warn("set_button invalid button value={d}", .{@intFromEnum(button)}); @@ -75,11 +76,11 @@ pub fn set_button(event_: Event, button: Button) callconv(.c) void { event_.?.event.button = button; } -pub fn clear_button(event_: Event) callconv(.c) void { +pub fn clear_button(event_: Event) callconv(lib.calling_conv) void { event_.?.event.button = null; } -pub fn get_button(event_: Event, out: ?*Button) callconv(.c) bool { +pub fn get_button(event_: Event, out: ?*Button) callconv(lib.calling_conv) bool { if (event_.?.event.button) |button| { if (out) |ptr| ptr.* = button; return true; @@ -88,19 +89,19 @@ pub fn get_button(event_: Event, out: ?*Button) callconv(.c) bool { return false; } -pub fn set_mods(event_: Event, mods: Mods) callconv(.c) void { +pub fn set_mods(event_: Event, mods: Mods) callconv(lib.calling_conv) void { event_.?.event.mods = mods; } -pub fn get_mods(event_: Event) callconv(.c) Mods { +pub fn get_mods(event_: Event) callconv(lib.calling_conv) Mods { return event_.?.event.mods; } -pub fn set_position(event_: Event, pos: Position) callconv(.c) void { +pub fn set_position(event_: Event, pos: Position) callconv(lib.calling_conv) void { event_.?.event.pos = pos; } -pub fn get_position(event_: Event) callconv(.c) Position { +pub fn get_position(event_: Event) callconv(lib.calling_conv) Position { return event_.?.event.pos; } diff --git a/src/terminal/c/osc.zig b/src/terminal/c/osc.zig index 648e448fd..8d0c065f9 100644 --- a/src/terminal/c/osc.zig +++ b/src/terminal/c/osc.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const osc = @import("../osc.zig"); @@ -15,7 +16,7 @@ pub const Command = ?*osc.Command; pub fn new( alloc_: ?*const CAllocator, result: *Parser, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const alloc = lib_alloc.default(alloc_); const ptr = alloc.create(osc.Parser) catch return .out_of_memory; @@ -24,7 +25,7 @@ pub fn new( return .success; } -pub fn free(parser_: Parser) callconv(.c) void { +pub fn free(parser_: Parser) callconv(lib.calling_conv) void { // C-built parsers always have an associated allocator. const parser = parser_ orelse return; const alloc = parser.alloc.?; @@ -32,19 +33,19 @@ pub fn free(parser_: Parser) callconv(.c) void { alloc.destroy(parser); } -pub fn reset(parser_: Parser) callconv(.c) void { +pub fn reset(parser_: Parser) callconv(lib.calling_conv) void { parser_.?.reset(); } -pub fn next(parser_: Parser, byte: u8) callconv(.c) void { +pub fn next(parser_: Parser, byte: u8) callconv(lib.calling_conv) void { parser_.?.next(byte); } -pub fn end(parser_: Parser, terminator: u8) callconv(.c) Command { +pub fn end(parser_: Parser, terminator: u8) callconv(lib.calling_conv) Command { return parser_.?.end(terminator); } -pub fn commandType(command_: Command) callconv(.c) osc.Command.Key { +pub fn commandType(command_: Command) callconv(lib.calling_conv) osc.Command.Key { const command = command_ orelse return .invalid; return command.*; } @@ -67,7 +68,7 @@ pub fn commandData( command_: Command, data: CommandData, out: ?*anyopaque, -) callconv(.c) bool { +) callconv(lib.calling_conv) bool { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(CommandData, @intFromEnum(data)) catch { log.warn("commandData invalid data value={d}", .{@intFromEnum(data)}); diff --git a/src/terminal/c/paste.zig b/src/terminal/c/paste.zig index eb4117a70..69df416c0 100644 --- a/src/terminal/c/paste.zig +++ b/src/terminal/c/paste.zig @@ -1,7 +1,8 @@ const std = @import("std"); +const lib = @import("../lib.zig"); const paste = @import("../../input/paste.zig"); -pub fn is_safe(data: ?[*]const u8, len: usize) callconv(.c) bool { +pub fn is_safe(data: ?[*]const u8, len: usize) callconv(lib.calling_conv) bool { const slice: []const u8 = if (data) |v| v[0..len] else &.{}; return paste.isSafe(slice); } diff --git a/src/terminal/c/render.zig b/src/terminal/c/render.zig index e29dfd019..6d9ac8d15 100644 --- a/src/terminal/c/render.zig +++ b/src/terminal/c/render.zig @@ -143,7 +143,7 @@ pub const Colors = extern struct { pub fn new( alloc_: ?*const CAllocator, result: *RenderState, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { result.* = new_(alloc_) catch |err| { result.* = null; return switch (err) { @@ -162,7 +162,7 @@ fn new_(alloc_: ?*const CAllocator) error{OutOfMemory}!*RenderStateWrapper { return ptr; } -pub fn free(state_: RenderState) callconv(.c) void { +pub fn free(state_: RenderState) callconv(lib.calling_conv) void { const state = state_ orelse return; const alloc = state.alloc; state.state.deinit(alloc); @@ -172,7 +172,7 @@ pub fn free(state_: RenderState) callconv(.c) void { pub fn update( state_: RenderState, terminal_: terminal_c.Terminal, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const state = state_ orelse return .invalid_value; const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal; @@ -184,7 +184,7 @@ pub fn get( state_: RenderState, data: Data, out: ?*anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(Data, @intFromEnum(data)) catch { log.warn("render_state_get invalid data value={d}", .{@intFromEnum(data)}); @@ -263,7 +263,7 @@ pub fn set( state_: RenderState, option: SetOption, value: ?*const anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(SetOption, @intFromEnum(option)) catch { log.warn("render_state_set invalid option value={d}", .{@intFromEnum(option)}); @@ -296,7 +296,7 @@ fn setTyped( pub fn colors_get( state_: RenderState, out_colors_: ?*Colors, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const state = state_ orelse return .invalid_value; const out_colors = out_colors_ orelse return .invalid_value; const out_size = out_colors.size; @@ -354,7 +354,7 @@ pub fn colors_get( pub fn row_iterator_new( alloc_: ?*const CAllocator, result: *RowIterator, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const alloc = lib_alloc.default(alloc_); const ptr = alloc.create(RowIteratorWrapper) catch { result.* = null; @@ -372,13 +372,13 @@ pub fn row_iterator_new( return .success; } -pub fn row_iterator_free(iterator_: RowIterator) callconv(.c) void { +pub fn row_iterator_free(iterator_: RowIterator) callconv(lib.calling_conv) void { const iterator = iterator_ orelse return; const alloc = iterator.alloc; alloc.destroy(iterator); } -pub fn row_iterator_next(iterator_: RowIterator) callconv(.c) bool { +pub fn row_iterator_next(iterator_: RowIterator) callconv(lib.calling_conv) bool { const it = iterator_ orelse return false; const next_y: size.CellCountInt = if (it.y) |y| y + 1 else 0; if (next_y >= it.raws.len) return false; @@ -389,7 +389,7 @@ pub fn row_iterator_next(iterator_: RowIterator) callconv(.c) bool { pub fn row_cells_new( alloc_: ?*const CAllocator, result: *RowCells, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const alloc = lib_alloc.default(alloc_); const ptr = alloc.create(RowCellsWrapper) catch { result.* = null; @@ -407,7 +407,7 @@ pub fn row_cells_new( return .success; } -pub fn row_cells_next(cells_: RowCells) callconv(.c) bool { +pub fn row_cells_next(cells_: RowCells) callconv(lib.calling_conv) bool { const cells = cells_ orelse return false; const next_x: size.CellCountInt = if (cells.x) |x| x + 1 else 0; if (next_x >= cells.raws.len) return false; @@ -415,14 +415,14 @@ pub fn row_cells_next(cells_: RowCells) callconv(.c) bool { return true; } -pub fn row_cells_select(cells_: RowCells, x: size.CellCountInt) callconv(.c) Result { +pub fn row_cells_select(cells_: RowCells, x: size.CellCountInt) callconv(lib.calling_conv) Result { const cells = cells_ orelse return .invalid_value; if (x >= cells.raws.len) return .invalid_value; cells.x = x; return .success; } -pub fn row_cells_free(cells_: RowCells) callconv(.c) void { +pub fn row_cells_free(cells_: RowCells) callconv(lib.calling_conv) void { const cells = cells_ orelse return; const alloc = cells.alloc; alloc.destroy(cells); @@ -455,7 +455,7 @@ pub fn row_cells_get( cells_: RowCells, data: RowCellsData, out: ?*anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(RowCellsData, @intFromEnum(data)) catch { log.warn("render_state_row_cells_get invalid data value={d}", .{@intFromEnum(data)}); @@ -555,7 +555,7 @@ pub fn row_get( iterator_: RowIterator, data: RowData, out: ?*anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(RowData, @intFromEnum(data)) catch { log.warn("render_state_row_get invalid data value={d}", .{@intFromEnum(data)}); @@ -605,7 +605,7 @@ pub fn row_set( iterator_: RowIterator, option: RowOption, value: ?*const anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(RowOption, @intFromEnum(option)) catch { log.warn("render_state_row_set invalid option value={d}", .{@intFromEnum(option)}); diff --git a/src/terminal/c/row.zig b/src/terminal/c/row.zig index 7b765b56a..d45327066 100644 --- a/src/terminal/c/row.zig +++ b/src/terminal/c/row.zig @@ -1,5 +1,6 @@ const std = @import("std"); const testing = std.testing; +const lib = @import("../lib.zig"); const page = @import("../page.zig"); const Row = page.Row; const Result = @import("result.zig").Result; @@ -65,7 +66,7 @@ pub fn get( row_: CRow, data: RowData, out: ?*anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(RowData, @intFromEnum(data)) catch { return .invalid_value; diff --git a/src/terminal/c/sgr.zig b/src/terminal/c/sgr.zig index 53536417f..7bd47b9ae 100644 --- a/src/terminal/c/sgr.zig +++ b/src/terminal/c/sgr.zig @@ -1,6 +1,7 @@ const std = @import("std"); const testing = std.testing; const Allocator = std.mem.Allocator; +const lib = @import("../lib.zig"); const lib_alloc = @import("../../lib/allocator.zig"); const CAllocator = lib_alloc.Allocator; const sgr = @import("../sgr.zig"); @@ -20,7 +21,7 @@ pub const Parser = ?*ParserWrapper; pub fn new( alloc_: ?*const CAllocator, result: *Parser, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const alloc = lib_alloc.default(alloc_); const ptr = alloc.create(ParserWrapper) catch return .out_of_memory; @@ -32,7 +33,7 @@ pub fn new( return .success; } -pub fn free(parser_: Parser) callconv(.c) void { +pub fn free(parser_: Parser) callconv(lib.calling_conv) void { const wrapper = parser_ orelse return; const alloc = wrapper.alloc; const parser: *sgr.Parser = &wrapper.parser; @@ -40,7 +41,7 @@ pub fn free(parser_: Parser) callconv(.c) void { alloc.destroy(wrapper); } -pub fn reset(parser_: Parser) callconv(.c) void { +pub fn reset(parser_: Parser) callconv(lib.calling_conv) void { const wrapper = parser_ orelse return; const parser: *sgr.Parser = &wrapper.parser; parser.idx = 0; @@ -51,7 +52,7 @@ pub fn setParams( params: [*]const u16, seps_: ?[*]const u8, len: usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const wrapper = parser_ orelse return .invalid_value; const alloc = wrapper.alloc; const parser: *sgr.Parser = &wrapper.parser; @@ -87,7 +88,7 @@ pub fn setParams( pub fn next( parser_: Parser, result: *sgr.Attribute.C, -) callconv(.c) bool { +) callconv(lib.calling_conv) bool { const wrapper = parser_ orelse return false; const parser: *sgr.Parser = &wrapper.parser; if (parser.next()) |attr| { @@ -101,7 +102,7 @@ pub fn next( pub fn unknown_full( unknown: sgr.Attribute.Unknown.C, ptr: ?*[*]const u16, -) callconv(.c) usize { +) callconv(lib.calling_conv) usize { if (ptr) |p| p.* = unknown.full_ptr; return unknown.full_len; } @@ -109,30 +110,30 @@ pub fn unknown_full( pub fn unknown_partial( unknown: sgr.Attribute.Unknown.C, ptr: ?*[*]const u16, -) callconv(.c) usize { +) callconv(lib.calling_conv) usize { if (ptr) |p| p.* = unknown.partial_ptr; return unknown.partial_len; } pub fn attribute_tag( attr: sgr.Attribute.C, -) callconv(.c) sgr.Attribute.Tag { +) callconv(lib.calling_conv) sgr.Attribute.Tag { return attr.tag; } pub fn attribute_value( attr: *sgr.Attribute.C, -) callconv(.c) *sgr.Attribute.CValue { +) callconv(lib.calling_conv) *sgr.Attribute.CValue { return &attr.value; } -pub fn wasm_alloc_attribute() callconv(.c) *sgr.Attribute.C { +pub fn wasm_alloc_attribute() callconv(lib.calling_conv) *sgr.Attribute.C { const alloc = std.heap.wasm_allocator; const ptr = alloc.create(sgr.Attribute.C) catch @panic("out of memory"); return ptr; } -pub fn wasm_free_attribute(attr: *sgr.Attribute.C) callconv(.c) void { +pub fn wasm_free_attribute(attr: *sgr.Attribute.C) callconv(lib.calling_conv) void { const alloc = std.heap.wasm_allocator; alloc.destroy(attr); } diff --git a/src/terminal/c/size_report.zig b/src/terminal/c/size_report.zig index dac909a5c..1c350c8f7 100644 --- a/src/terminal/c/size_report.zig +++ b/src/terminal/c/size_report.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const lib = @import("../lib.zig"); const terminal_size_report = @import("../size_report.zig"); const Result = @import("result.zig").Result; @@ -14,7 +15,7 @@ pub fn encode( out_: ?[*]u8, out_len: usize, out_written: *usize, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { var writer: std.Io.Writer = .fixed(if (out_) |out| out[0..out_len] else &.{}); terminal_size_report.encode(&writer, style, size) catch |err| switch (err) { error.WriteFailed => { diff --git a/src/terminal/c/style.zig b/src/terminal/c/style.zig index 99f591c10..82729fa94 100644 --- a/src/terminal/c/style.zig +++ b/src/terminal/c/style.zig @@ -1,6 +1,7 @@ const std = @import("std"); const assert = std.debug.assert; const testing = std.testing; +const lib = @import("../lib.zig"); const style = @import("../style.zig"); const color = @import("../color.zig"); const sgr = @import("../sgr.zig"); @@ -77,13 +78,13 @@ pub const Style = extern struct { }; /// Returns the default style. -pub fn default_style(result: *Style) callconv(.c) void { +pub fn default_style(result: *Style) callconv(lib.calling_conv) void { result.* = .fromStyle(.{}); assert(result.size == @sizeOf(Style)); } /// Returns true if the style is the default style. -pub fn style_is_default(s: *const Style) callconv(.c) bool { +pub fn style_is_default(s: *const Style) callconv(lib.calling_conv) bool { assert(s.size == @sizeOf(Style)); return s.fg_color.tag == .none and s.bg_color.tag == .none and diff --git a/src/terminal/c/terminal.zig b/src/terminal/c/terminal.zig index c01d1adab..9eb3282b1 100644 --- a/src/terminal/c/terminal.zig +++ b/src/terminal/c/terminal.zig @@ -55,39 +55,39 @@ const Effects = struct { da_features_buf: [64]device_attributes.Primary.Feature = undefined, /// C function pointer type for the write_pty callback. - pub const WritePtyFn = *const fn (Terminal, ?*anyopaque, [*]const u8, usize) callconv(.c) void; + pub const WritePtyFn = *const fn (Terminal, ?*anyopaque, [*]const u8, usize) callconv(lib.calling_conv) void; /// C function pointer type for the bell callback. - pub const BellFn = *const fn (Terminal, ?*anyopaque) callconv(.c) void; + pub const BellFn = *const fn (Terminal, ?*anyopaque) callconv(lib.calling_conv) void; /// C function pointer type for the color_scheme callback. /// Returns true and fills out_scheme if a color scheme is available, /// or returns false to silently ignore the query. - pub const ColorSchemeFn = *const fn (Terminal, ?*anyopaque, *device_status.ColorScheme) callconv(.c) bool; + pub const ColorSchemeFn = *const fn (Terminal, ?*anyopaque, *device_status.ColorScheme) callconv(lib.calling_conv) bool; /// C function pointer type for the enquiry callback. /// Returns the response bytes. The memory must remain valid /// until the callback returns. - pub const EnquiryFn = *const fn (Terminal, ?*anyopaque) callconv(.c) lib.String; + pub const EnquiryFn = *const fn (Terminal, ?*anyopaque) callconv(lib.calling_conv) lib.String; /// C function pointer type for the xtversion callback. /// Returns the version string (e.g. "ghostty 1.2.3"). The memory /// must remain valid until the callback returns. An empty string /// (len=0) causes the default "libghostty" to be reported. - pub const XtversionFn = *const fn (Terminal, ?*anyopaque) callconv(.c) lib.String; + pub const XtversionFn = *const fn (Terminal, ?*anyopaque) callconv(lib.calling_conv) lib.String; /// C function pointer type for the title_changed callback. - pub const TitleChangedFn = *const fn (Terminal, ?*anyopaque) callconv(.c) void; + pub const TitleChangedFn = *const fn (Terminal, ?*anyopaque) callconv(lib.calling_conv) void; /// C function pointer type for the size callback. /// Returns true and fills out_size if size is available, /// or returns false to silently ignore the query. - pub const SizeFn = *const fn (Terminal, ?*anyopaque, *size_report.Size) callconv(.c) bool; + pub const SizeFn = *const fn (Terminal, ?*anyopaque, *size_report.Size) callconv(lib.calling_conv) bool; /// C function pointer type for the device_attributes callback. /// Returns true and fills out_attrs if attributes are available, /// or returns false to silently ignore the query. - pub const DeviceAttributesFn = *const fn (Terminal, ?*anyopaque, *CDeviceAttributes) callconv(.c) bool; + pub const DeviceAttributesFn = *const fn (Terminal, ?*anyopaque, *CDeviceAttributes) callconv(lib.calling_conv) bool; /// C-compatible device attributes struct. /// C: GhosttyDeviceAttributes @@ -221,7 +221,7 @@ pub fn new( alloc_: ?*const CAllocator, result: *Terminal, opts: Options, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { result.* = new_(alloc_, opts) catch |err| { result.* = null; return switch (err) { @@ -282,7 +282,7 @@ pub fn vt_write( terminal_: Terminal, ptr: [*]const u8, len: usize, -) callconv(.c) void { +) callconv(lib.calling_conv) void { const wrapper = terminal_ orelse return; wrapper.stream.nextSlice(ptr[0..len]); } @@ -322,7 +322,7 @@ pub fn set( terminal_: Terminal, option: Option, value: ?*const anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(Option, @intFromEnum(option)) catch { log.warn("terminal_set invalid option value={d}", .{@intFromEnum(option)}); @@ -374,7 +374,7 @@ pub const ScrollViewport = ZigTerminal.ScrollViewport.C; pub fn scroll_viewport( terminal_: Terminal, behavior: ScrollViewport, -) callconv(.c) void { +) callconv(lib.calling_conv) void { const t: *ZigTerminal = (terminal_ orelse return).terminal; t.scrollViewport(switch (behavior.tag) { .top => .top, @@ -389,7 +389,7 @@ pub fn resize( rows: size.CellCountInt, cell_width_px: u32, cell_height_px: u32, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const wrapper = terminal_ orelse return .invalid_value; const t = wrapper.terminal; if (cols == 0 or rows == 0) return .invalid_value; @@ -423,7 +423,7 @@ pub fn resize( return .success; } -pub fn reset(terminal_: Terminal) callconv(.c) void { +pub fn reset(terminal_: Terminal) callconv(lib.calling_conv) void { const t: *ZigTerminal = (terminal_ orelse return).terminal; t.fullReset(); } @@ -432,7 +432,7 @@ pub fn mode_get( terminal_: Terminal, tag: modes.ModeTag.Backing, out_value: *bool, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal; const mode_tag: modes.ModeTag = @bitCast(tag); const mode = modes.modeFromInt(mode_tag.value, mode_tag.ansi) orelse return .invalid_value; @@ -444,7 +444,7 @@ pub fn mode_set( terminal_: Terminal, tag: modes.ModeTag.Backing, value: bool, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal; const mode_tag: modes.ModeTag = @bitCast(tag); const mode = modes.modeFromInt(mode_tag.value, mode_tag.ansi) orelse return .invalid_value; @@ -500,7 +500,7 @@ pub fn get( terminal_: Terminal, data: TerminalData, out: ?*anyopaque, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { if (comptime std.debug.runtime_safety) { _ = std.meta.intToEnum(TerminalData, @intFromEnum(data)) catch { log.warn("terminal_get invalid data value={d}", .{@intFromEnum(data)}); @@ -561,7 +561,7 @@ pub fn grid_ref( terminal_: Terminal, pt: point.Point.C, out_ref: ?*grid_ref_c.CGridRef, -) callconv(.c) Result { +) callconv(lib.calling_conv) Result { const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal; const zig_pt: point.Point = switch (pt.tag) { .active => .{ .active = pt.value.active }, @@ -575,7 +575,7 @@ pub fn grid_ref( return .success; } -pub fn free(terminal_: Terminal) callconv(.c) void { +pub fn free(terminal_: Terminal) callconv(lib.calling_conv) void { const wrapper = terminal_ orelse return; const t = wrapper.terminal; @@ -1162,7 +1162,7 @@ test "set write_pty callback" { last_userdata = null; } - fn writePty(_: Terminal, ud: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, ud: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); last_userdata = ud; @@ -1214,7 +1214,7 @@ test "set write_pty null clears callback" { const S = struct { var called: bool = false; - fn writePty(_: Terminal, _: ?*anyopaque, _: [*]const u8, _: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, _: [*]const u8, _: usize) callconv(lib.calling_conv) void { called = true; } }; @@ -1245,7 +1245,7 @@ test "set bell callback" { var bell_count: usize = 0; var last_userdata: ?*anyopaque = null; - fn bell(_: Terminal, ud: ?*anyopaque) callconv(.c) void { + fn bell(_: Terminal, ud: ?*anyopaque) callconv(lib.calling_conv) void { bell_count += 1; last_userdata = ud; } @@ -1306,13 +1306,13 @@ test "set enquiry callback" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } const response = "OK"; - fn enquiry(_: Terminal, _: ?*anyopaque) callconv(.c) lib.String { + fn enquiry(_: Terminal, _: ?*anyopaque) callconv(lib.calling_conv) lib.String { return .{ .ptr = response, .len = response.len }; } }; @@ -1365,13 +1365,13 @@ test "set xtversion callback" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } const version = "myterm 1.0"; - fn xtversion(_: Terminal, _: ?*anyopaque) callconv(.c) lib.String { + fn xtversion(_: Terminal, _: ?*anyopaque) callconv(lib.calling_conv) lib.String { return .{ .ptr = version, .len = version.len }; } }; @@ -1408,7 +1408,7 @@ test "xtversion without callback reports default" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } @@ -1440,7 +1440,7 @@ test "set title_changed callback" { var title_count: usize = 0; var last_userdata: ?*anyopaque = null; - fn titleChanged(_: Terminal, ud: ?*anyopaque) callconv(.c) void { + fn titleChanged(_: Terminal, ud: ?*anyopaque) callconv(lib.calling_conv) void { title_count += 1; last_userdata = ud; } @@ -1500,12 +1500,12 @@ test "set size callback" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } - fn sizeCb(_: Terminal, _: ?*anyopaque, out_size: *size_report.Size) callconv(.c) bool { + fn sizeCb(_: Terminal, _: ?*anyopaque, out_size: *size_report.Size) callconv(lib.calling_conv) bool { out_size.* = .{ .rows = 24, .columns = 80, @@ -1564,12 +1564,12 @@ test "set device_attributes callback primary" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } - fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(.c) bool { + fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(lib.calling_conv) bool { out.* = .{ .primary = .{ .conformance_level = 64, @@ -1618,12 +1618,12 @@ test "set device_attributes callback secondary" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } - fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(.c) bool { + fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(lib.calling_conv) bool { out.* = .{ .primary = .{ .conformance_level = 62, @@ -1672,12 +1672,12 @@ test "set device_attributes callback tertiary" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } - fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(.c) bool { + fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(lib.calling_conv) bool { out.* = .{ .primary = .{ .conformance_level = 62, @@ -1726,7 +1726,7 @@ test "device_attributes without callback uses default" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } @@ -1762,12 +1762,12 @@ test "device_attributes callback returns false uses default" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } - fn da(_: Terminal, _: ?*anyopaque, _: *Effects.CDeviceAttributes) callconv(.c) bool { + fn da(_: Terminal, _: ?*anyopaque, _: *Effects.CDeviceAttributes) callconv(lib.calling_conv) bool { return false; } }; @@ -1955,7 +1955,7 @@ test "resize sends in-band size report" { last_data = null; } - fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void { if (last_data) |d| testing.allocator.free(d); last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM"); } @@ -1990,7 +1990,7 @@ test "resize no size report without mode 2048" { const S = struct { var called: bool = false; - fn writePty(_: Terminal, _: ?*anyopaque, _: [*]const u8, _: usize) callconv(.c) void { + fn writePty(_: Terminal, _: ?*anyopaque, _: [*]const u8, _: usize) callconv(lib.calling_conv) void { called = true; } }; diff --git a/src/terminal/main.zig b/src/terminal/main.zig index 9f5b65e34..3253a95ed 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -73,8 +73,7 @@ pub const Attribute = sgr.Attribute; pub const Options = @import("build_options.zig").Options; pub const options = @import("terminal_options"); -/// This is set to true when we're building the C library. -pub const c_api = if (options.c_abi) @import("c/main.zig") else void; +pub const c_api = @import("c/main.zig"); test { @import("std").testing.refAllDecls(@This()); From 3c9c3a4f54f3c01e3b28fe63d5797bb3334c8e18 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Mar 2026 07:29:23 -0700 Subject: [PATCH 3/4] terminal/c: use lib.alloc instead of direct lib/allocator.zig import Each C API file independently imported ../../lib/allocator.zig as lib_alloc. Now that terminal/lib.zig re-exports the allocator module as lib.alloc, use that instead. This removes the redundant import and keeps all lib dependencies flowing through the single lib.zig entry point. --- src/terminal/c/allocator.zig | 23 ++++--- src/terminal/c/formatter.zig | 37 +++++------ src/terminal/c/key_encode.zig | 25 ++++--- src/terminal/c/key_event.zig | 13 ++-- src/terminal/c/main.zig | 4 +- src/terminal/c/mouse_encode.zig | 29 ++++---- src/terminal/c/mouse_event.zig | 9 ++- src/terminal/c/osc.zig | 9 ++- src/terminal/c/render.zig | 113 ++++++++++++++++---------------- src/terminal/c/sgr.zig | 9 ++- src/terminal/c/terminal.zig | 109 +++++++++++++++--------------- src/terminal/lib.zig | 1 + 12 files changed, 186 insertions(+), 195 deletions(-) diff --git a/src/terminal/c/allocator.zig b/src/terminal/c/allocator.zig index 5dc65aab1..ca698f3c8 100644 --- a/src/terminal/c/allocator.zig +++ b/src/terminal/c/allocator.zig @@ -1,8 +1,7 @@ const std = @import("std"); const testing = std.testing; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; /// Allocate a buffer of `len` bytes using the given allocator /// (or the default allocator if NULL). @@ -13,7 +12,7 @@ pub fn alloc( alloc_: ?*const CAllocator, len: usize, ) callconv(lib.calling_conv) ?[*]u8 { - const allocator = lib_alloc.default(alloc_); + const allocator = lib.alloc.default(alloc_); const buf = allocator.alloc(u8, len) catch return null; return buf.ptr; } @@ -29,14 +28,14 @@ pub fn free( len: usize, ) callconv(lib.calling_conv) void { const mem = ptr orelse return; - const allocator = lib_alloc.default(alloc_); + const allocator = lib.alloc.default(alloc_); allocator.free(mem[0..len]); } test "alloc returns non-null" { - const ptr = alloc(&lib_alloc.test_allocator, 16); + const ptr = alloc(&lib.alloc.test_allocator, 16); try testing.expect(ptr != null); - free(&lib_alloc.test_allocator, ptr, 16); + free(&lib.alloc.test_allocator, ptr, 16); } test "alloc with null allocator" { @@ -46,23 +45,23 @@ test "alloc with null allocator" { } test "alloc zero length" { - const ptr = alloc(&lib_alloc.test_allocator, 0); - defer free(&lib_alloc.test_allocator, ptr, 0); + const ptr = alloc(&lib.alloc.test_allocator, 0); + defer free(&lib.alloc.test_allocator, ptr, 0); } test "free null pointer" { - free(&lib_alloc.test_allocator, null, 0); + free(&lib.alloc.test_allocator, null, 0); } test "free allocated memory" { - const allocator = lib_alloc.default(&lib_alloc.test_allocator); + const allocator = lib.alloc.default(&lib.alloc.test_allocator); const mem = try allocator.alloc(u8, 16); - free(&lib_alloc.test_allocator, mem.ptr, mem.len); + free(&lib.alloc.test_allocator, mem.ptr, mem.len); } test "free with null allocator" { // null allocator falls back to the default (test allocator in tests) - const allocator = lib_alloc.default(null); + const allocator = lib.alloc.default(null); const mem = try allocator.alloc(u8, 8); free(null, mem.ptr, mem.len); } diff --git a/src/terminal/c/formatter.zig b/src/terminal/c/formatter.zig index dbaa0acc8..11717bc22 100644 --- a/src/terminal/c/formatter.zig +++ b/src/terminal/c/formatter.zig @@ -1,8 +1,7 @@ const std = @import("std"); const testing = std.testing; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const terminal_c = @import("terminal.zig"); const ZigTerminal = @import("../Terminal.zig"); const formatterpkg = @import("../formatter.zig"); @@ -127,7 +126,7 @@ fn terminal_new_( }!*FormatterWrapper { const t: *ZigTerminal = (terminal_ orelse return error.InvalidValue).terminal; - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(FormatterWrapper) catch return error.OutOfMemory; errdefer alloc.destroy(ptr); @@ -184,7 +183,7 @@ pub fn format_alloc( out_len: *usize, ) callconv(lib.calling_conv) Result { const wrapper = formatter_ orelse return .invalid_value; - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); var aw: std.Io.Writer.Allocating = .init(alloc); defer aw.deinit(); @@ -208,7 +207,7 @@ pub fn free(formatter_: Formatter) callconv(lib.calling_conv) void { test "terminal_new/free" { var t: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 10_000 }, )); @@ -216,7 +215,7 @@ test "terminal_new/free" { var f: Formatter = null; try testing.expectEqual(Result.success, terminal_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &f, t, .{ .emit = .plain, .unwrap = false, .trim = true, .extra = .{ .palette = false, .modes = false, .scrolling_region = false, .tabstops = false, .pwd = false, .keyboard = false, .screen = .{ .cursor = false, .style = false, .hyperlink = false, .protection = false, .kitty_keyboard = false, .charsets = false } } }, @@ -228,7 +227,7 @@ test "terminal_new/free" { test "terminal_new invalid_value on null terminal" { var f: Formatter = null; try testing.expectEqual(Result.invalid_value, terminal_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &f, null, .{ .emit = .plain, .unwrap = false, .trim = true, .extra = .{ .palette = false, .modes = false, .scrolling_region = false, .tabstops = false, .pwd = false, .keyboard = false, .screen = .{ .cursor = false, .style = false, .hyperlink = false, .protection = false, .kitty_keyboard = false, .charsets = false } } }, @@ -243,7 +242,7 @@ test "free null" { test "format plain" { var t: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 10_000 }, )); @@ -253,7 +252,7 @@ test "format plain" { var f: Formatter = null; try testing.expectEqual(Result.success, terminal_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &f, t, .{ .emit = .plain, .unwrap = false, .trim = true, .extra = .{ .palette = false, .modes = false, .scrolling_region = false, .tabstops = false, .pwd = false, .keyboard = false, .screen = .{ .cursor = false, .style = false, .hyperlink = false, .protection = false, .kitty_keyboard = false, .charsets = false } } }, @@ -269,7 +268,7 @@ test "format plain" { test "format reflects terminal changes" { var t: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 10_000 }, )); @@ -279,7 +278,7 @@ test "format reflects terminal changes" { var f: Formatter = null; try testing.expectEqual(Result.success, terminal_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &f, t, .{ .emit = .plain, .unwrap = false, .trim = true, .extra = .{ .palette = false, .modes = false, .scrolling_region = false, .tabstops = false, .pwd = false, .keyboard = false, .screen = .{ .cursor = false, .style = false, .hyperlink = false, .protection = false, .kitty_keyboard = false, .charsets = false } } }, @@ -301,7 +300,7 @@ test "format reflects terminal changes" { test "format null returns required size" { var t: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 10_000 }, )); @@ -311,7 +310,7 @@ test "format null returns required size" { var f: Formatter = null; try testing.expectEqual(Result.success, terminal_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &f, t, .{ .emit = .plain, .unwrap = false, .trim = true, .extra = .{ .palette = false, .modes = false, .scrolling_region = false, .tabstops = false, .pwd = false, .keyboard = false, .screen = .{ .cursor = false, .style = false, .hyperlink = false, .protection = false, .kitty_keyboard = false, .charsets = false } } }, @@ -333,7 +332,7 @@ test "format null returns required size" { test "format buffer too small" { var t: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 10_000 }, )); @@ -343,7 +342,7 @@ test "format buffer too small" { var f: Formatter = null; try testing.expectEqual(Result.success, terminal_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &f, t, .{ .emit = .plain, .unwrap = false, .trim = true, .extra = .{ .palette = false, .modes = false, .scrolling_region = false, .tabstops = false, .pwd = false, .keyboard = false, .screen = .{ .cursor = false, .style = false, .hyperlink = false, .protection = false, .kitty_keyboard = false, .charsets = false } } }, @@ -366,7 +365,7 @@ test "format null formatter" { test "format vt" { var t: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 10_000 }, )); @@ -376,7 +375,7 @@ test "format vt" { var f: Formatter = null; try testing.expectEqual(Result.success, terminal_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &f, t, .{ .emit = .vt, .unwrap = false, .trim = true, .extra = .{ .palette = true, .modes = false, .scrolling_region = false, .tabstops = false, .pwd = false, .keyboard = false, .screen = .{ .cursor = false, .style = true, .hyperlink = true, .protection = false, .kitty_keyboard = false, .charsets = false } } }, @@ -393,7 +392,7 @@ test "format vt" { test "format html" { var t: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 10_000 }, )); @@ -403,7 +402,7 @@ test "format html" { var f: Formatter = null; try testing.expectEqual(Result.success, terminal_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &f, t, .{ .emit = .html, .unwrap = false, .trim = true, .extra = .{ .palette = false, .modes = false, .scrolling_region = false, .tabstops = false, .pwd = false, .keyboard = false, .screen = .{ .cursor = false, .style = false, .hyperlink = false, .protection = false, .kitty_keyboard = false, .charsets = false } } }, diff --git a/src/terminal/c/key_encode.zig b/src/terminal/c/key_encode.zig index 2dbf71821..15fa74dd8 100644 --- a/src/terminal/c/key_encode.zig +++ b/src/terminal/c/key_encode.zig @@ -1,8 +1,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const key_encode = @import("../../input/key_encode.zig"); const key_event = @import("key_event.zig"); const KittyFlags = @import("../../terminal/kitty/key.zig").Flags; @@ -27,7 +26,7 @@ pub fn new( alloc_: ?*const CAllocator, result: *Encoder, ) callconv(lib.calling_conv) Result { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(KeyEncoderWrapper) catch return .out_of_memory; ptr.* = .{ @@ -166,7 +165,7 @@ test "alloc" { const testing = std.testing; var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); free(e); @@ -176,7 +175,7 @@ test "setopt bool" { const testing = std.testing; var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -198,7 +197,7 @@ test "setopt kitty flags" { const testing = std.testing; var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -219,7 +218,7 @@ test "setopt macos option as alt" { const testing = std.testing; var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -241,7 +240,7 @@ test "setopt_from_terminal" { // Create encoder var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -249,7 +248,7 @@ test "setopt_from_terminal" { // Create terminal var t: Terminal = undefined; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 0 }, )); @@ -275,7 +274,7 @@ test "setopt_from_terminal null" { const terminal_c = @import("terminal.zig"); var t: Terminal = undefined; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 0 }, )); @@ -285,7 +284,7 @@ test "setopt_from_terminal null" { // Valid encoder with null terminal var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -298,7 +297,7 @@ test "encode: kitty ctrl release with ctrl mod set" { // Create encoder var encoder: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &encoder, )); defer free(encoder); @@ -319,7 +318,7 @@ test "encode: kitty ctrl release with ctrl mod set" { // Create key event var event: key_event.Event = undefined; try testing.expectEqual(Result.success, key_event.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &event, )); defer key_event.free(event); diff --git a/src/terminal/c/key_event.zig b/src/terminal/c/key_event.zig index d3fe298d4..1feac9ac5 100644 --- a/src/terminal/c/key_event.zig +++ b/src/terminal/c/key_event.zig @@ -1,8 +1,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const key = @import("../../input/key.zig"); const Result = @import("result.zig").Result; @@ -23,7 +22,7 @@ pub fn new( alloc_: ?*const CAllocator, result: *Event, ) callconv(lib.calling_conv) Result { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(KeyEventWrapper) catch return .out_of_memory; ptr.* = .{ .alloc = alloc }; @@ -126,7 +125,7 @@ test "alloc" { const testing = std.testing; var e: Event = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); free(e); @@ -136,7 +135,7 @@ test "set" { const testing = std.testing; var e: Event = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -183,7 +182,7 @@ test "get" { const testing = std.testing; var e: Event = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -232,7 +231,7 @@ test "complete key event" { const testing = std.testing; var e: Event = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); diff --git a/src/terminal/c/main.zig b/src/terminal/c/main.zig index d854ac60e..788790c69 100644 --- a/src/terminal/c/main.zig +++ b/src/terminal/c/main.zig @@ -1,5 +1,5 @@ -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const lib = @import("../lib.zig"); +const CAllocator = lib.alloc.Allocator; const buildpkg = @import("build_info.zig"); pub const allocator = @import("allocator.zig"); diff --git a/src/terminal/c/mouse_encode.zig b/src/terminal/c/mouse_encode.zig index 6f9eb79da..331dd6060 100644 --- a/src/terminal/c/mouse_encode.zig +++ b/src/terminal/c/mouse_encode.zig @@ -2,8 +2,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const testing = std.testing; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const input_mouse_encode = @import("../../input/mouse_encode.zig"); const renderer_size = @import("../../renderer/size.zig"); const point = @import("../point.zig"); @@ -91,7 +90,7 @@ pub fn new( alloc_: ?*const CAllocator, result: *Encoder, ) callconv(lib.calling_conv) Result { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(MouseEncoderWrapper) catch return .out_of_memory; ptr.* = .{ @@ -275,7 +274,7 @@ fn testSize() Size { test "alloc" { var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); free(e); @@ -284,7 +283,7 @@ test "alloc" { test "setopt" { var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -316,14 +315,14 @@ test "setopt_from_terminal" { var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); var t: Terminal = undefined; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 0 }, )); @@ -345,7 +344,7 @@ test "setopt_from_terminal null" { const terminal_c = @import("terminal.zig"); var t: Terminal = undefined; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, .rows = 24, .max_scrollback = 0 }, )); @@ -354,7 +353,7 @@ test "setopt_from_terminal null" { var e: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); @@ -364,7 +363,7 @@ test "setopt_from_terminal null" { test "encode: sgr press left" { var encoder: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &encoder, )); defer free(encoder); @@ -378,7 +377,7 @@ test "encode: sgr press left" { var event: Event = undefined; try testing.expectEqual(Result.success, mouse_event.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &event, )); defer mouse_event.free(event); @@ -413,7 +412,7 @@ test "encode: sgr press left" { test "encode: motion dedupe and reset" { var encoder: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &encoder, )); defer free(encoder); @@ -429,7 +428,7 @@ test "encode: motion dedupe and reset" { var event: Event = undefined; try testing.expectEqual(Result.success, mouse_event.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &event, )); defer mouse_event.free(event); @@ -483,7 +482,7 @@ test "encode: motion dedupe and reset" { test "encode: querying required size doesn't update dedupe state" { var encoder: Encoder = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &encoder, )); defer free(encoder); @@ -499,7 +498,7 @@ test "encode: querying required size doesn't update dedupe state" { var event: Event = undefined; try testing.expectEqual(Result.success, mouse_event.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &event, )); defer mouse_event.free(event); diff --git a/src/terminal/c/mouse_event.zig b/src/terminal/c/mouse_event.zig index 0f634d4da..b3c19dd39 100644 --- a/src/terminal/c/mouse_event.zig +++ b/src/terminal/c/mouse_event.zig @@ -2,8 +2,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const testing = std.testing; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const key = @import("../../input/key.zig"); const mouse = @import("../../input/mouse.zig"); const mouse_encode = @import("../../input/mouse_encode.zig"); @@ -36,7 +35,7 @@ pub fn new( alloc_: ?*const CAllocator, result: *Event, ) callconv(lib.calling_conv) Result { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(MouseEventWrapper) catch return .out_of_memory; ptr.* = .{ .alloc = alloc }; @@ -108,7 +107,7 @@ pub fn get_position(event_: Event) callconv(lib.calling_conv) Position { test "alloc" { var e: Event = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); free(e); @@ -121,7 +120,7 @@ test "free null" { test "set/get" { var e: Event = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &e, )); defer free(e); diff --git a/src/terminal/c/osc.zig b/src/terminal/c/osc.zig index 8d0c065f9..7ba323001 100644 --- a/src/terminal/c/osc.zig +++ b/src/terminal/c/osc.zig @@ -1,7 +1,6 @@ const std = @import("std"); const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const osc = @import("../osc.zig"); const Result = @import("result.zig").Result; @@ -17,7 +16,7 @@ pub fn new( alloc_: ?*const CAllocator, result: *Parser, ) callconv(lib.calling_conv) Result { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(osc.Parser) catch return .out_of_memory; ptr.* = .init(alloc); @@ -107,7 +106,7 @@ test "alloc" { const testing = std.testing; var p: Parser = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &p, )); free(p); @@ -122,7 +121,7 @@ test "change window title" { const testing = std.testing; var p: Parser = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &p, )); defer free(p); diff --git a/src/terminal/c/render.zig b/src/terminal/c/render.zig index 6d9ac8d15..08a5c00f3 100644 --- a/src/terminal/c/render.zig +++ b/src/terminal/c/render.zig @@ -2,8 +2,7 @@ const std = @import("std"); const testing = std.testing; const Allocator = std.mem.Allocator; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const colorpkg = @import("../color.zig"); const cursorpkg = @import("../cursor.zig"); const page = @import("../page.zig"); @@ -155,7 +154,7 @@ pub fn new( } fn new_(alloc_: ?*const CAllocator) error{OutOfMemory}!*RenderStateWrapper { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(RenderStateWrapper) catch return error.OutOfMemory; ptr.* = .{ .alloc = alloc }; @@ -355,7 +354,7 @@ pub fn row_iterator_new( alloc_: ?*const CAllocator, result: *RowIterator, ) callconv(lib.calling_conv) Result { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(RowIteratorWrapper) catch { result.* = null; return .out_of_memory; @@ -390,7 +389,7 @@ pub fn row_cells_new( alloc_: ?*const CAllocator, result: *RowCells, ) callconv(lib.calling_conv) Result { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(RowCellsWrapper) catch { result.* = null; return .out_of_memory; @@ -639,7 +638,7 @@ fn rowSetTyped( test "render: new/free" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); try testing.expect(state != null); @@ -653,7 +652,7 @@ test "render: free null" { test "render: update invalid value" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -670,7 +669,7 @@ test "render: get invalid value" { test "render: get invalid data" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -681,7 +680,7 @@ test "render: get invalid data" { test "render: colors get invalid value" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -706,7 +705,7 @@ test "render: get/set dirty invalid value" { test "render: get/set dirty" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -729,7 +728,7 @@ test "render: get/set dirty" { test "render: set null value" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -740,7 +739,7 @@ test "render: set null value" { test "render: row iterator get invalid value" { var iterator: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &iterator, )); defer row_iterator_free(iterator); @@ -751,7 +750,7 @@ test "render: row iterator get invalid value" { test "render: row iterator new/free" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -763,7 +762,7 @@ test "render: row iterator new/free" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -772,7 +771,7 @@ test "render: row iterator new/free" { var iterator: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &iterator, )); defer row_iterator_free(iterator); @@ -806,7 +805,7 @@ test "render: row get null" { test "render: row get invalid data" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -818,7 +817,7 @@ test "render: row get invalid data" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -827,7 +826,7 @@ test "render: row get invalid data" { var iterator: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &iterator, )); defer row_iterator_free(iterator); @@ -845,7 +844,7 @@ test "render: row set null" { test "render: row set before iteration" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -857,7 +856,7 @@ test "render: row set before iteration" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -866,7 +865,7 @@ test "render: row set before iteration" { var iterator: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &iterator, )); defer row_iterator_free(iterator); @@ -879,7 +878,7 @@ test "render: row set before iteration" { test "render: row get before iteration" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -891,7 +890,7 @@ test "render: row get before iteration" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -900,7 +899,7 @@ test "render: row get before iteration" { var iterator: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &iterator, )); defer row_iterator_free(iterator); @@ -913,7 +912,7 @@ test "render: row get before iteration" { test "render: row get/set dirty" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -925,7 +924,7 @@ test "render: row get/set dirty" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -939,7 +938,7 @@ test "render: row get/set dirty" { // Create an iterator and verify it is dirty. var it: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &it, )); defer row_iterator_free(it); @@ -957,7 +956,7 @@ test "render: row get/set dirty" { // It should not be dirty anymore. var it2: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &it2, )); defer row_iterator_free(it2); @@ -971,7 +970,7 @@ test "render: row get/set dirty" { test "render: row iterator next" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -983,7 +982,7 @@ test "render: row iterator next" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -992,7 +991,7 @@ test "render: row iterator next" { var iterator: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &iterator, )); defer row_iterator_free(iterator); @@ -1021,7 +1020,7 @@ test "render: row iterator next" { test "render: update" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -1033,7 +1032,7 @@ test "render: update" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -1054,7 +1053,7 @@ test "render: update" { test "render: colors get" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -1066,7 +1065,7 @@ test "render: colors get" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -1096,7 +1095,7 @@ test "render: colors get" { test "render: row cells bg_color no background" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -1111,7 +1110,7 @@ test "render: row cells bg_color no background" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -1120,7 +1119,7 @@ test "render: row cells bg_color no background" { var it: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &it, )); defer row_iterator_free(it); @@ -1130,7 +1129,7 @@ test "render: row cells bg_color no background" { var cells: RowCells = null; try testing.expectEqual(Result.success, row_cells_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &cells, )); defer row_cells_free(cells); @@ -1146,7 +1145,7 @@ test "render: row cells bg_color no background" { test "render: row cells bg_color from style" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -1161,7 +1160,7 @@ test "render: row cells bg_color from style" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -1170,7 +1169,7 @@ test "render: row cells bg_color from style" { var it: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &it, )); defer row_iterator_free(it); @@ -1180,7 +1179,7 @@ test "render: row cells bg_color from style" { var cells: RowCells = null; try testing.expectEqual(Result.success, row_cells_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &cells, )); defer row_cells_free(cells); @@ -1198,7 +1197,7 @@ test "render: row cells bg_color from style" { test "render: row cells bg_color from content tag" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -1215,7 +1214,7 @@ test "render: row cells bg_color from content tag" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -1224,7 +1223,7 @@ test "render: row cells bg_color from content tag" { var it: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &it, )); defer row_iterator_free(it); @@ -1234,7 +1233,7 @@ test "render: row cells bg_color from content tag" { var cells: RowCells = null; try testing.expectEqual(Result.success, row_cells_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &cells, )); defer row_cells_free(cells); @@ -1252,7 +1251,7 @@ test "render: row cells bg_color from content tag" { test "render: row cells fg_color no foreground" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -1267,7 +1266,7 @@ test "render: row cells fg_color no foreground" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -1276,7 +1275,7 @@ test "render: row cells fg_color no foreground" { var it: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &it, )); defer row_iterator_free(it); @@ -1286,7 +1285,7 @@ test "render: row cells fg_color no foreground" { var cells: RowCells = null; try testing.expectEqual(Result.success, row_cells_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &cells, )); defer row_cells_free(cells); @@ -1302,7 +1301,7 @@ test "render: row cells fg_color no foreground" { test "render: row cells fg_color from style" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -1317,7 +1316,7 @@ test "render: row cells fg_color from style" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); @@ -1326,7 +1325,7 @@ test "render: row cells fg_color from style" { var it: RowIterator = null; try testing.expectEqual(Result.success, row_iterator_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &it, )); defer row_iterator_free(it); @@ -1336,7 +1335,7 @@ test "render: row cells fg_color from style" { var cells: RowCells = null; try testing.expectEqual(Result.success, row_cells_new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &cells, )); defer row_cells_free(cells); @@ -1354,7 +1353,7 @@ test "render: row cells fg_color from style" { test "render: colors get supports truncated sized struct" { var terminal: terminal_c.Terminal = null; try testing.expectEqual(Result.success, terminal_c.new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &terminal, .{ .cols = 80, @@ -1366,7 +1365,7 @@ test "render: colors get supports truncated sized struct" { var state: RenderState = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &state, )); defer free(state); diff --git a/src/terminal/c/sgr.zig b/src/terminal/c/sgr.zig index 7bd47b9ae..b0ef23d05 100644 --- a/src/terminal/c/sgr.zig +++ b/src/terminal/c/sgr.zig @@ -2,8 +2,7 @@ const std = @import("std"); const testing = std.testing; const Allocator = std.mem.Allocator; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const sgr = @import("../sgr.zig"); const Result = @import("result.zig").Result; @@ -22,7 +21,7 @@ pub fn new( alloc_: ?*const CAllocator, result: *Parser, ) callconv(lib.calling_conv) Result { - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const ptr = alloc.create(ParserWrapper) catch return .out_of_memory; ptr.* = .{ @@ -141,7 +140,7 @@ pub fn wasm_free_attribute(attr: *sgr.Attribute.C) callconv(lib.calling_conv) vo test "alloc" { var p: Parser = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &p, )); free(p); @@ -150,7 +149,7 @@ test "alloc" { test "simple params, no seps" { var p: Parser = undefined; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &p, )); defer free(p); diff --git a/src/terminal/c/terminal.zig b/src/terminal/c/terminal.zig index 9eb3282b1..62d3f61c4 100644 --- a/src/terminal/c/terminal.zig +++ b/src/terminal/c/terminal.zig @@ -1,8 +1,7 @@ const std = @import("std"); const testing = std.testing; const lib = @import("../lib.zig"); -const lib_alloc = @import("../../lib/allocator.zig"); -const CAllocator = lib_alloc.Allocator; +const CAllocator = lib.alloc.Allocator; const ZigTerminal = @import("../Terminal.zig"); const Stream = @import("../stream_terminal.zig").Stream; const ScreenSet = @import("../ScreenSet.zig"); @@ -239,7 +238,7 @@ fn new_( ) NewError!*TerminalWrapper { if (opts.cols == 0 or opts.rows == 0) return error.InvalidValue; - const alloc = lib_alloc.default(alloc_); + const alloc = lib.alloc.default(alloc_); const t = alloc.create(ZigTerminal) catch return error.OutOfMemory; errdefer alloc.destroy(t); @@ -589,7 +588,7 @@ pub fn free(terminal_: Terminal) callconv(lib.calling_conv) void { test "new/free" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -606,7 +605,7 @@ test "new invalid value" { var t: Terminal = null; try testing.expectEqual(Result.invalid_value, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 0, @@ -617,7 +616,7 @@ test "new invalid value" { try testing.expect(t == null); try testing.expectEqual(Result.invalid_value, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -635,7 +634,7 @@ test "free null" { test "scroll_viewport" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 5, @@ -691,7 +690,7 @@ test "scroll_viewport null" { test "reset" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -716,7 +715,7 @@ test "reset null" { test "resize" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -738,7 +737,7 @@ test "resize null" { test "resize invalid value" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -755,7 +754,7 @@ test "resize invalid value" { test "mode_get and mode_set" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -801,7 +800,7 @@ test "mode_set null" { test "mode_get unknown mode" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -819,7 +818,7 @@ test "mode_get unknown mode" { test "mode_set unknown mode" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -836,7 +835,7 @@ test "mode_set unknown mode" { test "vt_write" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -856,7 +855,7 @@ test "vt_write" { test "vt_write split escape sequence" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -881,7 +880,7 @@ test "vt_write split escape sequence" { test "get cols and rows" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -902,7 +901,7 @@ test "get cols and rows" { test "get cursor position" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -930,7 +929,7 @@ test "get null" { test "get cursor_visible" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -954,7 +953,7 @@ test "get cursor_visible" { test "get active_screen" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -972,7 +971,7 @@ test "get active_screen" { test "get kitty_keyboard_flags" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -996,7 +995,7 @@ test "get kitty_keyboard_flags" { test "get mouse_tracking" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1046,7 +1045,7 @@ test "get mouse_tracking" { test "get total_rows" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1064,7 +1063,7 @@ test "get total_rows" { test "get scrollback_rows" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1088,7 +1087,7 @@ test "get scrollback_rows" { test "get invalid" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1104,7 +1103,7 @@ test "get invalid" { test "grid_ref" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1142,7 +1141,7 @@ test "grid_ref null terminal" { test "set write_pty callback" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1185,7 +1184,7 @@ test "set write_pty callback" { test "set write_pty without callback ignores queries" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1202,7 +1201,7 @@ test "set write_pty without callback ignores queries" { test "set write_pty null clears callback" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1231,7 +1230,7 @@ test "set write_pty null clears callback" { test "set bell callback" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1271,7 +1270,7 @@ test "set bell callback" { test "bell without callback is silent" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1288,7 +1287,7 @@ test "bell without callback is silent" { test "set enquiry callback" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1330,7 +1329,7 @@ test "set enquiry callback" { test "enquiry without callback is silent" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1347,7 +1346,7 @@ test "enquiry without callback is silent" { test "set xtversion callback" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1390,7 +1389,7 @@ test "set xtversion callback" { test "xtversion without callback reports default" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1426,7 +1425,7 @@ test "xtversion without callback reports default" { test "set title_changed callback" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1465,7 +1464,7 @@ test "set title_changed callback" { test "title_changed without callback is silent" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1482,7 +1481,7 @@ test "title_changed without callback is silent" { test "set size callback" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1529,7 +1528,7 @@ test "set size callback" { test "size without callback is silent" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1546,7 +1545,7 @@ test "size without callback is silent" { test "set device_attributes callback primary" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1600,7 +1599,7 @@ test "set device_attributes callback primary" { test "set device_attributes callback secondary" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1654,7 +1653,7 @@ test "set device_attributes callback secondary" { test "set device_attributes callback tertiary" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1708,7 +1707,7 @@ test "set device_attributes callback tertiary" { test "device_attributes without callback uses default" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1744,7 +1743,7 @@ test "device_attributes without callback uses default" { test "device_attributes callback returns false uses default" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1785,7 +1784,7 @@ test "device_attributes callback returns false uses default" { test "set and get title" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1824,7 +1823,7 @@ test "set and get title" { test "set and get pwd" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1856,7 +1855,7 @@ test "set and get pwd" { test "get title set via vt_write" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1877,7 +1876,7 @@ test "get title set via vt_write" { test "resize updates pixel dimensions" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1897,7 +1896,7 @@ test "resize updates pixel dimensions" { test "resize pixel overflow saturates" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1917,7 +1916,7 @@ test "resize pixel overflow saturates" { test "resize disables synchronized output" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1937,7 +1936,7 @@ test "resize disables synchronized output" { test "resize sends in-band size report" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -1978,7 +1977,7 @@ test "resize sends in-band size report" { test "resize no size report without mode 2048" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -2006,7 +2005,7 @@ test "resize no size report without mode 2048" { test "resize in-band report without write_pty callback" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -2028,7 +2027,7 @@ test "resize null terminal" { test "resize zero cols" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -2044,7 +2043,7 @@ test "resize zero cols" { test "resize zero rows" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, @@ -2060,7 +2059,7 @@ test "resize zero rows" { test "grid_ref out of bounds" { var t: Terminal = null; try testing.expectEqual(Result.success, new( - &lib_alloc.test_allocator, + &lib.alloc.test_allocator, &t, .{ .cols = 80, diff --git a/src/terminal/lib.zig b/src/terminal/lib.zig index f68cd4356..8e8acf89d 100644 --- a/src/terminal/lib.zig +++ b/src/terminal/lib.zig @@ -15,6 +15,7 @@ else .auto; /// Forwarded decls from lib that are used. +pub const alloc = lib.allocator; pub const Enum = lib.Enum; pub const TaggedUnion = lib.TaggedUnion; pub const Struct = lib.Struct; From ac85a2f3d621758c8302a0c6956d5ca30b833e73 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Mar 2026 08:40:27 -0700 Subject: [PATCH 4/4] terminal: always use C ABI for now --- src/lib_vt.zig | 3 +++ src/terminal/lib.zig | 14 ++++++-------- src/terminal/main.zig | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib_vt.zig b/src/lib_vt.zig index a7d7171bc..0a749be87 100644 --- a/src/lib_vt.zig +++ b/src/lib_vt.zig @@ -264,4 +264,7 @@ test { _ = terminal; _ = @import("lib/main.zig"); @import("std").testing.refAllDecls(input); + if (comptime terminal.options.c_abi) { + _ = terminal.c_api; + } } diff --git a/src/terminal/lib.zig b/src/terminal/lib.zig index 8e8acf89d..3cd657b4e 100644 --- a/src/terminal/lib.zig +++ b/src/terminal/lib.zig @@ -5,14 +5,12 @@ const lib = @import("../lib/main.zig"); /// The target for the terminal lib in particular. pub const target: lib.Target = if (build_options.c_abi) .c else .zig; -/// The calling convention to use for C APIs. If we're not building for -/// C ABI then we use auto which allows our C APIs to be cleanly called -/// by Zig. This is required because we modify our struct layouts based -/// on C ABI too. -pub const calling_conv: std.builtin.CallingConvention = if (build_options.c_abi) - .c -else - .auto; +/// The calling convention to use for C APIs. +/// +/// This is always .c for now. I want to make this "Zig" when we're not +/// building the C ABI but there are bigger issues we need to resolve to +/// make that possible (change it and see for yourself). +pub const calling_conv: std.builtin.CallingConvention = .c; /// Forwarded decls from lib that are used. pub const alloc = lib.allocator; diff --git a/src/terminal/main.zig b/src/terminal/main.zig index 3253a95ed..9f5b65e34 100644 --- a/src/terminal/main.zig +++ b/src/terminal/main.zig @@ -73,7 +73,8 @@ pub const Attribute = sgr.Attribute; pub const Options = @import("build_options.zig").Options; pub const options = @import("terminal_options"); -pub const c_api = @import("c/main.zig"); +/// This is set to true when we're building the C library. +pub const c_api = if (options.c_abi) @import("c/main.zig") else void; test { @import("std").testing.refAllDecls(@This());