| ... | @@ -43,6 +43,7 @@ fn clean(out: anytype, n: usize) !void { | ... | @@ -43,6 +43,7 @@ fn clean(out: anytype, n: usize) !void { |
| 43 | | 43 | |
| 44 | pub fn forEnum(out: anytype, in: anytype, comptime prompt: []const u8, alloc: *std.mem.Allocator, comptime options: type, default: ?options) !options { | 44 | pub fn forEnum(out: anytype, in: anytype, comptime prompt: []const u8, alloc: *std.mem.Allocator, comptime options: type, default: ?options) !options { |
| 45 | comptime std.debug.assert(@typeInfo(options) == .Enum); | 45 | comptime std.debug.assert(@typeInfo(options) == .Enum); |
| | 46 | const def: ?[]const u8 = if (default) |d| @tagName(d) else null; |
| 46 | | 47 | |
| 47 | try out.print(comptime ansi.color.Fg(.Green, "? "), .{}); | 48 | try out.print(comptime ansi.color.Fg(.Green, "? "), .{}); |
| 48 | try out.print(comptime ansi.color.Bold(prompt ++ " "), .{}); | 49 | try out.print(comptime ansi.color.Bold(prompt ++ " "), .{}); |
| ... | @@ -50,14 +51,17 @@ pub fn forEnum(out: anytype, in: anytype, comptime prompt: []const u8, alloc: *s | ... | @@ -50,14 +51,17 @@ pub fn forEnum(out: anytype, in: anytype, comptime prompt: []const u8, alloc: *s |
| 50 | try out.print(ansi.style.Faint ++ "(", .{}); | 51 | try out.print(ansi.style.Faint ++ "(", .{}); |
| 51 | inline for (std.meta.fields(options)) |f, i| { | 52 | inline for (std.meta.fields(options)) |f, i| { |
| 52 | if (i != 0) try out.print("/", .{}); | 53 | if (i != 0) try out.print("/", .{}); |
| 53 | try out.print(f.name, .{}); | 54 | if (std.mem.eql(u8, f.name, def orelse "")) { |
| | 55 | try out.print(ansi.style.ResetIntensity, .{}); |
| | 56 | try out.print(comptime ansi.color.Fg(.Cyan, f.name), .{}); |
| | 57 | try out.print(ansi.style.Faint, .{}); |
| | 58 | } else try out.print(f.name, .{}); |
| 54 | } | 59 | } |
| 55 | try out.print(")" ++ ansi.style.ResetIntensity ++ " ", .{}); | 60 | try out.print(")" ++ ansi.style.ResetIntensity ++ " ", .{}); |
| 56 | | 61 | |
| 57 | var value: options = undefined; | 62 | var value: options = undefined; |
| 58 | var i: usize = 0; | 63 | var i: usize = 0; |
| 59 | while (true) { | 64 | while (true) { |
| 60 | const def: ?[]const u8 = if (default) |d| @tagName(d) else null; | | |
| 61 | const p = try doprompt(out, in, alloc, def); | 65 | const p = try doprompt(out, in, alloc, def); |
| 62 | defer if (!std.mem.eql(u8, p.value, def orelse "")) alloc.free(p.value); | 66 | defer if (!std.mem.eql(u8, p.value, def orelse "")) alloc.free(p.value); |
| 63 | | 67 | |