From ac82640e750efb3b89c609032bdec0898739a790 Mon Sep 17 00:00:00 2001 From: Alexei Samokvalov Date: Sun, 13 Oct 2024 22:44:35 +0200 Subject: [PATCH] Correctly print options with multi line help messages closes #41 --- examples/simple.zig | 2 +- src/Printer.zig | 2 +- src/help.zig | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/simple.zig b/examples/simple.zig index 24eee50..86a15b3 100644 --- a/examples/simple.zig +++ b/examples/simple.zig @@ -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), }, .{ diff --git a/src/Printer.zig b/src/Printer.zig index a3f6aa4..7e005f0 100644 --- a/src/Printer.zig +++ b/src/Printer.zig @@ -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"); } diff --git a/src/help.zig b/src/help.zig index deb54e6..5f19dfb 100644 --- a/src/help.zig +++ b/src/help.zig @@ -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}); + } } };