diff options
Diffstat (limited to 'src/cmd/sort.zig')
-rw-r--r-- | src/cmd/sort.zig | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/cmd/sort.zig b/src/cmd/sort.zig index 0f73940..79616e9 100644 --- a/src/cmd/sort.zig +++ b/src/cmd/sort.zig @@ -18,18 +18,24 @@ pub const Sort = struct { lines.deinit(); } - // Read input lines - if (ctx.input_source) |source| { - // Read from input redirection - while (try source.readLine(ctx.allocator)) |line| { - try lines.append(line); - } - } else { - // Read from stdin (simplified - just show message) - const msg = "SORT: Use input redirection (< file.txt) to sort file contents\n"; - var writer = ctx.output_writer; - try writer.write(msg); - return CommandStatus{ .Code = 0 }; + // Read input lines from unified input reader + var reader = ctx.input_reader; + + // Check if we're reading from stdin vs file redirection for DOS-authentic behavior + switch (ctx.input_reader) { + .stdin => { + // Reading from interactive stdin - show usage message (DOS behavior) + const msg = "SORT: Use input redirection (< file.txt) to sort file contents\n"; + var writer = ctx.output_writer; + try writer.write(msg); + return CommandStatus{ .Code = 0 }; + }, + .source => { + // Read from input redirection + while (try reader.readLine(ctx.allocator)) |line| { + try lines.append(line); + } + }, } // Sort the lines |