From 9edc1338b92d1ead4c5f2fad8c0516037963f7b6 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 16 Aug 2025 12:50:23 +0200 Subject: Unify output handling. Now every command always uses an OutputWriter instead of conditionally writing directly to stdout using std.debug.print. --- src/cmd/path.zig | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src/cmd/path.zig') diff --git a/src/cmd/path.zig b/src/cmd/path.zig index ca4de9a..009621f 100644 --- a/src/cmd/path.zig +++ b/src/cmd/path.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; @@ -15,20 +14,14 @@ pub const PathGet = struct { error.EnvironmentVariableNotFound => { // PATH not set, show empty const output = "PATH=(not set)\n"; - if (ctx.output_capture) |capture| { - try capture.write(output); - } else { - print("{s}", .{output}); - } + var writer = ctx.output_writer; + try writer.write(output); return CommandStatus{ .Code = 0 }; }, else => { const error_msg = "Cannot access PATH environment variable\n"; - if (ctx.output_capture) |capture| { - try capture.write(error_msg); - } else { - print("{s}", .{error_msg}); - } + var writer = ctx.output_writer; + try writer.write(error_msg); return CommandStatus{ .Code = 1 }; }, }; @@ -36,11 +29,8 @@ pub const PathGet = struct { const output = try std.fmt.allocPrint(ctx.allocator, "PATH={s}\n", .{current_path}); defer ctx.allocator.free(output); - if (ctx.output_capture) |capture| { - try capture.write(output); - } else { - print("{s}", .{output}); - } + var writer = ctx.output_writer; + try writer.write(output); return CommandStatus{ .Code = 0 }; } }; @@ -54,11 +44,8 @@ pub const PathSet = struct { // since Zig's std.process doesn't provide a simple way to set env vars const output = try std.fmt.allocPrint(ctx.allocator, "PATH would be set to: {s}\n(Note: Environment variable setting not implemented in this shell)\n", .{path_set.value}); defer ctx.allocator.free(output); - if (ctx.output_capture) |capture| { - try capture.write(output); - } else { - print("{s}", .{output}); - } + var writer = ctx.output_writer; + try writer.write(output); return CommandStatus{ .Code = 0 }; } }; -- cgit v1.2.1