feature. See also
. The project being documented here (as the example) is the Zig library itself.
cli.Diagnostics
pub const Diagnostics = struct
File
Code
pub const Diagnostics = struct {
errors: std.ArrayList(ErrorDetails) = .empty,
allocator: Allocator,
pub const ErrorDetails = struct {
arg_index: usize,
arg_span: ArgSpan = .{},
msg: std.ArrayList(u8) = .empty,
type: Type = .err,
print_args: bool = true,
pub const Type = enum { err, warning, note };
pub const ArgSpan = struct {
point_at_next_arg: bool = false,
name_offset: usize = 0,
prefix_len: usize = 0,
value_offset: usize = 0,
name_len: usize = 0,
};
};
pub fn init(allocator: Allocator) Diagnostics {
return .{
.allocator = allocator,
};
}
pub fn deinit(self: *Diagnostics) void {
for (self.errors.items) |*details| {
details.msg.deinit(self.allocator);
}
self.errors.deinit(self.allocator);
}
pub fn append(self: *Diagnostics, error_details: ErrorDetails) !void {
try self.errors.append(self.allocator, error_details);
}
pub fn renderToStderr(self: *Diagnostics, io: Io, args: []const []const u8) Io.Cancelable!void {
const stderr = try io.lockStderr(&.{}, null);
defer io.unlockStderr();
self.renderToTerminal(stderr.terminal(), args) catch return;
}
pub fn renderToTerminal(self: *Diagnostics, terminal: Io.Terminal, args: []const []const u8) !void {
for (self.errors.items) |err_details| {
try renderErrorMessage(terminal, err_details, args);
}
}
pub fn renderToWriter(self: *Diagnostics, writer: *Io.Writer, args: []const []const u8) !void {
return self.renderToTerminal(.{ .writer = writer, .mode = .no_color }, args);
}
pub fn hasError(self: *const Diagnostics) bool {
for (self.errors.items) |err| {
if (err.type == .err) return true;
}
return false;
}
}