Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost Program Options: Description too wide for terminal

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?

like image 493
phimuemue Avatar asked Jun 05 '13 09:06

phimuemue


1 Answers

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.

like image 170
Jesse Good Avatar answered Sep 30 '22 00:09

Jesse Good