libghostty: refactor lib calls into centralized terminal/lib.zig to prep for Zig to call C (#11831)
This parameterizes all our calling conventions on our C API based on whether we're building the C lib or Zig lib. If we're building the C lib, it's C calling convention, else Zig. This lets the Zig module call the C API via `terminal.c_api.<func>`. Zig is perfectly capable of calling C ABI but we actually modify our struct layouts depending on calling conv so you can't actually use the API prior to this. This fixes that all up. **Why would you want to do this?** The C API has some different semantics and stricter care about things like ABI compatibility (in how it changes structs and so on). It actually might be a more API-stable API to rely on even from Zig.pull/11836/head
commit
a8e65e829a
|
|
@ -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",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const CAllocator = lib.alloc.Allocator;
|
||||
|
||||
/// Allocate a buffer of `len` bytes using the given allocator
|
||||
/// (or the default allocator if NULL).
|
||||
|
|
@ -11,8 +11,8 @@ const CAllocator = lib_alloc.Allocator;
|
|||
pub fn alloc(
|
||||
alloc_: ?*const CAllocator,
|
||||
len: usize,
|
||||
) callconv(.c) ?[*]u8 {
|
||||
const allocator = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) ?[*]u8 {
|
||||
const allocator = lib.alloc.default(alloc_);
|
||||
const buf = allocator.alloc(u8, len) catch return null;
|
||||
return buf.ptr;
|
||||
}
|
||||
|
|
@ -26,16 +26,16 @@ 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_);
|
||||
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" {
|
||||
|
|
@ -45,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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const CAllocator = lib.alloc.Allocator;
|
||||
const terminal_c = @import("terminal.zig");
|
||||
const ZigTerminal = @import("../Terminal.zig");
|
||||
const formatterpkg = @import("../formatter.zig");
|
||||
|
|
@ -100,7 +100,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_,
|
||||
|
|
@ -126,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);
|
||||
|
|
@ -151,7 +151,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,9 +181,9 @@ 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_);
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
|
||||
var aw: std.Io.Writer.Allocating = .init(alloc);
|
||||
defer aw.deinit();
|
||||
|
|
@ -198,7 +198,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);
|
||||
|
|
@ -207,7 +207,7 @@ pub fn free(formatter_: Formatter) callconv(.c) 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 },
|
||||
));
|
||||
|
|
@ -215,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 } } },
|
||||
|
|
@ -227,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 } } },
|
||||
|
|
@ -242,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 },
|
||||
));
|
||||
|
|
@ -252,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 } } },
|
||||
|
|
@ -268,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 },
|
||||
));
|
||||
|
|
@ -278,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 } } },
|
||||
|
|
@ -300,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 },
|
||||
));
|
||||
|
|
@ -310,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 } } },
|
||||
|
|
@ -332,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 },
|
||||
));
|
||||
|
|
@ -342,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 } } },
|
||||
|
|
@ -365,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 },
|
||||
));
|
||||
|
|
@ -375,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 } } },
|
||||
|
|
@ -392,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 },
|
||||
));
|
||||
|
|
@ -402,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 } } },
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
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;
|
||||
|
|
@ -25,8 +25,8 @@ pub const Encoder = ?*KeyEncoderWrapper;
|
|||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Encoder,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
const ptr = alloc.create(KeyEncoderWrapper) catch
|
||||
return .out_of_memory;
|
||||
ptr.* = .{
|
||||
|
|
@ -37,7 +37,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 +72,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 +120,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 +132,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(
|
||||
|
|
@ -165,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);
|
||||
|
|
@ -175,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);
|
||||
|
|
@ -197,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);
|
||||
|
|
@ -218,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);
|
||||
|
|
@ -240,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);
|
||||
|
|
@ -248,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 },
|
||||
));
|
||||
|
|
@ -274,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 },
|
||||
));
|
||||
|
|
@ -284,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);
|
||||
|
|
@ -297,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);
|
||||
|
|
@ -318,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);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const CAllocator = lib.alloc.Allocator;
|
||||
const key = @import("../../input/key.zig");
|
||||
const Result = @import("result.zig").Result;
|
||||
|
||||
|
|
@ -21,8 +21,8 @@ pub const Event = ?*KeyEventWrapper;
|
|||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Event,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
const ptr = alloc.create(KeyEventWrapper) catch
|
||||
return .out_of_memory;
|
||||
ptr.* = .{ .alloc = alloc };
|
||||
|
|
@ -30,13 +30,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 +48,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 +65,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;
|
||||
}
|
||||
|
|
@ -125,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);
|
||||
|
|
@ -135,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);
|
||||
|
|
@ -182,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);
|
||||
|
|
@ -231,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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const testing = std.testing;
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
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");
|
||||
|
|
@ -89,8 +89,8 @@ pub const Option = enum(c_int) {
|
|||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Encoder,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
const ptr = alloc.create(MouseEncoderWrapper) catch
|
||||
return .out_of_memory;
|
||||
ptr.* = .{
|
||||
|
|
@ -101,7 +101,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 +111,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 +187,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 +195,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 +206,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;
|
||||
|
||||
|
|
@ -274,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);
|
||||
|
|
@ -283,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);
|
||||
|
|
@ -315,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 },
|
||||
));
|
||||
|
|
@ -344,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 },
|
||||
));
|
||||
|
|
@ -353,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);
|
||||
|
|
@ -363,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);
|
||||
|
|
@ -377,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);
|
||||
|
|
@ -412,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);
|
||||
|
|
@ -428,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);
|
||||
|
|
@ -482,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);
|
||||
|
|
@ -498,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);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const testing = std.testing;
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
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");
|
||||
|
|
@ -34,8 +34,8 @@ pub const Mods = key.Mods;
|
|||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Event,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
const ptr = alloc.create(MouseEventWrapper) catch
|
||||
return .out_of_memory;
|
||||
ptr.* = .{ .alloc = alloc };
|
||||
|
|
@ -43,13 +43,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 +60,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 +75,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,26 +88,26 @@ 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;
|
||||
}
|
||||
|
||||
test "alloc" {
|
||||
var e: Event = undefined;
|
||||
try testing.expectEqual(Result.success, new(
|
||||
&lib_alloc.test_allocator,
|
||||
&lib.alloc.test_allocator,
|
||||
&e,
|
||||
));
|
||||
free(e);
|
||||
|
|
@ -120,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);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const std = @import("std");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const CAllocator = lib.alloc.Allocator;
|
||||
const osc = @import("../osc.zig");
|
||||
const Result = @import("result.zig").Result;
|
||||
|
||||
|
|
@ -15,8 +15,8 @@ pub const Command = ?*osc.Command;
|
|||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Parser,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
const ptr = alloc.create(osc.Parser) catch
|
||||
return .out_of_memory;
|
||||
ptr.* = .init(alloc);
|
||||
|
|
@ -24,7 +24,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 +32,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 +67,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)});
|
||||
|
|
@ -106,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);
|
||||
|
|
@ -121,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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const lib = @import("../../lib/main.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const CAllocator = lib.alloc.Allocator;
|
||||
const colorpkg = @import("../color.zig");
|
||||
const cursorpkg = @import("../cursor.zig");
|
||||
const page = @import("../page.zig");
|
||||
|
|
@ -143,7 +142,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) {
|
||||
|
|
@ -155,14 +154,14 @@ 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 };
|
||||
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 +171,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 +183,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 +262,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 +295,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,8 +353,8 @@ pub fn colors_get(
|
|||
pub fn row_iterator_new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *RowIterator,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
const ptr = alloc.create(RowIteratorWrapper) catch {
|
||||
result.* = null;
|
||||
return .out_of_memory;
|
||||
|
|
@ -372,13 +371,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,8 +388,8 @@ pub fn row_iterator_next(iterator_: RowIterator) callconv(.c) bool {
|
|||
pub fn row_cells_new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *RowCells,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
const ptr = alloc.create(RowCellsWrapper) catch {
|
||||
result.* = null;
|
||||
return .out_of_memory;
|
||||
|
|
@ -407,7 +406,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 +414,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 +454,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 +554,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 +604,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)});
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const CAllocator = lib.alloc.Allocator;
|
||||
const sgr = @import("../sgr.zig");
|
||||
const Result = @import("result.zig").Result;
|
||||
|
||||
|
|
@ -20,8 +20,8 @@ pub const Parser = ?*ParserWrapper;
|
|||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Parser,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib.alloc.default(alloc_);
|
||||
const ptr = alloc.create(ParserWrapper) catch
|
||||
return .out_of_memory;
|
||||
ptr.* = .{
|
||||
|
|
@ -32,7 +32,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 +40,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 +51,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 +87,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 +101,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 +109,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);
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ pub fn wasm_free_attribute(attr: *sgr.Attribute.C) callconv(.c) void {
|
|||
test "alloc" {
|
||||
var p: Parser = undefined;
|
||||
try testing.expectEqual(Result.success, new(
|
||||
&lib_alloc.test_allocator,
|
||||
&lib.alloc.test_allocator,
|
||||
&p,
|
||||
));
|
||||
free(p);
|
||||
|
|
@ -149,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);
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const lib = @import("../../lib/main.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const CAllocator = lib.alloc.Allocator;
|
||||
const ZigTerminal = @import("../Terminal.zig");
|
||||
const Stream = @import("../stream_terminal.zig").Stream;
|
||||
const ScreenSet = @import("../ScreenSet.zig");
|
||||
|
|
@ -55,39 +54,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 +220,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) {
|
||||
|
|
@ -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);
|
||||
|
|
@ -282,7 +281,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 +321,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 +373,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 +388,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 +422,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 +431,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 +443,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 +499,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 +560,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 +574,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;
|
||||
|
||||
|
|
@ -589,7 +588,7 @@ pub fn free(terminal_: Terminal) callconv(.c) 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,
|
||||
|
|
@ -1162,7 +1161,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;
|
||||
|
|
@ -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,
|
||||
|
|
@ -1214,7 +1213,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;
|
||||
}
|
||||
};
|
||||
|
|
@ -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,
|
||||
|
|
@ -1245,7 +1244,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;
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
@ -1306,13 +1305,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 };
|
||||
}
|
||||
};
|
||||
|
|
@ -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,
|
||||
|
|
@ -1365,13 +1364,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 };
|
||||
}
|
||||
};
|
||||
|
|
@ -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,
|
||||
|
|
@ -1408,7 +1407,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");
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
@ -1440,7 +1439,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;
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
@ -1500,12 +1499,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,
|
||||
|
|
@ -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,
|
||||
|
|
@ -1564,12 +1563,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,
|
||||
|
|
@ -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,
|
||||
|
|
@ -1618,12 +1617,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,
|
||||
|
|
@ -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,
|
||||
|
|
@ -1672,12 +1671,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,
|
||||
|
|
@ -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,
|
||||
|
|
@ -1726,7 +1725,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");
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
@ -1762,12 +1761,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;
|
||||
}
|
||||
};
|
||||
|
|
@ -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,
|
||||
|
|
@ -1955,7 +1954,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");
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
@ -1990,7 +1989,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;
|
||||
}
|
||||
};
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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", // =
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
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.
|
||||
///
|
||||
/// 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;
|
||||
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;
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue