diff options
Diffstat (limited to 'src/cmd/dir.zig')
-rw-r--r-- | src/cmd/dir.zig | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/cmd/dir.zig b/src/cmd/dir.zig index 04f74dc..96c6319 100644 --- a/src/cmd/dir.zig +++ b/src/cmd/dir.zig @@ -120,8 +120,8 @@ pub const Dir = struct { subdirs: bool = false, // /s flag pub fn eval(dir: Dir, ctx: CommandContext) !CommandStatus { - var output_buffer = ArrayList(u8).init(ctx.allocator); - defer output_buffer.deinit(); + var output_buffer = ArrayList(u8){}; + defer output_buffer.deinit(ctx.allocator); // Format path in DOS style with backslashes and uppercase drive letter const formatted_path = try formatDosPath(ctx.allocator, dir.path); @@ -134,9 +134,9 @@ pub const Dir = struct { formatted_path[0] else 'C'; - try output_buffer.writer().print(" Volume in drive {c} has no label\n", .{drive_letter}); - try output_buffer.writer().print(" Volume Serial Number is 1234-5678\n", .{}); - try output_buffer.writer().print("\n Directory of {s}\n\n", .{formatted_path}); + try output_buffer.writer(ctx.allocator).print(" Volume in drive {c} has no label\n", .{drive_letter}); + try output_buffer.writer(ctx.allocator).print(" Volume Serial Number is 1234-5678\n", .{}); + try output_buffer.writer(ctx.allocator).print("\n Directory of {s}\n\n", .{formatted_path}); } var dir_iterator = std.fs.cwd().openDir(dir.path, .{ .iterate = true }) catch { @@ -172,23 +172,23 @@ pub const Dir = struct { switch (entry.kind) { .directory => { if (dir.bare_format) { - try output_buffer.writer().print("{s}\n", .{entry.name}); + try output_buffer.writer(ctx.allocator).print("{s}\n", .{entry.name}); } else if (dir.wide_format) { - try output_buffer.writer().print("{s:<12} ", .{entry.name}); + try output_buffer.writer(ctx.allocator).print("{s:<12} ", .{entry.name}); } else { - try output_buffer.writer().print("{s:<8} {s:<3} <DIR> {s}\n", .{ name, ext, date_time }); + try output_buffer.writer(ctx.allocator).print("{s:<8} {s:<3} <DIR> {s}\n", .{ name, ext, date_time }); } dir_count += 1; }, .file => { if (dir.bare_format) { - try output_buffer.writer().print("{s}\n", .{entry.name}); + try output_buffer.writer(ctx.allocator).print("{s}\n", .{entry.name}); } else if (dir.wide_format) { - try output_buffer.writer().print("{s:<12} ", .{entry.name}); + try output_buffer.writer(ctx.allocator).print("{s:<12} ", .{entry.name}); } else { const formatted_size = try formatWithCommas(ctx.allocator, stat.size); defer ctx.allocator.free(formatted_size); - try output_buffer.writer().print("{s:<8} {s:<3} {s:>14} {s}\n", .{ name, ext, formatted_size, date_time }); + try output_buffer.writer(ctx.allocator).print("{s:<8} {s:<3} {s:>14} {s}\n", .{ name, ext, formatted_size, date_time }); } file_count += 1; total_file_bytes += stat.size; @@ -199,7 +199,7 @@ pub const Dir = struct { // Add newline after wide format listing if (dir.wide_format and !dir.bare_format) { - try output_buffer.writer().print("\n", .{}); + try output_buffer.writer(ctx.allocator).print("\n", .{}); } // Only show footer for non-bare format @@ -218,8 +218,8 @@ pub const Dir = struct { const formatted_free_bytes = try formatWithCommas(ctx.allocator, bytes_free); defer ctx.allocator.free(formatted_free_bytes); - try output_buffer.writer().print(" {d} File(s) {s:>14} bytes\n", .{ file_count, formatted_total_bytes }); - try output_buffer.writer().print(" {d} Dir(s) {s:>14} bytes free\n", .{ dir_count, formatted_free_bytes }); + try output_buffer.writer(ctx.allocator).print(" {d} File(s) {s:>14} bytes\n", .{ file_count, formatted_total_bytes }); + try output_buffer.writer(ctx.allocator).print(" {d} Dir(s) {s:>14} bytes free\n", .{ dir_count, formatted_free_bytes }); } var writer = ctx.output_writer; |