CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

Feature request: Footer formatting and terminal geometry

Open sergeyklay opened this issue 6 years ago • 6 comments

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: image

sergeyklay avatar Nov 30 '19 09:11 sergeyklay

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.

phlptp avatar Dec 03 '19 05:12 phlptp

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...

henryiii avatar Dec 17 '19 14:12 henryiii

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     

flagarde avatar Jul 22 '20 11:07 flagarde

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.

jakoblover avatar Jul 22 '20 11:07 jakoblover

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

flagarde avatar Jul 22 '20 11:07 flagarde

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.

jakoblover avatar Jun 17 '22 12:06 jakoblover