Update to Zig 0.15.2
This commit is contained in:
parent
dc6f7e486f
commit
a5c560d2b9
4 changed files with 64 additions and 33 deletions
|
|
@ -20,18 +20,18 @@ pub const ConsoleColor = enum(u8) {
|
|||
red = 4,
|
||||
magenta = 5,
|
||||
brown = 6,
|
||||
lightGray = 7,
|
||||
darkGray = 8,
|
||||
lightBlue = 9,
|
||||
lightGreen = 10,
|
||||
lightCyan = 11,
|
||||
lightRed = 12,
|
||||
lightMagenta = 13,
|
||||
lightBrown = 14,
|
||||
light_gray = 7,
|
||||
dark_gray = 8,
|
||||
light_blue = 9,
|
||||
light_green = 10,
|
||||
light_cyan = 11,
|
||||
light_red = 12,
|
||||
light_magenta = 13,
|
||||
light_brown = 14,
|
||||
white = 15,
|
||||
};
|
||||
|
||||
const default_color = vgaEntryColor(ConsoleColor.lightGray, ConsoleColor.black);
|
||||
const default_color = vgaEntryColor(ConsoleColor.light_gray, ConsoleColor.black);
|
||||
|
||||
column: usize = 0,
|
||||
color: u8 = default_color,
|
||||
|
|
@ -115,21 +115,49 @@ pub fn puts(self: *Self, data: []const u8) void {
|
|||
}
|
||||
}
|
||||
|
||||
const Writer = std.io.Writer(
|
||||
*Self,
|
||||
error{},
|
||||
callback,
|
||||
);
|
||||
const Writer = struct {
|
||||
console: *Self,
|
||||
interface: std.Io.Writer,
|
||||
|
||||
pub fn writer(self: *Self) Writer {
|
||||
return .{ .context = self };
|
||||
}
|
||||
fn drain(io_w: *std.Io.Writer, data: []const []const u8, splat: usize) std.Io.Writer.Error!usize {
|
||||
const self: *@This() = @fieldParentPtr("interface", io_w);
|
||||
|
||||
fn callback(self: *Self, string: []const u8) error{}!usize {
|
||||
self.puts(string);
|
||||
return string.len;
|
||||
try self.puts(io_w.buffered());
|
||||
io_w.end = 0;
|
||||
|
||||
for (data[0..data.len - 1]) |bytes| {
|
||||
try self.puts(bytes);
|
||||
}
|
||||
const pattern = data[data.len - 1];
|
||||
for (0..splat) |_| {
|
||||
try self.puts(pattern);
|
||||
}
|
||||
|
||||
return std.Io.Writer.countSplat(data, splat);
|
||||
}
|
||||
|
||||
fn puts(self: *@This(), data: []const u8) std.Io.Writer.Error!void {
|
||||
self.console.puts(data);
|
||||
}
|
||||
};
|
||||
|
||||
pub fn writer(self: *Self, buffer: []u8) Writer {
|
||||
return .{
|
||||
.console = self,
|
||||
.interface = .{
|
||||
.buffer = buffer,
|
||||
.vtable = &.{
|
||||
.drain = Writer.drain,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn printf(self: *Self, comptime format: []const u8, args: anytype) void {
|
||||
std.fmt.format(self.writer(), format, args) catch unreachable;
|
||||
var buffer: [1024]u8 = undefined;
|
||||
var w = self.writer(&buffer);
|
||||
const io_w = &w.interface;
|
||||
io_w.print(format, args) catch unreachable;
|
||||
io_w.flush() catch unreachable;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue