diff options
| author | aver-d <aver-d@users.noreply.github.com> | 2018-02-25 00:56:33 +0000 |
|---|---|---|
| committer | aver-d <aver-d@users.noreply.github.com> | 2018-02-25 01:46:50 +0000 |
| commit | f43635c4df7ca91eb46538acd5e84ed19b203bf5 (patch) | |
| tree | 05abdcd623bd918a3c5576d421b7fb5536b46854 /src/parameters_parser.cc | |
| parent | 9bd9fecb53c51733e4addedcc9f635891ec6c2f7 (diff) | |
Ease reading of command-line options
This change displays command-line options in grid format. Each
parameter is indented with two spaces and then padded to maintain
vertical alignment of each description.
I think the visual spacing makes the options much easier to
read. This is particularly important for people new to Kakoune who
use `-help` as a way to become familiar with the program.
Diffstat (limited to 'src/parameters_parser.cc')
| -rw-r--r-- | src/parameters_parser.cc | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc index 30e2c346..d434a201 100644 --- a/src/parameters_parser.cc +++ b/src/parameters_parser.cc @@ -7,11 +7,26 @@ namespace Kakoune String generate_switches_doc(const SwitchMap& switches) { + Vector<int> lengths(switches.size()); + int i = 0; + for (auto& sw : switches) { + lengths[i++] = (int)sw.key.length() + (sw.value.takes_arg ? 5: 0); + } + int maxlen = *std::max_element(lengths.begin(), lengths.end()); + String res; - for (auto& sw : switches) - res += format("-{} {}: {}\n", sw.key, + i = 0; + for (auto& sw : switches) { + int len = lengths[i++]; + String pad = " "; + while (len++ < maxlen) + pad += ' '; + res += format(" -{} {}{}{}\n", + sw.key, sw.value.takes_arg ? "<arg>" : "", + pad, sw.value.description); + } return res; } |
