Skip to content

Commit 8fe912b

Browse files
chrisbbreuerclaude
andcommitted
fix: use Zig 0.15.1 APIs for compatibility with pantry
Replace std.Io.File with std.fs.File, std.Io.File.stdin/stdout/stderr with std.io.getStdIn/getStdOut/getStdErr, remove io parameter from all file/dir operations, use writer() instead of writerStreaming(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3688d4e commit 8fe912b

6 files changed

Lines changed: 32 additions & 78 deletions

File tree

src/cli/Help.zig

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,9 @@ pub fn init(allocator: std.mem.Allocator) Help {
99
return .{ .allocator = allocator };
1010
}
1111

12-
fn getWriter() std.Io.File.Writer {
13-
const io = std.Options.debug_io;
14-
var buf: [4096]u8 = undefined;
15-
return std.Io.File.stdout().writerStreaming(io, &buf);
16-
}
17-
1812
pub fn generate(self: *Help, command: *Command, cli_name: []const u8, version: []const u8) !void {
1913
_ = self;
20-
var buf: [4096]u8 = undefined;
21-
const io = std.Options.debug_io;
22-
var file_writer = std.Io.File.stdout().writerStreaming(io, &buf);
23-
const stdout = &file_writer.interface;
14+
const stdout = std.io.getStdOut().writer();
2415

2516
// Header
2617
try stdout.print("\n{s} v{s}\n", .{ cli_name, version });
@@ -129,6 +120,4 @@ pub fn generate(self: *Help, command: *Command, cli_name: []const u8, version: [
129120
try stdout.print("\n", .{});
130121
try stdout.print("Run '{s} <COMMAND> --help' for more information on a command.\n\n", .{command.name});
131122
}
132-
133-
try stdout.flush();
134123
}

src/cli/Middleware.zig

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,10 @@ pub const MiddlewareChain = struct {
9090

9191
// Built-in middleware
9292

93-
fn stdoutWriter() StdoutWriter {
94-
var buf: [4096]u8 = undefined;
95-
return .{
96-
.file_writer = std.Io.File.stdout().writerStreaming(std.Options.debug_io, &buf),
97-
};
98-
}
99-
100-
const StdoutWriter = struct {
101-
file_writer: std.Io.File.Writer,
102-
};
103-
10493
/// Logging middleware
10594
pub fn loggingMiddleware(ctx: *MiddlewareContext) !bool {
106-
var buf: [4096]u8 = undefined;
107-
var file_writer = std.Io.File.stdout().writerStreaming(std.Options.debug_io, &buf);
108-
try file_writer.interface.print("[LOG] Executing command: {s}\n", .{ctx.command.name});
109-
try file_writer.interface.flush();
95+
const stdout = std.io.getStdOut().writer();
96+
try stdout.print("[LOG] Executing command: {s}\n", .{ctx.command.name});
11097
return true;
11198
}
11299

@@ -126,10 +113,8 @@ pub fn validationMiddleware(ctx: *MiddlewareContext) !bool {
126113
// Check if all required options are present
127114
for (ctx.command.options.items) |opt| {
128115
if (opt.required and !ctx.parse_context.hasOption(opt.name)) {
129-
var buf: [4096]u8 = undefined;
130-
var file_writer = std.Io.File.stderr().writerStreaming(std.Options.debug_io, &buf);
131-
try file_writer.interface.print("Error: Missing required option '--{s}'\n", .{opt.long});
132-
try file_writer.interface.flush();
116+
const stderr = std.io.getStdErr().writer();
117+
try stderr.print("Error: Missing required option '--{s}'\n", .{opt.long});
133118
return false;
134119
}
135120
}

src/config/Config.zig

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ const Json5Parser = @import("Json5Parser.zig");
55

66
const Config = @This();
77

8-
fn getIo() std.Io {
9-
return std.Options.debug_io;
10-
}
11-
128
pub const ConfigFormat = enum {
139
toml,
1410
jsonc,
@@ -153,14 +149,11 @@ pub fn deinit(self: *Config) void {
153149

154150
/// Load config from a file
155151
pub fn loadFromFile(self: *Config, path: []const u8, format: ConfigFormat) !void {
156-
const io = getIo();
157-
const cwd: std.Io.Dir = .cwd();
158-
const file = try cwd.openFile(io, path, .{});
159-
defer file.close(io);
160-
161-
var read_buf: [4096]u8 = undefined;
162-
var reader = file.readerStreaming(io, &read_buf);
163-
const content = try reader.interface.allocRemaining(self.allocator, .unlimited);
152+
const cwd = std.fs.cwd();
153+
const file = try cwd.openFile(path, .{});
154+
defer file.close();
155+
156+
const content = try file.readToEndAlloc(self.allocator, std.math.maxInt(usize));
164157
defer self.allocator.free(content);
165158

166159
const actual_format = if (format == .auto) ConfigFormat.fromPath(path) else format;

src/prompt/PathPrompt.zig

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ const Ansi = @import("Ansi.zig");
55

66
const PathPrompt = @This();
77

8-
fn getIo() std.Io {
9-
return std.Options.debug_io;
10-
}
11-
128
pub const PathType = enum {
139
file,
1410
directory,
@@ -89,17 +85,16 @@ fn handleKey(self: *PathPrompt, key: Terminal.KeyPress) !void {
8985
} else {
9086
// Submit
9187
const value = self.core.getValue();
92-
const io = getIo();
93-
const cwd: std.Io.Dir = .cwd();
88+
const cwd = std.fs.cwd();
9489

9590
if (self.must_exist) {
96-
cwd.access(io, value, .{}) catch {
91+
cwd.access(value, .{}) catch {
9792
self.core.setError("Path does not exist");
9893
return;
9994
};
10095

10196
// Check type
102-
const stat = cwd.statFile(io, value, .{}) catch {
97+
const stat = cwd.statFile(value) catch {
10398
self.core.setError("Cannot access path");
10499
return;
105100
};
@@ -206,16 +201,15 @@ fn updateSuggestions(self: *PathPrompt) !void {
206201
const file_prefix = std.fs.path.basename(value);
207202

208203
// Open directory
209-
const io = getIo();
210-
const cwd: std.Io.Dir = .cwd();
211-
var dir = cwd.openDir(io, dir_path, .{ .iterate = true }) catch {
204+
const cwd = std.fs.cwd();
205+
var dir = cwd.openDir(dir_path, .{ .iterate = true }) catch {
212206
return; // Can't open, no suggestions
213207
};
214-
defer dir.close(io);
208+
defer dir.close();
215209

216210
var iter = dir.iterate();
217211
var count: usize = 0;
218-
while (try iter.next(io)) |entry| {
212+
while (try iter.next()) |entry| {
219213
if (count >= 10) break; // Limit to 10 suggestions
220214

221215
// Filter by type

src/prompt/Style.zig

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,18 @@ pub const Style = struct {
231231
const styled = try self.render();
232232
defer self.allocator.free(styled);
233233

234-
const io = std.Options.debug_io;
235-
try std.Io.File.stdout().writeStreamingAll(io, styled);
234+
const stdout = std.io.getStdOut();
235+
try stdout.writeAll(styled);
236236
}
237237

238238
/// Convenience method to render and return with newline
239239
pub fn println(self: *Style) !void {
240240
const styled = try self.render();
241241
defer self.allocator.free(styled);
242242

243-
const io = std.Options.debug_io;
244-
const stdout = std.Io.File.stdout();
245-
try stdout.writeStreamingAll(io, styled);
246-
try stdout.writeStreamingAll(io, "\n");
243+
const stdout = std.io.getStdOut();
244+
try stdout.writeAll(styled);
245+
try stdout.writeAll("\n");
247246
}
248247
};
249248

src/prompt/Terminal.zig

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ const posix = std.posix;
44

55
const Terminal = @This();
66

7-
/// Get a basic Io instance for synchronous operations
8-
fn getIo() std.Io {
9-
return std.Options.debug_io;
10-
}
11-
127
pub const RawMode = struct {
138
original_termios: if (builtin.os.tag != .windows) posix.termios else void,
149

@@ -17,7 +12,7 @@ pub const RawMode = struct {
1712
// Windows terminal setup would go here
1813
return RawMode{ .original_termios = {} };
1914
} else {
20-
const stdin = std.Io.File.stdin();
15+
const stdin = std.io.getStdIn();
2116
const original = try posix.tcgetattr(stdin.handle);
2217
var raw = original;
2318

@@ -40,7 +35,7 @@ pub const RawMode = struct {
4035
if (builtin.os.tag == .windows) {
4136
return;
4237
}
43-
const stdin = std.Io.File.stdin();
38+
const stdin = std.io.getStdIn();
4439
posix.tcsetattr(stdin.handle, .FLUSH, self.original_termios) catch {};
4540
}
4641
};
@@ -68,8 +63,8 @@ pub const KeyPress = struct {
6863
char: ?u8 = null,
6964
};
7065

71-
stdin: std.Io.File,
72-
stdout: std.Io.File,
66+
stdin: std.fs.File,
67+
stdout: std.fs.File,
7368
supports_unicode: bool,
7469
supports_color: bool,
7570
width: usize,
@@ -81,8 +76,8 @@ pub fn init() Terminal {
8176
const size = detectTerminalSize();
8277

8378
return .{
84-
.stdin = std.Io.File.stdin(),
85-
.stdout = std.Io.File.stdout(),
79+
.stdin = std.io.getStdIn(),
80+
.stdout = std.io.getStdOut(),
8681
.supports_unicode = supports_unicode,
8782
.supports_color = supports_color,
8883
.width = size.width,
@@ -123,7 +118,6 @@ const TerminalSize = struct {
123118
};
124119

125120
/// Manually defined winsize struct for ioctl TIOCGWINSZ.
126-
/// In Zig 0.16+, std.posix.system.winsize / std.c.winsize is no longer pub.
127121
const Winsize = extern struct {
128122
row: u16,
129123
col: u16,
@@ -138,7 +132,7 @@ fn detectTerminalSize() TerminalSize {
138132
}
139133

140134
// Try to get terminal size via ioctl
141-
const stdout = std.Io.File.stdout();
135+
const stdout = std.io.getStdOut();
142136
var ws: Winsize = undefined;
143137

144138
const result = posix.system.ioctl(stdout.handle, posix.T.IOCGWINSZ, @intFromPtr(&ws));
@@ -195,12 +189,12 @@ pub fn readKey(self: *Terminal) !?KeyPress {
195189
}
196190

197191
pub fn write(self: *Terminal, text: []const u8) !void {
198-
try self.stdout.writeStreamingAll(getIo(), text);
192+
try self.stdout.writeAll(text);
199193
}
200194

201195
pub fn writeLine(self: *Terminal, text: []const u8) !void {
202-
try self.stdout.writeStreamingAll(getIo(), text);
203-
try self.stdout.writeStreamingAll(getIo(), "\n");
196+
try self.stdout.writeAll(text);
197+
try self.stdout.writeAll("\n");
204198
}
205199

206200
pub fn clearScreen(self: *Terminal) !void {

0 commit comments

Comments
 (0)