mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 03:25:50 +00:00
terminal/c: use lib.calling_conv to allow Zig calling conv
This commit is contained in:
@@ -264,7 +264,4 @@ test {
|
||||
_ = terminal;
|
||||
_ = @import("lib/main.zig");
|
||||
@import("std").testing.refAllDecls(input);
|
||||
if (comptime terminal.options.c_abi) {
|
||||
_ = terminal.c_api;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const lib = @import("../lib.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
|
||||
@@ -11,7 +12,7 @@ const CAllocator = lib_alloc.Allocator;
|
||||
pub fn alloc(
|
||||
alloc_: ?*const CAllocator,
|
||||
len: usize,
|
||||
) callconv(.c) ?[*]u8 {
|
||||
) callconv(lib.calling_conv) ?[*]u8 {
|
||||
const allocator = lib_alloc.default(alloc_);
|
||||
const buf = allocator.alloc(u8, len) catch return null;
|
||||
return buf.ptr;
|
||||
@@ -26,7 +27,7 @@ pub fn free(
|
||||
alloc_: ?*const CAllocator,
|
||||
ptr: ?[*]u8,
|
||||
len: usize,
|
||||
) callconv(.c) void {
|
||||
) callconv(lib.calling_conv) void {
|
||||
const mem = ptr orelse return;
|
||||
const allocator = lib_alloc.default(alloc_);
|
||||
allocator.free(mem[0..len]);
|
||||
|
||||
@@ -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,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const lib = @import("../lib.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const terminal_c = @import("terminal.zig");
|
||||
@@ -100,7 +101,7 @@ pub fn terminal_new(
|
||||
result: *Formatter,
|
||||
terminal_: terminal_c.Terminal,
|
||||
opts: TerminalOptions,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
result.* = terminal_new_(
|
||||
alloc_,
|
||||
terminal_,
|
||||
@@ -151,7 +152,7 @@ pub fn format_buf(
|
||||
out_: ?[*]u8,
|
||||
out_len: usize,
|
||||
out_written: *usize,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const wrapper = formatter_ orelse return .invalid_value;
|
||||
|
||||
var writer: std.Io.Writer = .fixed(if (out_) |out|
|
||||
@@ -181,7 +182,7 @@ pub fn format_alloc(
|
||||
alloc_: ?*const CAllocator,
|
||||
out_ptr: *?[*]u8,
|
||||
out_len: *usize,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const wrapper = formatter_ orelse return .invalid_value;
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
|
||||
@@ -198,7 +199,7 @@ pub fn format_alloc(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn free(formatter_: Formatter) callconv(.c) void {
|
||||
pub fn free(formatter_: Formatter) callconv(lib.calling_conv) void {
|
||||
const wrapper = formatter_ orelse return;
|
||||
const alloc = wrapper.alloc;
|
||||
alloc.destroy(wrapper);
|
||||
|
||||
@@ -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,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const key_encode = @import("../../input/key_encode.zig");
|
||||
@@ -25,7 +26,7 @@ pub const Encoder = ?*KeyEncoderWrapper;
|
||||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Encoder,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(KeyEncoderWrapper) catch
|
||||
return .out_of_memory;
|
||||
@@ -37,7 +38,7 @@ pub fn new(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn free(encoder_: Encoder) callconv(.c) void {
|
||||
pub fn free(encoder_: Encoder) callconv(lib.calling_conv) void {
|
||||
const wrapper = encoder_ orelse return;
|
||||
const alloc = wrapper.alloc;
|
||||
alloc.destroy(wrapper);
|
||||
@@ -72,7 +73,7 @@ pub fn setopt(
|
||||
encoder_: Encoder,
|
||||
option: Option,
|
||||
value: ?*const anyopaque,
|
||||
) callconv(.c) void {
|
||||
) callconv(lib.calling_conv) void {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(Option, @intFromEnum(option)) catch {
|
||||
log.warn("setopt invalid option value={d}", .{@intFromEnum(option)});
|
||||
@@ -120,7 +121,7 @@ fn setoptTyped(
|
||||
pub fn setopt_from_terminal(
|
||||
encoder_: Encoder,
|
||||
terminal_: Terminal,
|
||||
) callconv(.c) void {
|
||||
) callconv(lib.calling_conv) void {
|
||||
const wrapper = encoder_ orelse return;
|
||||
const t: *ZigTerminal = (terminal_ orelse return).terminal;
|
||||
wrapper.opts = .fromTerminal(t);
|
||||
@@ -132,7 +133,7 @@ pub fn encode(
|
||||
out_: ?[*]u8,
|
||||
out_len: usize,
|
||||
out_written: *usize,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
// Attempt to write to this buffer
|
||||
var writer: std.Io.Writer = .fixed(if (out_) |out| out[0..out_len] else &.{});
|
||||
key_encode.encode(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const key = @import("../../input/key.zig");
|
||||
@@ -21,7 +22,7 @@ pub const Event = ?*KeyEventWrapper;
|
||||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Event,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(KeyEventWrapper) catch
|
||||
return .out_of_memory;
|
||||
@@ -30,13 +31,13 @@ pub fn new(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn free(event_: Event) callconv(.c) void {
|
||||
pub fn free(event_: Event) callconv(lib.calling_conv) void {
|
||||
const wrapper = event_ orelse return;
|
||||
const alloc = wrapper.alloc;
|
||||
alloc.destroy(wrapper);
|
||||
}
|
||||
|
||||
pub fn set_action(event_: Event, action: key.Action) callconv(.c) void {
|
||||
pub fn set_action(event_: Event, action: key.Action) callconv(lib.calling_conv) void {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(key.Action, @intFromEnum(action)) catch {
|
||||
log.warn("set_action invalid action value={d}", .{@intFromEnum(action)});
|
||||
@@ -48,12 +49,12 @@ pub fn set_action(event_: Event, action: key.Action) callconv(.c) void {
|
||||
event.action = action;
|
||||
}
|
||||
|
||||
pub fn get_action(event_: Event) callconv(.c) key.Action {
|
||||
pub fn get_action(event_: Event) callconv(lib.calling_conv) key.Action {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
return event.action;
|
||||
}
|
||||
|
||||
pub fn set_key(event_: Event, k: key.Key) callconv(.c) void {
|
||||
pub fn set_key(event_: Event, k: key.Key) callconv(lib.calling_conv) void {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(key.Key, @intFromEnum(k)) catch {
|
||||
log.warn("set_key invalid key value={d}", .{@intFromEnum(k)});
|
||||
@@ -65,58 +66,58 @@ pub fn set_key(event_: Event, k: key.Key) callconv(.c) void {
|
||||
event.key = k;
|
||||
}
|
||||
|
||||
pub fn get_key(event_: Event) callconv(.c) key.Key {
|
||||
pub fn get_key(event_: Event) callconv(lib.calling_conv) key.Key {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
return event.key;
|
||||
}
|
||||
|
||||
pub fn set_mods(event_: Event, mods: key.Mods) callconv(.c) void {
|
||||
pub fn set_mods(event_: Event, mods: key.Mods) callconv(lib.calling_conv) void {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
event.mods = mods;
|
||||
}
|
||||
|
||||
pub fn get_mods(event_: Event) callconv(.c) key.Mods {
|
||||
pub fn get_mods(event_: Event) callconv(lib.calling_conv) key.Mods {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
return event.mods;
|
||||
}
|
||||
|
||||
pub fn set_consumed_mods(event_: Event, consumed_mods: key.Mods) callconv(.c) void {
|
||||
pub fn set_consumed_mods(event_: Event, consumed_mods: key.Mods) callconv(lib.calling_conv) void {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
event.consumed_mods = consumed_mods;
|
||||
}
|
||||
|
||||
pub fn get_consumed_mods(event_: Event) callconv(.c) key.Mods {
|
||||
pub fn get_consumed_mods(event_: Event) callconv(lib.calling_conv) key.Mods {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
return event.consumed_mods;
|
||||
}
|
||||
|
||||
pub fn set_composing(event_: Event, composing: bool) callconv(.c) void {
|
||||
pub fn set_composing(event_: Event, composing: bool) callconv(lib.calling_conv) void {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
event.composing = composing;
|
||||
}
|
||||
|
||||
pub fn get_composing(event_: Event) callconv(.c) bool {
|
||||
pub fn get_composing(event_: Event) callconv(lib.calling_conv) bool {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
return event.composing;
|
||||
}
|
||||
|
||||
pub fn set_utf8(event_: Event, utf8: ?[*]const u8, len: usize) callconv(.c) void {
|
||||
pub fn set_utf8(event_: Event, utf8: ?[*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
event.utf8 = if (utf8) |ptr| ptr[0..len] else "";
|
||||
}
|
||||
|
||||
pub fn get_utf8(event_: Event, len: ?*usize) callconv(.c) ?[*]const u8 {
|
||||
pub fn get_utf8(event_: Event, len: ?*usize) callconv(lib.calling_conv) ?[*]const u8 {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
if (len) |l| l.* = event.utf8.len;
|
||||
return if (event.utf8.len == 0) null else event.utf8.ptr;
|
||||
}
|
||||
|
||||
pub fn set_unshifted_codepoint(event_: Event, codepoint: u32) callconv(.c) void {
|
||||
pub fn set_unshifted_codepoint(event_: Event, codepoint: u32) callconv(lib.calling_conv) void {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
event.unshifted_codepoint = @truncate(codepoint);
|
||||
}
|
||||
|
||||
pub fn get_unshifted_codepoint(event_: Event) callconv(.c) u32 {
|
||||
pub fn get_unshifted_codepoint(event_: Event) callconv(lib.calling_conv) u32 {
|
||||
const event: *key.KeyEvent = &event_.?.event;
|
||||
return event.unshifted_codepoint;
|
||||
}
|
||||
|
||||
@@ -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,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const testing = std.testing;
|
||||
const lib = @import("../lib.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const input_mouse_encode = @import("../../input/mouse_encode.zig");
|
||||
@@ -89,7 +90,7 @@ pub const Option = enum(c_int) {
|
||||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Encoder,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(MouseEncoderWrapper) catch
|
||||
return .out_of_memory;
|
||||
@@ -101,7 +102,7 @@ pub fn new(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn free(encoder_: Encoder) callconv(.c) void {
|
||||
pub fn free(encoder_: Encoder) callconv(lib.calling_conv) void {
|
||||
const wrapper = encoder_ orelse return;
|
||||
const alloc = wrapper.alloc;
|
||||
alloc.destroy(wrapper);
|
||||
@@ -111,7 +112,7 @@ pub fn setopt(
|
||||
encoder_: Encoder,
|
||||
option: Option,
|
||||
value: ?*const anyopaque,
|
||||
) callconv(.c) void {
|
||||
) callconv(lib.calling_conv) void {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(Option, @intFromEnum(option)) catch {
|
||||
log.warn("setopt invalid option value={d}", .{@intFromEnum(option)});
|
||||
@@ -187,7 +188,7 @@ fn setoptTyped(
|
||||
pub fn setopt_from_terminal(
|
||||
encoder_: Encoder,
|
||||
terminal_: Terminal,
|
||||
) callconv(.c) void {
|
||||
) callconv(lib.calling_conv) void {
|
||||
const wrapper = encoder_ orelse return;
|
||||
const t: *ZigTerminal = (terminal_ orelse return).terminal;
|
||||
wrapper.opts.event = t.flags.mouse_event;
|
||||
@@ -195,7 +196,7 @@ pub fn setopt_from_terminal(
|
||||
wrapper.last_cell = null;
|
||||
}
|
||||
|
||||
pub fn reset(encoder_: Encoder) callconv(.c) void {
|
||||
pub fn reset(encoder_: Encoder) callconv(lib.calling_conv) void {
|
||||
const wrapper = encoder_ orelse return;
|
||||
wrapper.last_cell = null;
|
||||
}
|
||||
@@ -206,7 +207,7 @@ pub fn encode(
|
||||
out_: ?[*]u8,
|
||||
out_len: usize,
|
||||
out_written: *usize,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const wrapper = encoder_ orelse return .invalid_value;
|
||||
const event = event_ orelse return .invalid_value;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const testing = std.testing;
|
||||
const lib = @import("../lib.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const key = @import("../../input/key.zig");
|
||||
@@ -34,7 +35,7 @@ pub const Mods = key.Mods;
|
||||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Event,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(MouseEventWrapper) catch
|
||||
return .out_of_memory;
|
||||
@@ -43,13 +44,13 @@ pub fn new(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn free(event_: Event) callconv(.c) void {
|
||||
pub fn free(event_: Event) callconv(lib.calling_conv) void {
|
||||
const wrapper = event_ orelse return;
|
||||
const alloc = wrapper.alloc;
|
||||
alloc.destroy(wrapper);
|
||||
}
|
||||
|
||||
pub fn set_action(event_: Event, action: Action) callconv(.c) void {
|
||||
pub fn set_action(event_: Event, action: Action) callconv(lib.calling_conv) void {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(Action, @intFromEnum(action)) catch {
|
||||
log.warn("set_action invalid action value={d}", .{@intFromEnum(action)});
|
||||
@@ -60,11 +61,11 @@ pub fn set_action(event_: Event, action: Action) callconv(.c) void {
|
||||
event_.?.event.action = action;
|
||||
}
|
||||
|
||||
pub fn get_action(event_: Event) callconv(.c) Action {
|
||||
pub fn get_action(event_: Event) callconv(lib.calling_conv) Action {
|
||||
return event_.?.event.action;
|
||||
}
|
||||
|
||||
pub fn set_button(event_: Event, button: Button) callconv(.c) void {
|
||||
pub fn set_button(event_: Event, button: Button) callconv(lib.calling_conv) void {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(Button, @intFromEnum(button)) catch {
|
||||
log.warn("set_button invalid button value={d}", .{@intFromEnum(button)});
|
||||
@@ -75,11 +76,11 @@ pub fn set_button(event_: Event, button: Button) callconv(.c) void {
|
||||
event_.?.event.button = button;
|
||||
}
|
||||
|
||||
pub fn clear_button(event_: Event) callconv(.c) void {
|
||||
pub fn clear_button(event_: Event) callconv(lib.calling_conv) void {
|
||||
event_.?.event.button = null;
|
||||
}
|
||||
|
||||
pub fn get_button(event_: Event, out: ?*Button) callconv(.c) bool {
|
||||
pub fn get_button(event_: Event, out: ?*Button) callconv(lib.calling_conv) bool {
|
||||
if (event_.?.event.button) |button| {
|
||||
if (out) |ptr| ptr.* = button;
|
||||
return true;
|
||||
@@ -88,19 +89,19 @@ pub fn get_button(event_: Event, out: ?*Button) callconv(.c) bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn set_mods(event_: Event, mods: Mods) callconv(.c) void {
|
||||
pub fn set_mods(event_: Event, mods: Mods) callconv(lib.calling_conv) void {
|
||||
event_.?.event.mods = mods;
|
||||
}
|
||||
|
||||
pub fn get_mods(event_: Event) callconv(.c) Mods {
|
||||
pub fn get_mods(event_: Event) callconv(lib.calling_conv) Mods {
|
||||
return event_.?.event.mods;
|
||||
}
|
||||
|
||||
pub fn set_position(event_: Event, pos: Position) callconv(.c) void {
|
||||
pub fn set_position(event_: Event, pos: Position) callconv(lib.calling_conv) void {
|
||||
event_.?.event.pos = pos;
|
||||
}
|
||||
|
||||
pub fn get_position(event_: Event) callconv(.c) Position {
|
||||
pub fn get_position(event_: Event) callconv(lib.calling_conv) Position {
|
||||
return event_.?.event.pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const lib = @import("../lib.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const osc = @import("../osc.zig");
|
||||
@@ -15,7 +16,7 @@ pub const Command = ?*osc.Command;
|
||||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Parser,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(osc.Parser) catch
|
||||
return .out_of_memory;
|
||||
@@ -24,7 +25,7 @@ pub fn new(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn free(parser_: Parser) callconv(.c) void {
|
||||
pub fn free(parser_: Parser) callconv(lib.calling_conv) void {
|
||||
// C-built parsers always have an associated allocator.
|
||||
const parser = parser_ orelse return;
|
||||
const alloc = parser.alloc.?;
|
||||
@@ -32,19 +33,19 @@ pub fn free(parser_: Parser) callconv(.c) void {
|
||||
alloc.destroy(parser);
|
||||
}
|
||||
|
||||
pub fn reset(parser_: Parser) callconv(.c) void {
|
||||
pub fn reset(parser_: Parser) callconv(lib.calling_conv) void {
|
||||
parser_.?.reset();
|
||||
}
|
||||
|
||||
pub fn next(parser_: Parser, byte: u8) callconv(.c) void {
|
||||
pub fn next(parser_: Parser, byte: u8) callconv(lib.calling_conv) void {
|
||||
parser_.?.next(byte);
|
||||
}
|
||||
|
||||
pub fn end(parser_: Parser, terminator: u8) callconv(.c) Command {
|
||||
pub fn end(parser_: Parser, terminator: u8) callconv(lib.calling_conv) Command {
|
||||
return parser_.?.end(terminator);
|
||||
}
|
||||
|
||||
pub fn commandType(command_: Command) callconv(.c) osc.Command.Key {
|
||||
pub fn commandType(command_: Command) callconv(lib.calling_conv) osc.Command.Key {
|
||||
const command = command_ orelse return .invalid;
|
||||
return command.*;
|
||||
}
|
||||
@@ -67,7 +68,7 @@ pub fn commandData(
|
||||
command_: Command,
|
||||
data: CommandData,
|
||||
out: ?*anyopaque,
|
||||
) callconv(.c) bool {
|
||||
) callconv(lib.calling_conv) bool {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(CommandData, @intFromEnum(data)) catch {
|
||||
log.warn("commandData invalid data value={d}", .{@intFromEnum(data)});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ pub const Colors = extern struct {
|
||||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *RenderState,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
result.* = new_(alloc_) catch |err| {
|
||||
result.* = null;
|
||||
return switch (err) {
|
||||
@@ -162,7 +162,7 @@ fn new_(alloc_: ?*const CAllocator) error{OutOfMemory}!*RenderStateWrapper {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
pub fn free(state_: RenderState) callconv(.c) void {
|
||||
pub fn free(state_: RenderState) callconv(lib.calling_conv) void {
|
||||
const state = state_ orelse return;
|
||||
const alloc = state.alloc;
|
||||
state.state.deinit(alloc);
|
||||
@@ -172,7 +172,7 @@ pub fn free(state_: RenderState) callconv(.c) void {
|
||||
pub fn update(
|
||||
state_: RenderState,
|
||||
terminal_: terminal_c.Terminal,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const state = state_ orelse return .invalid_value;
|
||||
const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal;
|
||||
|
||||
@@ -184,7 +184,7 @@ pub fn get(
|
||||
state_: RenderState,
|
||||
data: Data,
|
||||
out: ?*anyopaque,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(Data, @intFromEnum(data)) catch {
|
||||
log.warn("render_state_get invalid data value={d}", .{@intFromEnum(data)});
|
||||
@@ -263,7 +263,7 @@ pub fn set(
|
||||
state_: RenderState,
|
||||
option: SetOption,
|
||||
value: ?*const anyopaque,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(SetOption, @intFromEnum(option)) catch {
|
||||
log.warn("render_state_set invalid option value={d}", .{@intFromEnum(option)});
|
||||
@@ -296,7 +296,7 @@ fn setTyped(
|
||||
pub fn colors_get(
|
||||
state_: RenderState,
|
||||
out_colors_: ?*Colors,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const state = state_ orelse return .invalid_value;
|
||||
const out_colors = out_colors_ orelse return .invalid_value;
|
||||
const out_size = out_colors.size;
|
||||
@@ -354,7 +354,7 @@ pub fn colors_get(
|
||||
pub fn row_iterator_new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *RowIterator,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(RowIteratorWrapper) catch {
|
||||
result.* = null;
|
||||
@@ -372,13 +372,13 @@ pub fn row_iterator_new(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn row_iterator_free(iterator_: RowIterator) callconv(.c) void {
|
||||
pub fn row_iterator_free(iterator_: RowIterator) callconv(lib.calling_conv) void {
|
||||
const iterator = iterator_ orelse return;
|
||||
const alloc = iterator.alloc;
|
||||
alloc.destroy(iterator);
|
||||
}
|
||||
|
||||
pub fn row_iterator_next(iterator_: RowIterator) callconv(.c) bool {
|
||||
pub fn row_iterator_next(iterator_: RowIterator) callconv(lib.calling_conv) bool {
|
||||
const it = iterator_ orelse return false;
|
||||
const next_y: size.CellCountInt = if (it.y) |y| y + 1 else 0;
|
||||
if (next_y >= it.raws.len) return false;
|
||||
@@ -389,7 +389,7 @@ pub fn row_iterator_next(iterator_: RowIterator) callconv(.c) bool {
|
||||
pub fn row_cells_new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *RowCells,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(RowCellsWrapper) catch {
|
||||
result.* = null;
|
||||
@@ -407,7 +407,7 @@ pub fn row_cells_new(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn row_cells_next(cells_: RowCells) callconv(.c) bool {
|
||||
pub fn row_cells_next(cells_: RowCells) callconv(lib.calling_conv) bool {
|
||||
const cells = cells_ orelse return false;
|
||||
const next_x: size.CellCountInt = if (cells.x) |x| x + 1 else 0;
|
||||
if (next_x >= cells.raws.len) return false;
|
||||
@@ -415,14 +415,14 @@ pub fn row_cells_next(cells_: RowCells) callconv(.c) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn row_cells_select(cells_: RowCells, x: size.CellCountInt) callconv(.c) Result {
|
||||
pub fn row_cells_select(cells_: RowCells, x: size.CellCountInt) callconv(lib.calling_conv) Result {
|
||||
const cells = cells_ orelse return .invalid_value;
|
||||
if (x >= cells.raws.len) return .invalid_value;
|
||||
cells.x = x;
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn row_cells_free(cells_: RowCells) callconv(.c) void {
|
||||
pub fn row_cells_free(cells_: RowCells) callconv(lib.calling_conv) void {
|
||||
const cells = cells_ orelse return;
|
||||
const alloc = cells.alloc;
|
||||
alloc.destroy(cells);
|
||||
@@ -455,7 +455,7 @@ pub fn row_cells_get(
|
||||
cells_: RowCells,
|
||||
data: RowCellsData,
|
||||
out: ?*anyopaque,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(RowCellsData, @intFromEnum(data)) catch {
|
||||
log.warn("render_state_row_cells_get invalid data value={d}", .{@intFromEnum(data)});
|
||||
@@ -555,7 +555,7 @@ pub fn row_get(
|
||||
iterator_: RowIterator,
|
||||
data: RowData,
|
||||
out: ?*anyopaque,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(RowData, @intFromEnum(data)) catch {
|
||||
log.warn("render_state_row_get invalid data value={d}", .{@intFromEnum(data)});
|
||||
@@ -605,7 +605,7 @@ pub fn row_set(
|
||||
iterator_: RowIterator,
|
||||
option: RowOption,
|
||||
value: ?*const anyopaque,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(RowOption, @intFromEnum(option)) catch {
|
||||
log.warn("render_state_row_set invalid option value={d}", .{@intFromEnum(option)});
|
||||
|
||||
@@ -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,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const lib = @import("../lib.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const sgr = @import("../sgr.zig");
|
||||
@@ -20,7 +21,7 @@ pub const Parser = ?*ParserWrapper;
|
||||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Parser,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(ParserWrapper) catch
|
||||
return .out_of_memory;
|
||||
@@ -32,7 +33,7 @@ pub fn new(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn free(parser_: Parser) callconv(.c) void {
|
||||
pub fn free(parser_: Parser) callconv(lib.calling_conv) void {
|
||||
const wrapper = parser_ orelse return;
|
||||
const alloc = wrapper.alloc;
|
||||
const parser: *sgr.Parser = &wrapper.parser;
|
||||
@@ -40,7 +41,7 @@ pub fn free(parser_: Parser) callconv(.c) void {
|
||||
alloc.destroy(wrapper);
|
||||
}
|
||||
|
||||
pub fn reset(parser_: Parser) callconv(.c) void {
|
||||
pub fn reset(parser_: Parser) callconv(lib.calling_conv) void {
|
||||
const wrapper = parser_ orelse return;
|
||||
const parser: *sgr.Parser = &wrapper.parser;
|
||||
parser.idx = 0;
|
||||
@@ -51,7 +52,7 @@ pub fn setParams(
|
||||
params: [*]const u16,
|
||||
seps_: ?[*]const u8,
|
||||
len: usize,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const wrapper = parser_ orelse return .invalid_value;
|
||||
const alloc = wrapper.alloc;
|
||||
const parser: *sgr.Parser = &wrapper.parser;
|
||||
@@ -87,7 +88,7 @@ pub fn setParams(
|
||||
pub fn next(
|
||||
parser_: Parser,
|
||||
result: *sgr.Attribute.C,
|
||||
) callconv(.c) bool {
|
||||
) callconv(lib.calling_conv) bool {
|
||||
const wrapper = parser_ orelse return false;
|
||||
const parser: *sgr.Parser = &wrapper.parser;
|
||||
if (parser.next()) |attr| {
|
||||
@@ -101,7 +102,7 @@ pub fn next(
|
||||
pub fn unknown_full(
|
||||
unknown: sgr.Attribute.Unknown.C,
|
||||
ptr: ?*[*]const u16,
|
||||
) callconv(.c) usize {
|
||||
) callconv(lib.calling_conv) usize {
|
||||
if (ptr) |p| p.* = unknown.full_ptr;
|
||||
return unknown.full_len;
|
||||
}
|
||||
@@ -109,30 +110,30 @@ pub fn unknown_full(
|
||||
pub fn unknown_partial(
|
||||
unknown: sgr.Attribute.Unknown.C,
|
||||
ptr: ?*[*]const u16,
|
||||
) callconv(.c) usize {
|
||||
) callconv(lib.calling_conv) usize {
|
||||
if (ptr) |p| p.* = unknown.partial_ptr;
|
||||
return unknown.partial_len;
|
||||
}
|
||||
|
||||
pub fn attribute_tag(
|
||||
attr: sgr.Attribute.C,
|
||||
) callconv(.c) sgr.Attribute.Tag {
|
||||
) callconv(lib.calling_conv) sgr.Attribute.Tag {
|
||||
return attr.tag;
|
||||
}
|
||||
|
||||
pub fn attribute_value(
|
||||
attr: *sgr.Attribute.C,
|
||||
) callconv(.c) *sgr.Attribute.CValue {
|
||||
) callconv(lib.calling_conv) *sgr.Attribute.CValue {
|
||||
return &attr.value;
|
||||
}
|
||||
|
||||
pub fn wasm_alloc_attribute() callconv(.c) *sgr.Attribute.C {
|
||||
pub fn wasm_alloc_attribute() callconv(lib.calling_conv) *sgr.Attribute.C {
|
||||
const alloc = std.heap.wasm_allocator;
|
||||
const ptr = alloc.create(sgr.Attribute.C) catch @panic("out of memory");
|
||||
return ptr;
|
||||
}
|
||||
|
||||
pub fn wasm_free_attribute(attr: *sgr.Attribute.C) callconv(.c) void {
|
||||
pub fn wasm_free_attribute(attr: *sgr.Attribute.C) callconv(lib.calling_conv) void {
|
||||
const alloc = std.heap.wasm_allocator;
|
||||
alloc.destroy(attr);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -55,39 +55,39 @@ const Effects = struct {
|
||||
da_features_buf: [64]device_attributes.Primary.Feature = undefined,
|
||||
|
||||
/// C function pointer type for the write_pty callback.
|
||||
pub const WritePtyFn = *const fn (Terminal, ?*anyopaque, [*]const u8, usize) callconv(.c) void;
|
||||
pub const WritePtyFn = *const fn (Terminal, ?*anyopaque, [*]const u8, usize) callconv(lib.calling_conv) void;
|
||||
|
||||
/// C function pointer type for the bell callback.
|
||||
pub const BellFn = *const fn (Terminal, ?*anyopaque) callconv(.c) void;
|
||||
pub const BellFn = *const fn (Terminal, ?*anyopaque) callconv(lib.calling_conv) void;
|
||||
|
||||
/// C function pointer type for the color_scheme callback.
|
||||
/// Returns true and fills out_scheme if a color scheme is available,
|
||||
/// or returns false to silently ignore the query.
|
||||
pub const ColorSchemeFn = *const fn (Terminal, ?*anyopaque, *device_status.ColorScheme) callconv(.c) bool;
|
||||
pub const ColorSchemeFn = *const fn (Terminal, ?*anyopaque, *device_status.ColorScheme) callconv(lib.calling_conv) bool;
|
||||
|
||||
/// C function pointer type for the enquiry callback.
|
||||
/// Returns the response bytes. The memory must remain valid
|
||||
/// until the callback returns.
|
||||
pub const EnquiryFn = *const fn (Terminal, ?*anyopaque) callconv(.c) lib.String;
|
||||
pub const EnquiryFn = *const fn (Terminal, ?*anyopaque) callconv(lib.calling_conv) lib.String;
|
||||
|
||||
/// C function pointer type for the xtversion callback.
|
||||
/// Returns the version string (e.g. "ghostty 1.2.3"). The memory
|
||||
/// must remain valid until the callback returns. An empty string
|
||||
/// (len=0) causes the default "libghostty" to be reported.
|
||||
pub const XtversionFn = *const fn (Terminal, ?*anyopaque) callconv(.c) lib.String;
|
||||
pub const XtversionFn = *const fn (Terminal, ?*anyopaque) callconv(lib.calling_conv) lib.String;
|
||||
|
||||
/// C function pointer type for the title_changed callback.
|
||||
pub const TitleChangedFn = *const fn (Terminal, ?*anyopaque) callconv(.c) void;
|
||||
pub const TitleChangedFn = *const fn (Terminal, ?*anyopaque) callconv(lib.calling_conv) void;
|
||||
|
||||
/// C function pointer type for the size callback.
|
||||
/// Returns true and fills out_size if size is available,
|
||||
/// or returns false to silently ignore the query.
|
||||
pub const SizeFn = *const fn (Terminal, ?*anyopaque, *size_report.Size) callconv(.c) bool;
|
||||
pub const SizeFn = *const fn (Terminal, ?*anyopaque, *size_report.Size) callconv(lib.calling_conv) bool;
|
||||
|
||||
/// C function pointer type for the device_attributes callback.
|
||||
/// Returns true and fills out_attrs if attributes are available,
|
||||
/// or returns false to silently ignore the query.
|
||||
pub const DeviceAttributesFn = *const fn (Terminal, ?*anyopaque, *CDeviceAttributes) callconv(.c) bool;
|
||||
pub const DeviceAttributesFn = *const fn (Terminal, ?*anyopaque, *CDeviceAttributes) callconv(lib.calling_conv) bool;
|
||||
|
||||
/// C-compatible device attributes struct.
|
||||
/// C: GhosttyDeviceAttributes
|
||||
@@ -221,7 +221,7 @@ pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *Terminal,
|
||||
opts: Options,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
result.* = new_(alloc_, opts) catch |err| {
|
||||
result.* = null;
|
||||
return switch (err) {
|
||||
@@ -282,7 +282,7 @@ pub fn vt_write(
|
||||
terminal_: Terminal,
|
||||
ptr: [*]const u8,
|
||||
len: usize,
|
||||
) callconv(.c) void {
|
||||
) callconv(lib.calling_conv) void {
|
||||
const wrapper = terminal_ orelse return;
|
||||
wrapper.stream.nextSlice(ptr[0..len]);
|
||||
}
|
||||
@@ -322,7 +322,7 @@ pub fn set(
|
||||
terminal_: Terminal,
|
||||
option: Option,
|
||||
value: ?*const anyopaque,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(Option, @intFromEnum(option)) catch {
|
||||
log.warn("terminal_set invalid option value={d}", .{@intFromEnum(option)});
|
||||
@@ -374,7 +374,7 @@ pub const ScrollViewport = ZigTerminal.ScrollViewport.C;
|
||||
pub fn scroll_viewport(
|
||||
terminal_: Terminal,
|
||||
behavior: ScrollViewport,
|
||||
) callconv(.c) void {
|
||||
) callconv(lib.calling_conv) void {
|
||||
const t: *ZigTerminal = (terminal_ orelse return).terminal;
|
||||
t.scrollViewport(switch (behavior.tag) {
|
||||
.top => .top,
|
||||
@@ -389,7 +389,7 @@ pub fn resize(
|
||||
rows: size.CellCountInt,
|
||||
cell_width_px: u32,
|
||||
cell_height_px: u32,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const wrapper = terminal_ orelse return .invalid_value;
|
||||
const t = wrapper.terminal;
|
||||
if (cols == 0 or rows == 0) return .invalid_value;
|
||||
@@ -423,7 +423,7 @@ pub fn resize(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn reset(terminal_: Terminal) callconv(.c) void {
|
||||
pub fn reset(terminal_: Terminal) callconv(lib.calling_conv) void {
|
||||
const t: *ZigTerminal = (terminal_ orelse return).terminal;
|
||||
t.fullReset();
|
||||
}
|
||||
@@ -432,7 +432,7 @@ pub fn mode_get(
|
||||
terminal_: Terminal,
|
||||
tag: modes.ModeTag.Backing,
|
||||
out_value: *bool,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal;
|
||||
const mode_tag: modes.ModeTag = @bitCast(tag);
|
||||
const mode = modes.modeFromInt(mode_tag.value, mode_tag.ansi) orelse return .invalid_value;
|
||||
@@ -444,7 +444,7 @@ pub fn mode_set(
|
||||
terminal_: Terminal,
|
||||
tag: modes.ModeTag.Backing,
|
||||
value: bool,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal;
|
||||
const mode_tag: modes.ModeTag = @bitCast(tag);
|
||||
const mode = modes.modeFromInt(mode_tag.value, mode_tag.ansi) orelse return .invalid_value;
|
||||
@@ -500,7 +500,7 @@ pub fn get(
|
||||
terminal_: Terminal,
|
||||
data: TerminalData,
|
||||
out: ?*anyopaque,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
if (comptime std.debug.runtime_safety) {
|
||||
_ = std.meta.intToEnum(TerminalData, @intFromEnum(data)) catch {
|
||||
log.warn("terminal_get invalid data value={d}", .{@intFromEnum(data)});
|
||||
@@ -561,7 +561,7 @@ pub fn grid_ref(
|
||||
terminal_: Terminal,
|
||||
pt: point.Point.C,
|
||||
out_ref: ?*grid_ref_c.CGridRef,
|
||||
) callconv(.c) Result {
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const t: *ZigTerminal = (terminal_ orelse return .invalid_value).terminal;
|
||||
const zig_pt: point.Point = switch (pt.tag) {
|
||||
.active => .{ .active = pt.value.active },
|
||||
@@ -575,7 +575,7 @@ pub fn grid_ref(
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn free(terminal_: Terminal) callconv(.c) void {
|
||||
pub fn free(terminal_: Terminal) callconv(lib.calling_conv) void {
|
||||
const wrapper = terminal_ orelse return;
|
||||
const t = wrapper.terminal;
|
||||
|
||||
@@ -1162,7 +1162,7 @@ test "set write_pty callback" {
|
||||
last_userdata = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, ud: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, ud: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
last_userdata = ud;
|
||||
@@ -1214,7 +1214,7 @@ test "set write_pty null clears callback" {
|
||||
|
||||
const S = struct {
|
||||
var called: bool = false;
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, _: [*]const u8, _: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, _: [*]const u8, _: usize) callconv(lib.calling_conv) void {
|
||||
called = true;
|
||||
}
|
||||
};
|
||||
@@ -1245,7 +1245,7 @@ test "set bell callback" {
|
||||
var bell_count: usize = 0;
|
||||
var last_userdata: ?*anyopaque = null;
|
||||
|
||||
fn bell(_: Terminal, ud: ?*anyopaque) callconv(.c) void {
|
||||
fn bell(_: Terminal, ud: ?*anyopaque) callconv(lib.calling_conv) void {
|
||||
bell_count += 1;
|
||||
last_userdata = ud;
|
||||
}
|
||||
@@ -1306,13 +1306,13 @@ test "set enquiry callback" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
|
||||
const response = "OK";
|
||||
fn enquiry(_: Terminal, _: ?*anyopaque) callconv(.c) lib.String {
|
||||
fn enquiry(_: Terminal, _: ?*anyopaque) callconv(lib.calling_conv) lib.String {
|
||||
return .{ .ptr = response, .len = response.len };
|
||||
}
|
||||
};
|
||||
@@ -1365,13 +1365,13 @@ test "set xtversion callback" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
|
||||
const version = "myterm 1.0";
|
||||
fn xtversion(_: Terminal, _: ?*anyopaque) callconv(.c) lib.String {
|
||||
fn xtversion(_: Terminal, _: ?*anyopaque) callconv(lib.calling_conv) lib.String {
|
||||
return .{ .ptr = version, .len = version.len };
|
||||
}
|
||||
};
|
||||
@@ -1408,7 +1408,7 @@ test "xtversion without callback reports default" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
@@ -1440,7 +1440,7 @@ test "set title_changed callback" {
|
||||
var title_count: usize = 0;
|
||||
var last_userdata: ?*anyopaque = null;
|
||||
|
||||
fn titleChanged(_: Terminal, ud: ?*anyopaque) callconv(.c) void {
|
||||
fn titleChanged(_: Terminal, ud: ?*anyopaque) callconv(lib.calling_conv) void {
|
||||
title_count += 1;
|
||||
last_userdata = ud;
|
||||
}
|
||||
@@ -1500,12 +1500,12 @@ test "set size callback" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
|
||||
fn sizeCb(_: Terminal, _: ?*anyopaque, out_size: *size_report.Size) callconv(.c) bool {
|
||||
fn sizeCb(_: Terminal, _: ?*anyopaque, out_size: *size_report.Size) callconv(lib.calling_conv) bool {
|
||||
out_size.* = .{
|
||||
.rows = 24,
|
||||
.columns = 80,
|
||||
@@ -1564,12 +1564,12 @@ test "set device_attributes callback primary" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
|
||||
fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(.c) bool {
|
||||
fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(lib.calling_conv) bool {
|
||||
out.* = .{
|
||||
.primary = .{
|
||||
.conformance_level = 64,
|
||||
@@ -1618,12 +1618,12 @@ test "set device_attributes callback secondary" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
|
||||
fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(.c) bool {
|
||||
fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(lib.calling_conv) bool {
|
||||
out.* = .{
|
||||
.primary = .{
|
||||
.conformance_level = 62,
|
||||
@@ -1672,12 +1672,12 @@ test "set device_attributes callback tertiary" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
|
||||
fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(.c) bool {
|
||||
fn da(_: Terminal, _: ?*anyopaque, out: *Effects.CDeviceAttributes) callconv(lib.calling_conv) bool {
|
||||
out.* = .{
|
||||
.primary = .{
|
||||
.conformance_level = 62,
|
||||
@@ -1726,7 +1726,7 @@ test "device_attributes without callback uses default" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
@@ -1762,12 +1762,12 @@ test "device_attributes callback returns false uses default" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
|
||||
fn da(_: Terminal, _: ?*anyopaque, _: *Effects.CDeviceAttributes) callconv(.c) bool {
|
||||
fn da(_: Terminal, _: ?*anyopaque, _: *Effects.CDeviceAttributes) callconv(lib.calling_conv) bool {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -1955,7 +1955,7 @@ test "resize sends in-band size report" {
|
||||
last_data = null;
|
||||
}
|
||||
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, ptr: [*]const u8, len: usize) callconv(lib.calling_conv) void {
|
||||
if (last_data) |d| testing.allocator.free(d);
|
||||
last_data = testing.allocator.dupe(u8, ptr[0..len]) catch @panic("OOM");
|
||||
}
|
||||
@@ -1990,7 +1990,7 @@ test "resize no size report without mode 2048" {
|
||||
|
||||
const S = struct {
|
||||
var called: bool = false;
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, _: [*]const u8, _: usize) callconv(.c) void {
|
||||
fn writePty(_: Terminal, _: ?*anyopaque, _: [*]const u8, _: usize) callconv(lib.calling_conv) void {
|
||||
called = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,8 +73,7 @@ pub const Attribute = sgr.Attribute;
|
||||
pub const Options = @import("build_options.zig").Options;
|
||||
pub const options = @import("terminal_options");
|
||||
|
||||
/// This is set to true when we're building the C library.
|
||||
pub const c_api = if (options.c_abi) @import("c/main.zig") else void;
|
||||
pub const c_api = @import("c/main.zig");
|
||||
|
||||
test {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
|
||||
Reference in New Issue
Block a user