Update fmt.zig with new master Io changes

Signed-off-by: Emily Flion <emneo@kreog.com>
This commit is contained in:
Emily Flion 2026-01-01 18:18:12 +01:00
parent 3fac53b652
commit 24cf819a6c
No known key found for this signature in database
GPG Key ID: 8EBFC4B924C62D20

View File

@ -9,6 +9,7 @@ const Ast = std.zig.Ast;
/// to stderr with error information at the lines that failed. If present, `message` is printed
/// at the end of the error output. Caller owns allocated slice.
pub fn zig(
io: std.Io,
allocator: Allocator,
input: []const u8,
message: ?[]const u8,
@ -26,9 +27,13 @@ pub fn zig(
.zig,
);
if (ast.errors.len > 0) {
const tty = std.Io.tty.detectConfig(std.fs.File.stderr());
var stderr_fw = std.fs.File.stderr().writer(&.{});
var write_buf: [256]u8 = undefined;
var stderr_fw = std.Io.File.stderr().writer(io, &write_buf);
const writer = &stderr_fw.interface;
const tty: std.Io.Terminal = .{
.writer = writer,
.mode = try .detect(io, std.Io.File.stderr(), false, false),
};
var it = std.mem.tokenizeScalar(u8, input, '\n');
var line_number: usize = 1;
@ -36,7 +41,7 @@ pub fn zig(
const maybe_err = for (ast.errors) |err| {
if (ast.tokenLocation(0, err.token).line == line_number + 1) break err;
} else null;
try tty.setColor(writer, if (maybe_err != null) .red else .cyan);
try tty.setColor(if (maybe_err != null) .red else .cyan);
const error_message = if (maybe_err) |err| blk: {
var buf_writer: Writer.Allocating = .init(alloc);
try buf_writer.writer.writeAll(" // ");
@ -50,10 +55,10 @@ pub fn zig(
});
}
if (message) |msg| {
try tty.setColor(writer, .yellow);
try tty.setColor(.yellow);
try writer.print("\n{s}\n", .{msg});
}
try tty.setColor(writer, .reset);
try tty.setColor(.reset);
return error.JetCommonInvalidZigCode;
}