Skip to content

Commit 4ffa9d3

Browse files
chrisbbreuerclaude
andcommitted
fix: zig 0.16 compatibility — winsize struct and libc linking
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a7203aa commit 4ffa9d3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

build.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ pub fn build(b: *std.Build) void {
99
.root_source_file = b.path("src/root.zig"),
1010
.target = target,
1111
.optimize = optimize,
12+
.link_libc = true,
1213
});
1314

1415
// ── Tests ───────────────────────────────────────────────────────────
1516
const test_module = b.createModule(.{
1617
.root_source_file = b.path("src/root.zig"),
1718
.target = target,
1819
.optimize = optimize,
20+
.link_libc = true,
1921
});
2022
const lib_tests = b.addTest(.{
2123
.root_module = test_module,

src/prompt/Terminal.zig

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ const TerminalSize = struct {
122122
height: usize,
123123
};
124124

125+
/// Manually defined winsize struct for ioctl TIOCGWINSZ.
126+
/// In Zig 0.16+, std.posix.system.winsize / std.c.winsize is no longer pub.
127+
const Winsize = extern struct {
128+
row: u16,
129+
col: u16,
130+
xpixel: u16,
131+
ypixel: u16,
132+
};
133+
125134
fn detectTerminalSize() TerminalSize {
126135
if (builtin.os.tag == .windows) {
127136
// Windows console API would go here
@@ -130,13 +139,13 @@ fn detectTerminalSize() TerminalSize {
130139

131140
// Try to get terminal size via ioctl
132141
const stdout = std.Io.File.stdout();
133-
var winsize: posix.system.winsize = undefined;
142+
var ws: Winsize = undefined;
134143

135-
const result = posix.system.ioctl(stdout.handle, posix.T.IOCGWINSZ, @intFromPtr(&winsize));
136-
if (result == 0 and winsize.col > 0 and winsize.row > 0) {
144+
const result = posix.system.ioctl(stdout.handle, posix.T.IOCGWINSZ, @intFromPtr(&ws));
145+
if (result == 0 and ws.col > 0 and ws.row > 0) {
137146
return .{
138-
.width = winsize.col,
139-
.height = winsize.row,
147+
.width = ws.col,
148+
.height = ws.row,
140149
};
141150
}
142151

0 commit comments

Comments
 (0)