summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-02-28 15:17:51 +1100
committerMaxime Coste <mawww@kakoune.org>2018-02-28 15:32:11 +1100
commit44a5082aafc055086f6001c16a4265e4610f8d2e (patch)
tree611e0031a94fd5a39b62e7cf463dadf9d73fbf86
parenta6fd70c456935b47230b4de297e67d9e02bc85bc (diff)
Commands: Refactor generate_switches_doc
-rw-r--r--src/parameters_parser.cc21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc
index 7638c246..a4456db4 100644
--- a/src/parameters_parser.cc
+++ b/src/parameters_parser.cc
@@ -7,24 +7,19 @@ 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;
- i = 0;
+ if (switches.empty())
+ return res;
+
+ auto switch_len = [](auto& sw) { return sw.key.column_length() + (sw.value.takes_arg ? 5 : 0); };
+ auto switches_len = switches | transform(switch_len);
+ const ColumnCount maxlen = *std::max_element(switches_len.begin(), switches_len.end());
+
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,
+ String{' ', maxlen - switch_len(sw) + 1},
sw.value.description);
}
return res;