catchorg / Clara

A simple to use, composable, command line parser for C++ 11 and beyond
Boost Software License 1.0
649 stars 67 forks source link

Handle carriage returns in the description text of the command line options #26

Open whatsthecraic opened 6 years ago

whatsthecraic commented 6 years ago

Hi,

in the help screen, when the description contains a carriage return (\n), the library prints it in the middle of the column. This causes the overall content to be misaligned. See the example below:

# ./my_hello_program -h
usage:
  my_hello_program [<arguments> ... ] options

where options are:
  -?, -h, --help                   display usage information
  -e, --experiment <experiment>    The experiment to perform. The possible
                                   choices are:
- option1: Insert <N>
                                   unique elements in the data structure,
                                   then perform <M> look ups of existing
                                   elements. Measure the total insertion &
                                   look up time
- option2:
                                   Create an AB tree with the defined bounds
                                   for the leaves and the inner nodes. Measure
                                   the loading time, the insertion time and
                                   look up time
-
                                   option3: Insert the elements
                                   gradually, by doubling the size of the
                                   data structure, and measure at each step
                                   both the insert & search time
[...]

Note that my intention is that the options, listed below the experiment, should still appear on the rightmost column, the one that contains the description of the parameter `experiment'.

Perhaps does it exist a manner to achieve the intended behaviour without altering the source code of the library?

All the best, Dean

whatsthecraic commented 6 years ago

Hi, I'm attaching below a tentative fix for my use case: patch.txt

philsquared commented 6 years ago

Hi @whatsthecraic - sorry it's take so long to get to this. I'm not sure if the issue you had has been resolved in the meantime, or if I'm just missing what you're issue was in the first place. I've added a couple of tests to try and reproduce issues with newlines in descriptions but they all seem to work ok. Is this still a problem for you? If so would you be able to give me a bit more info?

(see: https://github.com/catchorg/Clara/blob/master/src/ClaraTests.cpp#L456)

whatsthecraic commented 6 years ago

@philsquared yes, it appears to have been fixed by some commit in the meanwhile. My version was v1.0.