diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-31 06:28:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-31 06:28:48 -0300 |
| commit | a479792a1ab2b593642d7f648194bfa23ce01dba (patch) | |
| tree | 96ddee7d879a9084daa07db43b0b7910b072a785 /test/kitty_client.zig | |
| parent | e179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff) | |
| parent | 4c761893e5b3fdae422622cfa02104ab36633045 (diff) | |
| download | pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip | |
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'test/kitty_client.zig')
| -rw-r--r-- | test/kitty_client.zig | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/test/kitty_client.zig b/test/kitty_client.zig index 753727df..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,15 +43,14 @@ pub fn main(init: std.process.Init) !void { const case = args[1]; const out = try arena.dupeSentinel(u8, args[2], 0); - var saved: c.termios = undefined; - if (c.tcgetattr(0, &saved) != 0) return error.NotATerminal; + const saved = try getTermios(); var raw = saved; raw.lflag.ICANON = false; raw.lflag.ECHO = false; - raw.cc[@backingInt(c.V.MIN)] = 0; - raw.cc[@backingInt(c.V.TIME)] = 1; - _ = c.tcsetattr(0, .NOW, &raw); - defer _ = c.tcsetattr(0, .NOW, &saved); + raw.cc[@backingInt(std.posix.V.MIN)] = 0; + raw.cc[@backingInt(std.posix.V.TIME)] = 1; + setTermios(raw); + defer setTermios(saved); var cmds: std.ArrayList(u8) = .empty; try play(arena, case, &cmds); |
