Hey! I'm working on a terminal manipulation library in Zig called termy, inspired by Rust's Crossterm. It's still early in development, and I'm trying to figure out the API before I get too far into the project.
One thing I'm unsure about is whether terminal operations should work directly, like this:
try termy.setForeground(&writer, .red);
try termy.writeAll(&writer, "Some Error!\n");
try termy.setForeground(&writer, .reset);
Or whether I should use a queue-based approach, similar to crossterm where you queue multiple commands and write them together:
try termy.queue(&writer, .{
termy.style.Fg.Color{ .Red = {} },
termy.style.Print{ .msg = "Some Error!\n" },
termy.style.Fg.Color{ .Reset = {} },
});
try writer.flush();
I'm not sure which approach makes more sense in terms of performance and usability, or which feels more natural to use in Zig. I love how the data-oriented approach looks, but I think it may affect performance.
I'd appreciate some feedback!
- Which approach would you prefer, and why?
- Would it make sense to support both?
- Are there any common mistakes I should avoid when designing a Zig library?
- What features would make you choose
termy over other terminal libraries?
I'm still working on the fundamentals, so I'd rather get the design right now than have to change everything later.