const std = @import("std"); const Allocator = std.mem.Allocator; const print = std.debug.print; const types = @import("./types.zig"); const CommandStatus = types.CommandStatus; const OutputCapture = types.OutputCapture; const InputSource = types.InputSource; pub const EchoOff = struct { pub fn eval(echo_off: EchoOff, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { _ = echo_off; _ = allocator; _ = output_capture; _ = input_source; return CommandStatus{ .Code = 0 }; } }; pub const EchoOn = struct { pub fn eval(echo_on: EchoOn, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { _ = echo_on; _ = allocator; _ = input_source; const output = "ECHO is on\n"; if (output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); } return CommandStatus{ .Code = 0 }; } }; pub const EchoPlain = struct { pub fn eval(echo_plain: EchoPlain, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { _ = echo_plain; _ = allocator; _ = input_source; const output = "ECHO is on\n"; if (output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); } return CommandStatus{ .Code = 0 }; } }; pub const EchoText = struct { message: []const u8, pub fn eval(echo_text: EchoText, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { _ = input_source; const output = try std.fmt.allocPrint(allocator, "{s}\n", .{echo_text.message}); defer allocator.free(output); if (output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); } return CommandStatus{ .Code = 0 }; } };