mod(terminal): add writer interface implementation

This commit is contained in:
2024-11-11 12:29:33 +01:00
parent 4c67a86c27
commit 53fc34ba69

View File

@@ -55,6 +55,21 @@ pub fn write(buf: []const u8) !usize {
return try std.posix.write(std.posix.STDIN_FILENO, buf);
}
fn contextWrite(context: @This(), data: []const u8) anyerror!usize {
_ = context;
return try std.posix.write(std.posix.STDOUT_FILENO, data);
}
const Writer = std.io.Writer(
@This(),
anyerror,
contextWrite,
);
pub fn writer() Writer {
return .{ .context = .{} };
}
pub fn setCursorPosition(pos: Position) !void {
var buf: [64]u8 = undefined;
const value = try std.fmt.bufPrint(&buf, "\x1b[{d};{d}H", .{ pos.row, pos.col });