argtable / argtable3

A single-file, ANSI C, command-line parsing library that parses GNU-style command-line options.
http://www.argtable.org
Other
372 stars 65 forks source link

arg_print_formatted_ds does not reset column count when reaching newline #76

Closed ph2355 closed 1 year ago

ph2355 commented 1 year ago

I was redirected here from this issue: https://github.com/espressif/esp-idf/issues/9907

I want to insert some newlines in my text, which the function does print, but doesn't reset the column count when encountering a newline. This results in line wrap to print a newline before reaching 80 characters in that line (or whatever number of characters line wrap is set to). Consequently I get an ugly print for which an example is provided in the above mentioned issue.

Basically this is a feature request to reset column count upon reaching a newline.

tomghuang commented 1 year ago

Hi @ph2355 ,

If you want to split the long lines in your own way, you should use the arg_rem function. For example, in the ls.c example, you can see the following code snippet:

timesty = arg_str0(NULL, "time-style","STYLE", "show times using style STYLE:"),
          arg_rem (NULL,                       "  full-iso, long-iso, iso, locale, +FORMAT"),
          arg_rem (NULL,                       "FORMAT is interpreted like `date'; if FORMAT is"),
          arg_rem (NULL,                       "FORMAT1<newline>FORMAT2, FORMAT1 applies to"),
          arg_rem (NULL,                       "non-recent files and FORMAT2 to recent files;"),
          arg_rem (NULL,                       "if STYLE is prefixed with `posix-', STYLE"),
          arg_rem (NULL,                       "takes effect only outside the POSIX locale"),

When you run ./ls --help, you will see the following output:

  --time-style=STYLE        show times using style STYLE:
                              full-iso, long-iso, iso, locale, +FORMAT
                            FORMAT is interpreted like `date'; if FORMAT is
                            FORMAT1<newline>FORMAT2, FORMAT1 applies to
                            non-recent files and FORMAT2 to recent files;
                            if STYLE is prefixed with `posix-', STYLE
                            takes effect only outside the POSIX locale
ph2355 commented 1 year ago

Great, thanks.