I'm trying to create a simple wrapper around console io, but having issues with determining how to create fields for the respective writers and readers of stdout and stdin. Maybe I'm going about this entirely wrong?
main.zig
const std = @import("std");
const Screen = @import("screen.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
const screen: Screen = Screen.init(alloc);
_ = screen;
}
screen.zig
const std = @import("std");
const Self = @This();
alloc: std.mem.Allocator,
stdout: std.fs.File,
buffWriter: std.io.bufferedWriter,
writer: std.io.Writer,
stdin: std.fs.File,
readBuffer: std.ArrayList(u8),
buffReader: std.io.BufferedReader,
reader: std.io.Reader,
pub fn init(self: *Self, alloc: std.mem.Allocator) !void {
self.alloc = alloc;
// Handle to the standard output
self.stdout = std.io.getStdOut();
self.buffWriter = std.io.bufferedWriter(self.sdout.writer());
self.writer = self.buffWriter.writer();
// Handle to the standard input
self.stdin = std.io.getStdIn();
self.readBuffer = std.ArrayList(u8).init(self.alloc, 4098);
self.buffReader = std.io.bufferedReader(self.stdin.reader());
self.reader = self.readBuffer.reader();
}
pub fn deinit(self: *Self) void {
self.readBuffer.deinit();
}