authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-14 04:47:26 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-14 04:47:26 -07:00
log686b598e608c15fe86f871113c0fd7f47fab9d26
treea7c23febc83bd6480d23d740c7ea0ac25c389931
parent48aabfe1b35f06dedf4e1c86cbe338067b873618
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add some nprint impls


1 files changed, 25 insertions(+), 3 deletions(-)

git.zig+25-3
......@@ -415,12 +415,18 @@ pub const Tree = struct {
415415 pub fn format(self: Mode, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) !void {
416416 _ = fmt;
417417 _ = options;
418
419418 try writer.print("{}", .{self.type});
420419 try writer.print("{}", .{self.perm_user});
421420 try writer.print("{}", .{self.perm_group});
422421 try writer.print("{}", .{self.perm_other});
423422 }
423
424 pub fn nprint(self: Mode, writer: anytype) !void {
425 try self.type.nprint(writer);
426 try self.perm_user.nprint(writer);
427 try self.perm_group.nprint(writer);
428 try self.perm_other.nprint(writer);
429 }
424430 };
425431
426432 pub const Type = enum(u16) {
......@@ -433,7 +439,6 @@ pub const Tree = struct {
433439 pub fn format(self: Type, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) !void {
434440 _ = fmt;
435441 _ = options;
436
437442 try writer.writeByte(switch (self) {
438443 .file => '-',
439444 .directory => 'd',
......@@ -442,6 +447,16 @@ pub const Tree = struct {
442447 .none => '-',
443448 });
444449 }
450
451 pub fn nprint(self: Type, writer: anytype) !void {
452 try writer.writeAll(&.{switch (self) {
453 .file => '-',
454 .directory => 'd',
455 .submodule => 'm',
456 .symlink => '-',
457 .none => '-',
458 }});
459 }
445460 };
446461
447462 pub const Perm = packed struct(u3) {
......@@ -452,11 +467,18 @@ pub const Tree = struct {
452467 pub fn format(self: Perm, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) !void {
453468 _ = fmt;
454469 _ = options;
455
456470 try writer.writeByte(if (self.read) 'r' else '-');
457471 try writer.writeByte(if (self.write) 'w' else '-');
458472 try writer.writeByte(if (self.execute) 'x' else '-');
459473 }
474
475 pub fn nprint(self: Perm, writer: anytype) !void {
476 try writer.writeAll(&.{
477 if (self.read) 'r' else '-',
478 if (self.write) 'w' else '-',
479 if (self.execute) 'x' else '-',
480 });
481 }
460482 };
461483 };
462484};