summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c103d47)
raw | patch | inline | side by side (parent: c103d47)
author | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Sat, 24 Dec 2011 17:28:06 +0000 (18:28 +0100) | ||
committer | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Sat, 24 Dec 2011 17:28:06 +0000 (18:28 +0100) |
NEWS | patch | blob | history | |
src/command.c | patch | blob | history | |
src/command.h | patch | blob | history | |
src/screen_keydef.c | patch | blob | history |
index 5ca49b188d05d4f63b72cda0ab995ae96e7d6d71..f435e1ce05bfd1f7a835925dd7ef3981bd40fc59 100644 (file)
--- a/NEWS
+++ b/NEWS
configure script is called with --enable-documentation
* screen_lyrics: You can now edit lyrics by pressing 'e'
* configurable timeout for MPD connections
+* screen_keydef: show command descriptions
ncmpc 0.19 - (07/23/2011)
diff --git a/src/command.c b/src/command.c
index 656bb18e389db0bd89a1389be818a861d2a7a3e1..85e499a00873ad2c985dbfbb1241c26b7b1006f2 100644 (file)
--- a/src/command.c
+++ b/src/command.c
{
return cmds;
}
+
+size_t
+get_cmds_max_name_width(command_definition_t *c)
+{
+ static size_t max = 0;
+
+ if (max != 0)
+ return max;
+
+ size_t len;
+ command_definition_t *p;
+
+ for (p = c; p->name != NULL; p++) {
+ /*
+ * width and length are considered the same here, as command
+ * names are not translated.
+ */
+ len = (size_t) strlen(p->name);
+ if (len > max)
+ max = len;
+ }
+
+ return max;
+}
#endif
const char *
diff --git a/src/command.h b/src/command.h
index 225d76e5fb4bfa5e4a7c00a9ea26eaf6a89d4083..847d5ed7c22c2edf466fc6b58da11897c484ce96 100644 (file)
--- a/src/command.h
+++ b/src/command.h
#ifdef ENABLE_KEYDEF_SCREEN
command_definition_t *get_command_definitions(void);
+size_t get_cmds_max_name_width(command_definition_t *cmds);
#endif
command_t find_key_command(int key, command_definition_t *cmds);
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index 8174c0426e3a0f4c582a0e8edbdcb0b3c65804ca..22797eab10b8c5bd83b257db9c3cfaa8059960a9 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
assert(idx < (unsigned) command_n_commands);
- return cmds[idx].name;
+ /*
+ * Format the lines in two aligned columnes for the key name and
+ * the description, like this:
+ *
+ * this-command - do this
+ * that-one - do that
+ */
+ size_t len = strlen(cmds[idx].name);
+ strncpy(buf, cmds[idx].name, sizeof(buf));
+
+ if (len < get_cmds_max_name_width(cmds))
+ memset(buf + len, ' ', get_cmds_max_name_width(cmds) - len);
+
+ g_snprintf(buf + get_cmds_max_name_width(cmds),
+ sizeof(buf) - get_cmds_max_name_width(cmds),
+ " - %s", _(cmds[idx].description));
+
+ return buf;
} else {
if (idx == subcmd_item_up)
return "[..]";