Skip to content

Commit

Permalink
Correctly print options with multi line help messages
Browse files Browse the repository at this point in the history
closes #41
  • Loading branch information
sam701 committed Oct 13, 2024
1 parent 7fce6a3 commit ac82640
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/simple.zig
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn parseArgs() cli.AppRunner.Error!cli.ExecFn {
},
.{
.long_name = "int",
.help = "this is an int",
.help = "this is an int\nwith the second line",
.value_ref = r.mkRef(&config.int),
},
.{
Expand Down
2 changes: 1 addition & 1 deletion src/Printer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub inline fn write(self: *const Self, text: []const u8) void {
_ = self.out.write(text) catch unreachable;
}

pub inline fn printNewLine(self: *Self) void {
pub inline fn printNewLine(self: *const Self) void {
self.write("\n");
}

Expand Down
12 changes: 10 additions & 2 deletions src/help.zig
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,16 @@ const HelpPrinter = struct {
self.printer.printColor(color_clear);
width += option.value_name.len + 3;
}
self.printer.printSpaces(option_column_width - width);

self.printer.format("{s}\n", .{option.help});
// print option help
self.printer.printSpaces(option_column_width - width);
var it = std.mem.splitScalar(u8, option.help, '\n');
var lineNo: usize = 0;
while (it.next()) |line| : (lineNo += 1) {
if (lineNo > 0) {
self.printer.printSpaces(option_column_width + 8);
}
self.printer.format("{s}\n", .{line});
}
}
};

0 comments on commit ac82640

Please sign in to comment.