Code

support multiple lines selection
[ncmpc.git] / src / screen_help.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2009 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #include "config.h"
21 #include "i18n.h"
22 #include "mpdclient.h"
23 #include "command.h"
24 #include "screen.h"
25 #include "screen_utils.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
31 typedef struct {
32         signed char highlight;
33         command_t command;
34         const char *text;
35 } help_text_row_t;
37 static help_text_row_t help_text[] = {
38         { 1, CMD_NONE, N_("Movement") },
39         { 2, CMD_NONE, NULL },
40         { 0, CMD_LIST_PREVIOUS, NULL },
41         { 0, CMD_LIST_NEXT, NULL },
42         { 0, CMD_LIST_PREVIOUS_PAGE, NULL },
43         { 0, CMD_LIST_NEXT_PAGE, NULL },
44         { 0, CMD_LIST_FIRST, NULL },
45         { 0, CMD_LIST_LAST, NULL },
46         { 0, CMD_LIST_VISUAL_SELECT, NULL },
47         { 0, CMD_NONE, NULL },
48         { 0, CMD_SCREEN_PREVIOUS,NULL },
49         { 0, CMD_SCREEN_NEXT, NULL },
50         { 0, CMD_SCREEN_HELP, NULL },
51         { 0, CMD_SCREEN_PLAY, NULL },
52         { 0, CMD_SCREEN_FILE, NULL },
53 #ifdef ENABLE_ARTIST_SCREEN
54         { 0, CMD_SCREEN_ARTIST, NULL },
55 #endif
56 #ifdef ENABLE_SEARCH_SCREEN
57         { 0, CMD_SCREEN_SEARCH, NULL },
58 #endif
59 #ifdef ENABLE_KEYDEF_SCREEN
60         { 0, CMD_SCREEN_KEYDEF, NULL },
61 #endif
63         { 0, CMD_NONE, NULL },
64         { 0, CMD_NONE, NULL },
65         { 1, CMD_NONE, N_("Global") },
66         { 2, CMD_NONE, NULL },
67         { 0, CMD_STOP, NULL },
68         { 0, CMD_PAUSE, NULL },
69         { 0, CMD_CROP, NULL },
70         { 0, CMD_TRACK_NEXT, NULL },
71         { 0, CMD_TRACK_PREVIOUS, NULL },
72         { 0, CMD_SEEK_FORWARD, NULL },
73         { 0, CMD_SEEK_BACKWARD, NULL },
74         { 0, CMD_VOLUME_DOWN, NULL },
75         { 0, CMD_VOLUME_UP, NULL },
76         { 0, CMD_NONE, NULL },
77         { 0, CMD_REPEAT, NULL },
78         { 0, CMD_RANDOM, NULL },
79         { 0, CMD_CROSSFADE, NULL },
80         { 0, CMD_SHUFFLE, NULL },
81         { 0, CMD_DB_UPDATE, NULL },
82         { 0, CMD_NONE, NULL },
83         { 0, CMD_LIST_FIND, NULL },
84         { 0, CMD_LIST_RFIND, NULL },
85         { 0, CMD_LIST_FIND_NEXT, NULL },
86         { 0, CMD_LIST_RFIND_NEXT, NULL },
87         { 0, CMD_TOGGLE_FIND_WRAP, NULL },
88         { 0, CMD_LOCATE, NULL },
89         { 0, CMD_VIEW, NULL },
90         { 0, CMD_NONE, NULL },
91         { 0, CMD_QUIT, NULL },
93         { 0, CMD_NONE, NULL },
94         { 0, CMD_NONE, NULL },
95         { 1, CMD_NONE, N_("Playlist screen") },
96         { 2, CMD_NONE, NULL },
97         { 0, CMD_PLAY, N_("Play") },
98         { 0, CMD_DELETE, NULL },
99         { 0, CMD_CLEAR, NULL },
100         { 0, CMD_LIST_MOVE_UP, N_("Move song up") },
101         { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
102         { 0, CMD_ADD, NULL },
103         { 0, CMD_SAVE_PLAYLIST, NULL },
104         { 0, CMD_SCREEN_UPDATE, N_("Center") },
105         { 0, CMD_TOGGLE_AUTOCENTER, NULL },
107         { 0, CMD_NONE, NULL },
108         { 0, CMD_NONE, NULL },
109         { 1, CMD_NONE, N_("Browse screen") },
110         { 2, CMD_NONE, NULL },
111         { 0, CMD_PLAY, N_("Enter directory/Select and play song") },
112         { 0, CMD_SELECT, NULL },
113         { 0, CMD_ADD, N_("Append song to playlist") },
114         { 0, CMD_SAVE_PLAYLIST, NULL },
115         { 0, CMD_DELETE, N_("Delete playlist") },
116         { 0, CMD_GO_PARENT_DIRECTORY, NULL },
117         { 0, CMD_GO_ROOT_DIRECTORY, NULL },
118         { 0, CMD_SCREEN_UPDATE, NULL },
120 #ifdef ENABLE_SEARCH_SCREEN
121         { 0, CMD_NONE, NULL },
122         { 0, CMD_NONE, NULL },
123         { 1, CMD_NONE, N_("Search screen") },
124         { 2, CMD_NONE, NULL },
125         { 0, CMD_SCREEN_SEARCH, N_("Search") },
126         { 0, CMD_PLAY, N_("Select and play") },
127         { 0, CMD_SELECT, NULL },
128         { 0, CMD_ADD, N_("Append song to playlist") },
129         { 0, CMD_SELECT_ALL,     NULL },
130         { 0, CMD_SEARCH_MODE, NULL },
131 #endif
132 #ifdef ENABLE_LYRICS_SCREEN
133         { 0, CMD_NONE, NULL },
134         { 0, CMD_NONE, NULL },
135         { 1, CMD_NONE, N_("Lyrics screen") },
136         { 2, CMD_NONE, NULL },
137         { 0, CMD_SCREEN_LYRICS, N_("View Lyrics") },
138         { 0, CMD_SELECT, N_("(Re)load lyrics") },
139         { 0, CMD_INTERRUPT, N_("Interrupt retrieval") },
140         { 0, CMD_LYRICS_UPDATE, N_("Explicitly download lyrics") },
141         { 0, CMD_ADD, N_("Save lyrics") },
142 #endif
143 #ifdef ENABLE_OUTPUTS_SCREEN
144         { 0, CMD_NONE, NULL },
145         { 0, CMD_NONE, NULL },
146         { 1, CMD_NONE, N_("Outputs screen") },
147         { 2, CMD_NONE, NULL },
148         { 0, CMD_PLAY, N_("Enable/disable output") },
149 #endif
150 };
152 #define help_text_rows (sizeof(help_text) / sizeof(help_text[0]))
154 static list_window_t *lw;
156 static const char *
157 list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data)
159         static char buf[512];
161         if (idx >= help_text_rows)
162                 return NULL;
164         if (help_text[idx].highlight)
165                 *highlight = true;
167         if (help_text[idx].command == CMD_NONE) {
168                 if (help_text[idx].text)
169                         g_snprintf(buf, sizeof(buf), "      %s", _(help_text[idx].text));
170                 else if (help_text[idx].highlight == 2) {
171                         int i;
173                         for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
174                                 buf[i] = '-';
175                         buf[i] = '\0';
176                 } else
177                         g_strlcpy(buf, " ", sizeof(buf));
178                 return buf;
179         }
181         if (help_text[idx].text)
182                 g_snprintf(buf, sizeof(buf),
183                            "%20s : %s   ",
184                            get_key_names(help_text[idx].command, TRUE),
185                            _(help_text[idx].text));
186         else
187                 g_snprintf(buf, sizeof(buf),
188                            "%20s : %s   ",
189                            get_key_names(help_text[idx].command, TRUE),
190                            get_key_description(help_text[idx].command));
191         return buf;
194 static void
195 help_init(WINDOW *w, int cols, int rows)
197   lw = list_window_init(w, cols, rows);
198         lw->hide_cursor = true;
201 static void
202 help_resize(int cols, int rows)
204   lw->cols = cols;
205   lw->rows = rows;
208 static void
209 help_exit(void)
211   list_window_free(lw);
215 static const char *
216 help_title(G_GNUC_UNUSED char *str, G_GNUC_UNUSED size_t size)
218         return _("Help");
221 static void
222 help_paint(void)
224         list_window_paint(lw, list_callback, NULL);
227 static bool
228 help_cmd(G_GNUC_UNUSED mpdclient_t *c, command_t cmd)
230         if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
231                 list_window_paint(lw, list_callback, NULL);
232                 wrefresh(lw->w);
233                 return true;
234         }
236         lw->selected = lw->start+lw->rows;
237         if (screen_find(lw,  help_text_rows,
238                         cmd, list_callback, NULL)) {
239                 /* center the row */
240                 list_window_center(lw, help_text_rows, lw->selected);
241                 list_window_paint(lw, list_callback, NULL);
242                 wrefresh(lw->w);
243                 return true;
244         }
246         return false;
249 const struct screen_functions screen_help = {
250         .init = help_init,
251         .exit = help_exit,
252         .resize = help_resize,
253         .paint = help_paint,
254         .cmd = help_cmd,
255         .get_title = help_title,
256 };