CLI11
CLI11 copied to clipboard
Feature request: Footer formatting and terminal geometry
Hello,
I would like to format footer output using configured width as well as to take into account terminal geometry.
Consider the following example:
$ ./app subcommand --help
SYNOPSIS
subcommand [OPTIONS]
OPTIONS
--option1 TEXT Some description for this option
--flag1 Some description for this flag
--flag2 Some description for this flag
-h,--help Print this help message and quit
DESCRIPTION
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n
sed do eiusmod tempor incididunt ut labore et dolor\n
magna aliqua. Ut enim ad minim veniam, quis nostrud\n
exercitation ullamco laboris nisi ut aliquip ex ea commodo\n
consequat. Duis aute irure dolor in reprehenderit in voluptate\n
velit esse cillum dolore eu fugiat nulla pariatur.\n
Excepteur sint occaecat cupidatat non proident, sunt in culpa\n
qui officia deserunt mollit anim id est laborum.\n
Here DESCRIPTION is the footer text. And right now I forced to split string manually using "\n". I do not want to split the footer string manually. I want pass the whole string to the footer() and not worried about line breaks. I would like to calculate terminal geometry (internally) and set footer width at CLI11 configuring time. Some examples:
app.footer_width(78);
cmd.get_fooler().width(78);
cmd->footer(string, 78);
This is probably an unrelated task, one would be even better if I could align the text to the right border. For example:

I believe the formatter that does the printing is polymorphic so you might be able customize the output to meet the requirements. @henryiii would know more, I haven't used that feature.
Wow, haven't seen fixed width full alignment before. I guess one of the next things to work on is proper docs for the formatter. You can replace parts or the whole. And I'm happy to take improvements to the default. We could also have a library of user submitted formatters, I suppose...
Hi, If you don't mind relying on other library maybe fmt could help https://fmt.dev/latest/syntax.html Aligning the text and specifying a width:
fmt::format("{:<30}", "left aligned");
// Result: "left aligned "
fmt::format("{:>30}", "right aligned");
// Result: " right aligned"
fmt::format("{:^30}", "centered");
// Result: " centered "
fmt::format("{:*^30}", "centered"); // use '*' as a fill char
// Result: "***********centered***********"
Dynamic width:
fmt::format("{:<{}}", "left aligned", 30);
// Result: "left aligned
I very much enjoy the fact that CLI11 does not require external dependencies, please don't make users include fmt. I like the idea of user-submitted formatters though.
Yes I agree I enjoy it too ! But fmt is an header library too i think and it could be included with gitmodule , cmake externalpackage etc... it looks fmt has a quite permissive license maybe some part of the code could be used
I definitely think there should be a helpformatter that does include fmt, but that fmt should not be required to compile cli11. I might get something up and running.