Boost Program Options: Description too wide for terminal
Asked Answered
C

1

6

I am using Boost Program Options to parse command line arguments (and I don't want to miss it since it works great). However, I have one problem: Boost program options offer the possibility to assign a description to each option. Boost then offers the possibility to

cout << program_options_description << endl

to nicely display help explaining the options. However, it seems to be the case that these error messages are adjusted to a terminal width of 80 (I conclude this from the fact that for a width of 80, the line breaks are nicely set).

If my current terminal has another width (in particular one that has less than 80 columns), the displayed help looks very unnatural due to automatic line breaks done by the terminal.

So: Is there a possibility that Boost automatically adjusts the option descriptions to the current terminal width?

Czarevna answered 5/6, 2013 at 9:11 Comment(0)
W
13

The options_description accepts the column width as a parameter.

options_description(const std::string &, unsigned = m_default_line_length, 
                      unsigned = m_default_line_length/2);

I believe the default is 80 for m_default_line_length. Also, see this SO question to get the terminal width on linux and then pass that to the constructor. Or if you are windows, you would want to call GetConsoleScreenBufferInfo.

Wellworn answered 5/6, 2013 at 9:26 Comment(1)
see this SO post for this full Windows code.Metalepsis

© 2022 - 2024 — McMap. All rights reserved.