Code

Added support for (auto) center/focus playlists.
[ncmpc.git] / screen_help.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <glib.h>
4 #include <ncurses.h>
6 #include "config.h"
7 #include "libmpdclient.h"
8 #include "mpc.h"
9 #include "command.h"
10 #include "screen.h"
11 #include "screen_utils.h"
12 #include "screen_help.h"
14 typedef struct
15 {
16   char highlight;
17   command_t command;
18   char *text;
19 } help_text_row_t;
21 static help_text_row_t help_text[] = 
22 {
23   { 1, CMD_NONE,  "          Keys   " },
24   { 0, CMD_NONE,  "        --------" },
25   { 0, CMD_STOP,           "Stop" },
26   { 0, CMD_PAUSE,          "Pause" },
27   { 0, CMD_TRACK_NEXT,     "Next track" },
28   { 0, CMD_TRACK_PREVIOUS, "Prevoius track (back)" },
29   { 0, CMD_VOLUME_DOWN,    "Volume down" },
30   { 0, CMD_VOLUME_UP,      "Volume up" },
31   { 0, CMD_NONE, " " },
32   { 0, CMD_LIST_NEXT,      "Move cursor up" },
33   { 0, CMD_LIST_PREVIOUS,  "Move cursor down" },
34   { 0, CMD_LIST_FIND,      "Find" },
35   { 0, CMD_LIST_RFIND,     "find backward" },
36   { 0, CMD_LIST_FIND_NEXT, "Find next" },
37   { 0, CMD_LIST_RFIND_NEXT,"Find previuos" },
38   { 0, CMD_TOGGLE_FIND_WRAP, "Toggle find mode" },
39   { 0, CMD_NONE, " " },
40   { 0, CMD_SCREEN_NEXT,   "Change screen" },
41   { 0, CMD_SCREEN_HELP,   "Help screen" },
42   { 0, CMD_SCREEN_PLAY,   "Playlist screen" },
43   { 0, CMD_SCREEN_FILE,   "Browse screen" },
44   { 0, CMD_QUIT,          "Quit" },
45   { 0, CMD_NONE, " " },
46   { 0, CMD_NONE, " " },
47   { 1, CMD_NONE, "    Keys - Playlist screen " },
48   { 0, CMD_NONE, "  --------------------------" },
49   { 0, CMD_PLAY,           "Play selected entry" },
50   { 0, CMD_DELETE,         "Delete selected entry from playlist" },
51   { 0, CMD_SHUFFLE,        "Shuffle playlist" },
52   { 0, CMD_CLEAR,          "Clear playlist" },
53   { 0, CMD_SAVE_PLAYLIST,  "Save playlist" },
54   { 0, CMD_REPEAT,         "Toggle repeat mode" },
55   { 0, CMD_RANDOM,         "Toggle random mode" },
56   { 0, CMD_SCREEN_UPDATE,  "Center playing track" },
57   { 0, CMD_TOGGLE_AUTOCENTER, "Toggle auto center" },
58   { 0, CMD_NONE, " " },
59   { 0, CMD_NONE, " " },
60   { 1, CMD_NONE, "    Keys - Browse screen " },
61   { 0, CMD_NONE, "  ------------------------" },
62   { 0, CMD_PLAY,            "Enter directory/Load playlist" },
63   { 0, CMD_SELECT,          "Add/remove song from playlist" },
64   { 0, CMD_DELETE,          "Delete playlist" },
65   { 0, CMD_SCREEN_UPDATE,   "Update" },
66   { 0, CMD_NONE, " " },
67   { 0, CMD_NONE, " " },
68   { 1, CMD_NONE, " " PACKAGE " version " VERSION },
69   { 0, CMD_NONE, NULL }
70 };
72 static int help_text_rows = -1;
76 static char *
77 list_callback(int index, int *highlight, void *data)
78 {
79   static char buf[256];
81   if( help_text_rows<0 )
82     {
83       help_text_rows = 0;
84       while( help_text[help_text_rows].text )
85         help_text_rows++;
86     }
88   *highlight = 0;
89   if( index<help_text_rows )
90     {
91       *highlight = help_text[index].highlight;
92       if( help_text[index].command == CMD_NONE )
93         return help_text[index].text;
94       snprintf(buf, 256, 
95                "%20s : %s", 
96                command_get_keys(help_text[index].command),
97                help_text[index].text);
98       return buf;
99     }
101   return NULL;
105 void 
106 help_open(screen_t *screen, mpd_client_t *c)
110 void 
111 help_close(screen_t *screen, mpd_client_t *c)
115 void 
116 help_paint(screen_t *screen, mpd_client_t *c)
118   list_window_t *w = screen->helplist;
120   w->clear = 1;
121   list_window_paint(screen->helplist, list_callback, NULL);
122   wrefresh(screen->helplist->w);
125 void 
126 help_update(screen_t *screen, mpd_client_t *c)
127 {  
128   list_window_t *w = screen->helplist;
129  
130   if( w->repaint )
131     {
132       list_window_paint(screen->helplist, list_callback, NULL);
133       wrefresh(screen->helplist->w);
134       w->repaint = 0;
135     }
139 int 
140 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
142   int retval;
144   retval = list_window_cmd(screen->helplist, help_text_rows, cmd);
145   if( !retval )
146     return screen_find(screen, c, 
147                        screen->helplist, help_text_rows,
148                        cmd, list_callback);
150   return retval;