summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-05-03 16:36:22 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2020-05-03 16:36:22 +0200
commit9ff20ef857429619267e3f156a4f81ad9e1eb8c1 (patch)
tree0c0ec72db743b8834627ded8ba13a075835c1a57
parent8be4b0a532bc385a32457bff1bfd4e6070dc02f7 (diff)
Improve help printouts.HEADmaster
-rw-r--r--getoptpp.hpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/getoptpp.hpp b/getoptpp.hpp
index a363750..92f8e82 100644
--- a/getoptpp.hpp
+++ b/getoptpp.hpp
@@ -108,14 +108,8 @@ class Options {
const std::vector<std::string> arguments() const { return args; }
void help() {
- std::size_t width = 0;
- for(auto const & opt : options) {
- if(opt.name == nullptr) {
- continue; // skip terminating option
- }
- width = std::max(width, std::strlen(opt.name) + (opt.has_arg != no_argument ? 0 : 3));
- }
- width += 1;
+ std::size_t width = 26;
+ std::size_t column_width = 80;
int index = 0;
for(auto const & help_text : help_texts) {
@@ -136,19 +130,43 @@ class Options {
break;
}
+ std::string option_str;
+ if(opt.val >= '!' && opt.val <= '~')
+ {
+ option_str = " -" + std::string(1, opt.val) + ", --" + opt.name + " " + args;
+ }
+ else
+ {
+ option_str = " --" + std::string(opt.name) + " " + args;
+ }
+
std::string padding;
- std::size_t pad_size = width - (std::strlen(opt.name) + args.size());
- padding.append(pad_size, ' ');
- if(opt.val >= 33 && opt.val <= 126)
+ if(option_str.size() < width)
{
- std::cout << " -" << static_cast<char>(opt.val) << ", --" << opt.name << " " << args << padding;
+ padding.append(width - option_str.size(), ' ');
}
else
{
- std::cout << " --" << opt.name << " " << args << padding;
+ padding = "\n";
+ padding.append(width, ' ');
}
- std::cout << help_text << std::endl;
+ std::cout << option_str << padding;
+
+ auto i = width;
+ for(auto c : help_text)
+ {
+ if((c == '\n') || (i > column_width && (c == ' ' || c == '\t')))
+ {
+ std::string padding(width, ' ');
+ std::cout << '\n' << padding;
+ i = width;
+ continue;
+ }
+ std::cout << c;
+ ++i;
+ }
+ std::cout << '\n';
++index;
}
}