summaryrefslogtreecommitdiff
path: root/test/kitty_client.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/kitty_client.zig')
-rw-r--r--test/kitty_client.zig25
1 files changed, 20 insertions, 5 deletions
diff --git a/test/kitty_client.zig b/test/kitty_client.zig
index 0d84f374..03ad629e 100644
--- a/test/kitty_client.zig
+++ b/test/kitty_client.zig
@@ -17,6 +17,23 @@ pub const side = 64;
pub const colour = [3]u8{ 13, 77, 231 };
const sync = "\x1b_Gi=999,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\";
+// The kernel's ioctls on Linux: glibc's tcgetattr writes its 60-byte
+// termios into Zig's 44-byte kernel one, and std.posix's calls glibc's in a
+// program linking libc (src/main.zig exports kernel ones; this has none).
+const linux = @import("builtin").os.tag == .linux;
+
+fn getTermios() !std.posix.termios {
+ if (!linux) return std.posix.tcgetattr(0) catch error.NotATerminal;
+ var t: std.os.linux.termios = undefined;
+ if (std.os.linux.errno(std.os.linux.tcgetattr(0, &t)) != .SUCCESS) return error.NotATerminal;
+ return t;
+}
+
+fn setTermios(t: std.posix.termios) void {
+ if (!linux) return std.posix.tcsetattr(0, .NOW, t) catch {};
+ _ = std.os.linux.tcsetattr(0, .NOW, &t);
+}
+
pub fn main(init: std.process.Init) !void {
var arena_state: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
defer arena_state.deinit();
@@ -26,16 +43,14 @@ pub fn main(init: std.process.Init) !void {
const case = args[1];
const out = try arena.dupeSentinel(u8, args[2], 0);
- // std.posix, not std.c: glibc's tcgetattr writes its 60-byte termios
- // into Zig's 44-byte kernel one.
- const saved = std.posix.tcgetattr(0) catch return error.NotATerminal;
+ const saved = try getTermios();
var raw = saved;
raw.lflag.ICANON = false;
raw.lflag.ECHO = false;
raw.cc[@backingInt(std.posix.V.MIN)] = 0;
raw.cc[@backingInt(std.posix.V.TIME)] = 1;
- std.posix.tcsetattr(0, .NOW, raw) catch {};
- defer std.posix.tcsetattr(0, .NOW, saved) catch {};
+ setTermios(raw);
+ defer setTermios(saved);
var cmds: std.ArrayList(u8) = .empty;
try play(arena, case, &cmds);