Code

*: add "pure" attributes
[ncmpc.git] / src / command.c
index af6afd15a01ee7e93ab01a31e72cfa6a4f301e2d..5621b165650b34fd2197b846755ee3c3967ef242 100644 (file)
 #include <signal.h>
 #include <unistd.h>
 
-#undef DEBUG_KEYS
-
-#ifdef DEBUG_KEYS
-#define DK(x) x
-#else
-#define DK(x)
-#endif
-
 #define KEY_CTL(x) ((x) & 0x1f) /* KEY_CTL(A) == ^A == \1 */
 
 #define BS   KEY_BACKSPACE
@@ -64,6 +56,7 @@
 #define F6   KEY_F(6)
 #define F7   KEY_F(7)
 #define F8   KEY_F(8)
+#define F9   KEY_F(9)
 #define C(x) KEY_CTL(x)
 
 static command_definition_t cmds[] = {
@@ -111,7 +104,7 @@ static command_definition_t cmds[] = {
        { { '1', F1, 'h' }, 0, CMD_SCREEN_HELP, "screen-help",
          N_("Help screen") },
        { { '2', F2, 0 }, 0, CMD_SCREEN_PLAY, "screen-playlist",
-         N_("Playlist screen") },
+         N_("Queue screen") },
        { { '3', F3, 0 }, 0, CMD_SCREEN_FILE, "screen-browse",
          N_("Browse screen") },
 
@@ -138,15 +131,15 @@ static command_definition_t cmds[] = {
        { { '-', LEFT, 0 }, 0, CMD_VOLUME_DOWN, "volume-down",
          N_("Decrease volume") },
        { { ' ', 0, 0 }, 0, CMD_SELECT, "select",
-         N_("Select/deselect song in playlist") },
+         N_("Select/deselect song in queue") },
        { { 't', 0, 0 }, 0, CMD_SELECT_ALL, "select_all",
          N_("Select all listed items") },
        { { DEL, 'd', 0 }, 0, CMD_DELETE, "delete",
-         N_("Delete song from playlist") },
+         N_("Delete song from queue") },
        { { 'Z', 0, 0 }, 0, CMD_SHUFFLE, "shuffle",
-         N_("Shuffle playlist") },
+         N_("Shuffle queue") },
        { { 'c', 0, 0 }, 0, CMD_CLEAR, "clear",
-         N_("Clear playlist") },
+         N_("Clear queue") },
        { { 'r', 0, 0 }, 0, CMD_REPEAT, "repeat",
          N_("Toggle repeat mode") },
        { { 'z', 0, 0 }, 0, CMD_RANDOM, "random",
@@ -160,9 +153,9 @@ static command_definition_t cmds[] = {
        { { C('U'), 0, 0 }, 0, CMD_DB_UPDATE, "db-update",
          N_("Start a music database update") },
        { { 'S', 0, 0 }, 0, CMD_SAVE_PLAYLIST, "save",
-         N_("Save playlist") },
+         N_("Save queue") },
        { { 'a', 0, 0 }, 0, CMD_ADD, "add",
-         N_("Add url/file to playlist") },
+         N_("Add url/file to queue") },
 
        { { '!', 0, 0 }, 0, CMD_GO_ROOT_DIRECTORY, "go-root-directory",
          N_("Go to root directory") },
@@ -241,8 +234,10 @@ static command_definition_t cmds[] = {
          N_("Interrupt action") },
        { {'u', 0, 0 }, 0, CMD_LYRICS_UPDATE, "lyrics-update",
          N_("Update Lyrics") },
-       { {'e', 0, 0 }, 0, CMD_LYRICS_EDIT, "lyrics-edit",
-         N_("Edit Lyrics") },
+       /* this command may move out of #ifdef ENABLE_LYRICS_SCREEN
+          at some point */
+       { {'e', 0, 0 }, 0, CMD_EDIT, "edit",
+         N_("Edit the current item") },
 #endif
 
 #ifdef ENABLE_OUTPUTS_SCREEN
@@ -250,6 +245,10 @@ static command_definition_t cmds[] = {
          N_("Outputs screen") },
 #endif
 
+#ifdef ENABLE_CHAT_SCREEN
+       { {'9', F9, 0}, 0, CMD_SCREEN_CHAT, "screen-chat",
+         N_("Chat screen") },
+#endif
 
        { { -1, -1, -1 }, 0, CMD_NONE, NULL, NULL }
 };
@@ -260,6 +259,30 @@ get_command_definitions(void)
 {
        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 *
@@ -328,28 +351,28 @@ command_dump_keys(void)
 {
        for (int i = 0; cmds[i].description; i++)
                if (cmds[i].command != CMD_NONE)
-                       printf(" %20s : %s\n", get_key_names(cmds[i].command,1),cmds[i].name);
+                       printf(" %20s : %s\n",
+                              get_key_names(cmds[i].command, true),
+                              cmds[i].name);
 }
 
 #ifndef NCMPC_MINI
 
-static int
+static void
 set_key_flags(command_definition_t *cp, command_t command, int flags)
 {
        for (int i = 0; cp[i].name; i++) {
                if (cp[i].command == command) {
                        cp[i].flags |= flags;
-                       return 0;
+                       break;
                }
        }
-
-       return 1;
 }
 
 #endif
 
 const char *
-get_key_names(command_t command, int all)
+get_key_names(command_t command, bool all)
 {
        for (int i = 0; cmds[i].description; i++) {
                if (cmds[i].command == command) {
@@ -391,7 +414,7 @@ get_key_command_name(command_t command)
 }
 
 command_t
-get_key_command_from_name(char *name)
+get_key_command_from_name(const char *name)
 {
        for (int i = 0; cmds[i].name; i++)
                if (strcmp(name, cmds[i].name) == 0)
@@ -401,16 +424,15 @@ get_key_command_from_name(char *name)
 }
 
 command_t
-find_key_command(int key, command_definition_t *c)
+find_key_command(int key, const command_definition_t *c)
 {
        assert(key != 0);
        assert(c != NULL);
 
        for (int i = 0; c[i].name; i++) {
-               if (c[i].keys[0] == key ||
-                   c[i].keys[1] == key ||
-                   c[i].keys[2] == key)
-                       return c[i].command;
+               for (int j = 0; j < MAX_COMMAND_KEYS; j++)
+                       if (c[i].keys[j] == key)
+                               return c[i].command;
        }
 
        return CMD_NONE;
@@ -428,7 +450,7 @@ get_keyboard_command(void)
        int key;
 
        key = wgetch(stdscr);
-       if (key == ERR)
+       if (key == ERR || key == '\0')
                return CMD_NONE;
 
 #ifdef HAVE_GETMOUSE
@@ -531,4 +553,4 @@ write_key_bindings(FILE *f, int flags)
        return ferror(f);
 }
 
-#endif
+#endif /* NCMPC_MINI */