Skip to content

Commit a6180bb

Browse files
chrisbbreuerclaude
andcommitted
revert: restore Zig 0.16-dev APIs (will upload dev Zig to pantry)
Reverts the 0.15.1 API downgrade. The repos should target 0.16-dev. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1ebc41c commit a6180bb

7 files changed

Lines changed: 126 additions & 107 deletions

File tree

src/cli/Help.zig

Lines changed: 50 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,82 +9,81 @@ 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+
1218
pub fn generate(self: *Help, command: *Command, cli_name: []const u8, version: []const u8) !void {
1319
_ = self;
14-
const stdout = std.fs.File.stdout();
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;
1524

1625
// Header
17-
var buf: [4096]u8 = undefined;
18-
var line = try std.fmt.bufPrint(&buf, "\n{s} v{s}\n", .{ cli_name, version });
19-
try stdout.writeAll(line);
20-
line = try std.fmt.bufPrint(&buf, "{s}\n\n", .{command.description});
21-
try stdout.writeAll(line);
26+
try stdout.print("\n{s} v{s}\n", .{ cli_name, version });
27+
try stdout.print("{s}\n\n", .{command.description});
2228

2329
// Usage
24-
try stdout.writeAll("USAGE:\n");
25-
line = try std.fmt.bufPrint(&buf, " {s}", .{command.name});
26-
try stdout.writeAll(line);
30+
try stdout.print("USAGE:\n", .{});
31+
try stdout.print(" {s}", .{command.name});
2732

2833
if (command.options.items.len > 0) {
29-
try stdout.writeAll(" [OPTIONS]");
34+
try stdout.print(" [OPTIONS]", .{});
3035
}
3136

3237
if (command.subcommands.items.len > 0) {
33-
try stdout.writeAll(" <COMMAND>");
38+
try stdout.print(" <COMMAND>", .{});
3439
}
3540

3641
for (command.arguments.items) |arg| {
3742
if (arg.required) {
38-
line = try std.fmt.bufPrint(&buf, " <{s}>", .{arg.name});
39-
try stdout.writeAll(line);
43+
try stdout.print(" <{s}>", .{arg.name});
4044
} else {
41-
line = try std.fmt.bufPrint(&buf, " [{s}]", .{arg.name});
42-
try stdout.writeAll(line);
45+
try stdout.print(" [{s}]", .{arg.name});
4346
}
4447
if (arg.variadic) {
45-
try stdout.writeAll("...");
48+
try stdout.print("...", .{});
4649
}
4750
}
48-
try stdout.writeAll("\n\n");
51+
try stdout.print("\n\n", .{});
4952

5053
// Arguments
5154
if (command.arguments.items.len > 0) {
52-
try stdout.writeAll("ARGUMENTS:\n");
55+
try stdout.print("ARGUMENTS:\n", .{});
5356
for (command.arguments.items) |arg| {
54-
line = try std.fmt.bufPrint(&buf, " <{s}>", .{arg.name});
55-
try stdout.writeAll(line);
57+
try stdout.print(" <{s}>", .{arg.name});
5658
if (arg.variadic) {
57-
try stdout.writeAll("...");
59+
try stdout.print("...", .{});
5860
}
5961
const padding = 20 -| (arg.name.len + 2 + if (arg.variadic) @as(usize, 3) else @as(usize, 0));
60-
for (0..padding) |_| try stdout.writeAll(" ");
61-
line = try std.fmt.bufPrint(&buf, "{s}", .{arg.description});
62-
try stdout.writeAll(line);
62+
for (0..padding) |_| try stdout.writeByte(' ');
63+
try stdout.print("{s}", .{arg.description});
6364
if (!arg.required) {
64-
try stdout.writeAll(" (optional)");
65+
try stdout.print(" (optional)", .{});
6566
}
66-
try stdout.writeAll("\n");
67+
try stdout.print("\n", .{});
6768
}
68-
try stdout.writeAll("\n");
69+
try stdout.print("\n", .{});
6970
}
7071

7172
// Options
7273
if (command.options.items.len > 0) {
73-
try stdout.writeAll("OPTIONS:\n");
74+
try stdout.print("OPTIONS:\n", .{});
7475
for (command.options.items) |opt| {
7576
var length: usize = 0;
7677

7778
if (opt.short) |s| {
78-
line = try std.fmt.bufPrint(&buf, " -{c}, ", .{s});
79-
try stdout.writeAll(line);
79+
try stdout.print(" -{c}, ", .{s});
8080
length += 6;
8181
} else {
82-
try stdout.writeAll(" ");
82+
try stdout.print(" ", .{});
8383
length += 6;
8484
}
8585

86-
line = try std.fmt.bufPrint(&buf, "--{s}", .{opt.long});
87-
try stdout.writeAll(line);
86+
try stdout.print("--{s}", .{opt.long});
8887
length += opt.long.len + 2;
8988

9089
if (opt.option_type != .bool) {
@@ -94,46 +93,42 @@ pub fn generate(self: *Help, command: *Command, cli_name: []const u8, version: [
9493
.float => "<FLOAT>",
9594
.bool => "",
9695
};
97-
line = try std.fmt.bufPrint(&buf, " {s}", .{type_name});
98-
try stdout.writeAll(line);
96+
try stdout.print(" {s}", .{type_name});
9997
length += type_name.len + 1;
10098
}
10199

102100
const padding = 30 -| length;
103-
for (0..padding) |_| try stdout.writeAll(" ");
101+
for (0..padding) |_| try stdout.writeByte(' ');
104102

105-
line = try std.fmt.bufPrint(&buf, "{s}", .{opt.description});
106-
try stdout.writeAll(line);
103+
try stdout.print("{s}", .{opt.description});
107104

108105
if (opt.required) {
109-
try stdout.writeAll(" (required)");
106+
try stdout.print(" (required)", .{});
110107
} else if (opt.default_value) |default| {
111-
line = try std.fmt.bufPrint(&buf, " (default: {s})", .{default});
112-
try stdout.writeAll(line);
108+
try stdout.print(" (default: {s})", .{default});
113109
}
114110

115-
try stdout.writeAll("\n");
111+
try stdout.print("\n", .{});
116112
}
117113

118-
try stdout.writeAll(" -h, --help");
119-
for (0..20) |_| try stdout.writeAll(" ");
120-
try stdout.writeAll("Print help\n");
121-
try stdout.writeAll("\n");
114+
try stdout.print(" -h, --help", .{});
115+
for (0..20) |_| try stdout.writeByte(' ');
116+
try stdout.print("Print help\n", .{});
117+
try stdout.print("\n", .{});
122118
}
123119

124120
// Commands
125121
if (command.subcommands.items.len > 0) {
126-
try stdout.writeAll("COMMANDS:\n");
122+
try stdout.print("COMMANDS:\n", .{});
127123
for (command.subcommands.items) |subcmd| {
128-
line = try std.fmt.bufPrint(&buf, " {s}", .{subcmd.name});
129-
try stdout.writeAll(line);
124+
try stdout.print(" {s}", .{subcmd.name});
130125
const padding = 20 -| subcmd.name.len;
131-
for (0..padding) |_| try stdout.writeAll(" ");
132-
line = try std.fmt.bufPrint(&buf, "{s}\n", .{subcmd.description});
133-
try stdout.writeAll(line);
126+
for (0..padding) |_| try stdout.writeByte(' ');
127+
try stdout.print("{s}\n", .{subcmd.description});
134128
}
135-
try stdout.writeAll("\n");
136-
line = try std.fmt.bufPrint(&buf, "Run '{s} <COMMAND> --help' for more information on a command.\n\n", .{command.name});
137-
try stdout.writeAll(line);
129+
try stdout.print("\n", .{});
130+
try stdout.print("Run '{s} <COMMAND> --help' for more information on a command.\n\n", .{command.name});
138131
}
132+
133+
try stdout.flush();
139134
}

src/cli/Middleware.zig

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,23 @@ 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+
93104
/// Logging middleware
94105
pub fn loggingMiddleware(ctx: *MiddlewareContext) !bool {
95-
const stdout = std.fs.File.stdout();
96-
var buf: [256]u8 = undefined;
97-
const line = try std.fmt.bufPrint(&buf, "[LOG] Executing command: {s}\n", .{ctx.command.name});
98-
try stdout.writeAll(line);
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();
99110
return true;
100111
}
101112

@@ -115,10 +126,10 @@ pub fn validationMiddleware(ctx: *MiddlewareContext) !bool {
115126
// Check if all required options are present
116127
for (ctx.command.options.items) |opt| {
117128
if (opt.required and !ctx.parse_context.hasOption(opt.name)) {
118-
const stderr = std.fs.File.stderr();
119-
var buf: [256]u8 = undefined;
120-
const line = try std.fmt.bufPrint(&buf, "Error: Missing required option '--{s}'\n", .{opt.long});
121-
try stderr.writeAll(line);
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();
122133
return false;
123134
}
124135
}

src/config/Config.zig

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

66
const Config = @This();
77

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

150154
/// Load config from a file
151155
pub fn loadFromFile(self: *Config, path: []const u8, format: ConfigFormat) !void {
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));
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);
157164
defer self.allocator.free(content);
158165

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

src/prompt/PathPrompt.zig

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

66
const PathPrompt = @This();
77

8+
fn getIo() std.Io {
9+
return std.Options.debug_io;
10+
}
11+
812
pub const PathType = enum {
913
file,
1014
directory,
@@ -85,16 +89,17 @@ fn handleKey(self: *PathPrompt, key: Terminal.KeyPress) !void {
8589
} else {
8690
// Submit
8791
const value = self.core.getValue();
88-
const cwd = std.fs.cwd();
92+
const io = getIo();
93+
const cwd: std.Io.Dir = .cwd();
8994

9095
if (self.must_exist) {
91-
cwd.access(value, .{}) catch {
96+
cwd.access(io, value, .{}) catch {
9297
self.core.setError("Path does not exist");
9398
return;
9499
};
95100

96101
// Check type
97-
const stat = cwd.statFile(value) catch {
102+
const stat = cwd.statFile(io, value, .{}) catch {
98103
self.core.setError("Cannot access path");
99104
return;
100105
};
@@ -201,15 +206,16 @@ fn updateSuggestions(self: *PathPrompt) !void {
201206
const file_prefix = std.fs.path.basename(value);
202207

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

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

215221
// Filter by type

src/prompt/ProgressBar.zig

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

77
pub const ProgressBarStyle = enum {
8-
bar, // [=====> ]
9-
blocks, // ████████░░░
10-
dots, // ⣿⣿⣿⣿⣿⣀⣀⣀⣀⣀
11-
ascii, // [###> ]
8+
bar, // [=====> ]
9+
blocks, // ████████░░░
10+
dots, // ⣿⣿⣿⣿⣿⣀⣀⣀⣀⣀
11+
ascii, // [###> ]
1212
};
1313

1414
terminal: Terminal,

0 commit comments

Comments
 (0)