summaryrefslogtreecommitdiff
path: root/src/cmd/cls.zig
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-16 12:50:23 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-16 12:50:23 +0200
commit9edc1338b92d1ead4c5f2fad8c0516037963f7b6 (patch)
tree64f3ed617771f9327bd49e3732adb9271e3559cc /src/cmd/cls.zig
parent754a74da6052c9f5e8dc4a536c58ccc11cb66369 (diff)
Unify output handling.
Now every command always uses an OutputWriter instead of conditionally writing directly to stdout using std.debug.print.
Diffstat (limited to 'src/cmd/cls.zig')
-rw-r--r--src/cmd/cls.zig12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/cmd/cls.zig b/src/cmd/cls.zig
index 4e7b8c6..a017278 100644
--- a/src/cmd/cls.zig
+++ b/src/cmd/cls.zig
@@ -1,6 +1,5 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
-const print = std.debug.print;
const types = @import("./lib/types.zig");
const CommandStatus = types.CommandStatus;
@@ -10,9 +9,14 @@ pub const Cls = struct {
pub fn eval(cls: Cls, ctx: CommandContext) !CommandStatus {
_ = cls;
- if (ctx.output_capture == null) {
- // Clear screen - only works when not redirected
- print("\x1B[2J\x1B[H", .{});
+ // Clear screen - only works when going to stdout, not when redirected
+ switch (ctx.output_writer) {
+ .stdout => |writer| {
+ try writer.write("\x1B[2J\x1B[H");
+ },
+ .capture => {
+ // Do nothing when output is captured/redirected
+ },
}
return CommandStatus{ .Code = 0 };
}