chor: use new Writer interface for terminal's Writer; fix test cases
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 3m38s

This commit is contained in:
2025-10-01 10:59:29 +02:00
parent aa17e13b99
commit 832fc45c3e
6 changed files with 46 additions and 44 deletions

View File

@@ -62,17 +62,24 @@ pub fn write(buf: []const u8) !usize {
return try posix.write(posix.STDIN_FILENO, buf);
}
fn contextWrite(context: *const anyopaque, data: []const u8) anyerror!usize {
_ = context;
return try posix.write(posix.STDOUT_FILENO, data);
fn drainFn(w: *std.Io.Writer, data: []const []const u8, splat: usize) error{WriteFailed}!usize {
_ = w;
if (data.len == 0 or splat == 0) return 0;
var len: usize = 0;
for (data) |bytes| len += posix.write(posix.STDOUT_FILENO, bytes) catch return error.WriteFailed;
return len;
}
const Writer = std.io.AnyWriter;
pub fn writer() Writer {
// TODO I now need to add that much, for just the one function above?
pub fn writer() std.Io.Writer {
return .{
.context = &.{},
.writeFn = contextWrite,
.vtable = &.{
.drain = drainFn,
.flush = std.Io.Writer.noopFlush,
},
.buffer = &.{},
};
}
@@ -231,6 +238,7 @@ const log = std.log.scoped(.terminal);
const std = @import("std");
const mem = std.mem;
const posix = std.posix;
const assert = std.debug.assert;
const ctlseqs = @import("ctlseqs.zig");
const input = @import("input.zig");
const Key = input.Key;