mod(terminal): add writer interface implementation
This commit is contained in:
@@ -55,6 +55,21 @@ pub fn write(buf: []const u8) !usize {
|
|||||||
return try std.posix.write(std.posix.STDIN_FILENO, buf);
|
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 {
|
pub fn setCursorPosition(pos: Position) !void {
|
||||||
var buf: [64]u8 = undefined;
|
var buf: [64]u8 = undefined;
|
||||||
const value = try std.fmt.bufPrint(&buf, "\x1b[{d};{d}H", .{ pos.row, pos.col });
|
const value = try std.fmt.bufPrint(&buf, "\x1b[{d};{d}H", .{ pos.row, pos.col });
|
||||||
|
|||||||
Reference in New Issue
Block a user