From 4be3fcdb616647215dc162c9e2f64b7d6e3ad09d Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Sun, 5 Sep 2021 13:14:17 -0700 Subject: Indent help text on every new line to allow for user-controlled wrapping --- clap.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'clap.zig') diff --git a/clap.zig b/clap.zig index 5bb3542..b280f70 100644 --- a/clap.zig +++ b/clap.zig @@ -408,7 +408,16 @@ pub fn helpFull( try stream.print("\t", .{}); try printParam(cs.writer(), Id, param, Error, context, valueText); try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, cs.bytes_written)); - try stream.print("\t{s}\n", .{try helpText(context, param)}); + const help_text = try helpText(context, param); + var help_text_line_it = mem.split(help_text, "\n"); + var indent_line = false; + while (help_text_line_it.next()) |line| : (indent_line = true) { + if (indent_line) { + try stream.print("\t", .{}); + try stream.writeByteNTimes(' ', max_spacing); + } + try stream.print("\t{s}\n", .{line}); + } } } @@ -509,6 +518,7 @@ test "clap.help" { parseParam("--aa Long flag.") catch unreachable, parseParam("--bb Long option.") catch unreachable, parseParam("-c, --cc Both flag.") catch unreachable, + parseParam("--complicate Flag with a complicated and\nvery long description that\nspans multiple lines.") catch unreachable, parseParam("-d, --dd Both option.") catch unreachable, parseParam("-d, --dd ... Both repeated option.") catch unreachable, parseParam( @@ -523,6 +533,9 @@ test "clap.help" { "\t --aa \tLong flag.\n" ++ "\t --bb \tLong option.\n" ++ "\t-c, --cc \tBoth flag.\n" ++ + "\t --complicate\tFlag with a complicated and\n" ++ + "\t \tvery long description that\n" ++ + "\t \tspans multiple lines.\n" ++ "\t-d, --dd \tBoth option.\n" ++ "\t-d, --dd ...\tBoth repeated option.\n"; -- cgit v1.2.3