summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-27 04:22:15 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-27 04:31:08 +0200
commit021bc214a3a6a1c220b4f09d3d4bf1ce980a0efa (patch)
treece850596ea3d4ceb375dfcaa4a22a0aff8dc3e26
parent23efe3bfdffbc24254d0b539241ecaf120814480 (diff)
downloadnncmpp-021bc214a3a6a1c220b4f09d3d4bf1ce980a0efa.tar.gz
nncmpp-021bc214a3a6a1c220b4f09d3d4bf1ce980a0efa.tar.xz
nncmpp-021bc214a3a6a1c220b4f09d3d4bf1ce980a0efa.zip
Improve the Help tab
There are now up to three bindings per action by default, so grouping is desirable. We can even follow the more or less logical order given by enumeration values. It should be much easier to find what you need.
-rw-r--r--nncmpp.c70
1 files changed, 51 insertions, 19 deletions
diff --git a/nncmpp.c b/nncmpp.c
index 2f6ed0b..1deb23e 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -3030,40 +3030,72 @@ info_tab_init (void)
// --- Help tab ----------------------------------------------------------------
-static void
-help_tab_on_item_draw (size_t item_index, struct row_buffer *buffer, int width)
-{
- (void) width;
-
- // TODO: group them the other way around for clarity
- // - go through 0..ACTION_COUNT
- // - ...
-
- hard_assert (item_index < g_normal_keys_len);
- struct binding *binding = &g_normal_keys[item_index];
+static struct strv g_help_tab_lines;
+static size_t
+help_tab_strfkey (const termo_key_t *key, char *buf, size_t len)
+{
// For display purposes, this is highly desirable
int flags = termo_get_flags (g.tk);
termo_set_flags (g.tk, flags | TERMO_FLAG_SPACESYMBOL);
- termo_key_t key = binding->decoded;
- termo_canonicalise (g.tk, &key);
+ termo_key_t fixed = *key;
+ termo_canonicalise (g.tk, &fixed);
termo_set_flags (g.tk, flags);
+ return termo_strfkey_utf8 (g.tk, buf, len, &fixed, TERMO_FORMAT_ALTISMETA);
+}
+static void
+help_tab_group (struct binding *keys, size_t len, struct strv *out)
+{
char buf[16];
- termo_strfkey_utf8 (g.tk, buf, sizeof buf, &key, TERMO_FORMAT_ALTISMETA);
- char *text = xstrdup_printf ("%-12s %s",
- buf, g_actions[binding->action].description);
- row_buffer_append (buffer, text, 0);
- free (text);
+ for (enum action i = 0; i < ACTION_COUNT; i++)
+ {
+ struct strv ass = strv_make ();
+ for (size_t k = 0; k < len; k++)
+ {
+ if (keys[k].action != i)
+ continue;
+ help_tab_strfkey (&keys[k].decoded, buf, sizeof buf);
+ strv_append (&ass, buf);
+ }
+ if (ass.len)
+ {
+ char *joined = strv_join (&ass, ", ");
+ strv_append_owned (out, xstrdup_printf
+ (" %-30s %s", g_actions[i].description, joined));
+ free (joined);
+ }
+ strv_free (&ass);
+ }
+}
+
+static void
+help_tab_on_item_draw (size_t item_index, struct row_buffer *buffer, int width)
+{
+ (void) width;
+
+ hard_assert (item_index < g_help_tab_lines.len);
+ const char *line = g_help_tab_lines.vector[item_index];
+ row_buffer_append (buffer, line, *line == ' ' ? 0 : A_BOLD);
}
static struct tab *
help_tab_init (void)
{
+ g_help_tab_lines = strv_make ();
+
+ strv_append (&g_help_tab_lines, "Normal mode actions");
+ help_tab_group (g_normal_keys, g_normal_keys_len, &g_help_tab_lines);
+ strv_append (&g_help_tab_lines, "");
+
+ strv_append (&g_help_tab_lines, "Editor mode actions");
+ help_tab_group (g_editor_keys, g_editor_keys_len, &g_help_tab_lines);
+ strv_append (&g_help_tab_lines, "");
+
static struct tab super;
tab_init (&super, "Help");
super.on_item_draw = help_tab_on_item_draw;
- super.item_count = g_normal_keys_len;
+ super.item_count = g_help_tab_lines.len;
return &super;
}