Code

list_window: Added scroll up/down commands
[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_TOP, NULL },
43         { 0, CMD_LIST_MIDDLE, NULL },
44         { 0, CMD_LIST_BOTTOM, NULL },
45         { 0, CMD_LIST_PREVIOUS_PAGE, NULL },
46         { 0, CMD_LIST_NEXT_PAGE, NULL },
47         { 0, CMD_LIST_FIRST, NULL },
48         { 0, CMD_LIST_LAST, NULL },
49         { 0, CMD_LIST_VISUAL_SELECT, NULL },
50         { 0, CMD_LIST_SCROLL_UP_LINE, NULL},
51         { 0, CMD_LIST_SCROLL_DOWN_LINE, NULL},
52         { 0, CMD_NONE, NULL },
53         { 0, CMD_SCREEN_PREVIOUS,NULL },
54         { 0, CMD_SCREEN_NEXT, NULL },
55         { 0, CMD_SCREEN_HELP, NULL },
56         { 0, CMD_SCREEN_PLAY, NULL },
57         { 0, CMD_SCREEN_FILE, NULL },
58 #ifdef ENABLE_ARTIST_SCREEN
59         { 0, CMD_SCREEN_ARTIST, NULL },
60 #endif
61 #ifdef ENABLE_SEARCH_SCREEN
62         { 0, CMD_SCREEN_SEARCH, NULL },
63 #endif
64 #ifdef ENABLE_KEYDEF_SCREEN
65         { 0, CMD_SCREEN_KEYDEF, NULL },
66 #endif
68         { 0, CMD_NONE, NULL },
69         { 0, CMD_NONE, NULL },
70         { 1, CMD_NONE, N_("Global") },
71         { 2, CMD_NONE, NULL },
72         { 0, CMD_STOP, NULL },
73         { 0, CMD_PAUSE, NULL },
74         { 0, CMD_CROP, NULL },
75         { 0, CMD_TRACK_NEXT, NULL },
76         { 0, CMD_TRACK_PREVIOUS, NULL },
77         { 0, CMD_SEEK_FORWARD, NULL },
78         { 0, CMD_SEEK_BACKWARD, NULL },
79         { 0, CMD_VOLUME_DOWN, NULL },
80         { 0, CMD_VOLUME_UP, NULL },
81         { 0, CMD_NONE, NULL },
82         { 0, CMD_REPEAT, NULL },
83         { 0, CMD_RANDOM, NULL },
84         { 0, CMD_CROSSFADE, NULL },
85         { 0, CMD_SHUFFLE, NULL },
86         { 0, CMD_DB_UPDATE, NULL },
87         { 0, CMD_NONE, NULL },
88         { 0, CMD_LIST_FIND, NULL },
89         { 0, CMD_LIST_RFIND, NULL },
90         { 0, CMD_LIST_FIND_NEXT, NULL },
91         { 0, CMD_LIST_RFIND_NEXT, NULL },
92         { 0, CMD_LIST_JUMP, NULL },
93         { 0, CMD_TOGGLE_FIND_WRAP, NULL },
94         { 0, CMD_LOCATE, NULL },
95         { 0, CMD_VIEW, NULL },
96         { 0, CMD_NONE, NULL },
97         { 0, CMD_QUIT, NULL },
99         { 0, CMD_NONE, NULL },
100         { 0, CMD_NONE, NULL },
101         { 1, CMD_NONE, N_("Playlist screen") },
102         { 2, CMD_NONE, NULL },
103         { 0, CMD_PLAY, N_("Play") },
104         { 0, CMD_DELETE, NULL },
105         { 0, CMD_CLEAR, NULL },
106         { 0, CMD_LIST_MOVE_UP, N_("Move song up") },
107         { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
108         { 0, CMD_ADD, NULL },
109         { 0, CMD_SAVE_PLAYLIST, NULL },
110         { 0, CMD_SCREEN_UPDATE, N_("Center") },
111         { 0, CMD_TOGGLE_AUTOCENTER, NULL },
113         { 0, CMD_NONE, NULL },
114         { 0, CMD_NONE, NULL },
115         { 1, CMD_NONE, N_("Browse screen") },
116         { 2, CMD_NONE, NULL },
117         { 0, CMD_PLAY, N_("Enter directory/Select and play song") },
118         { 0, CMD_SELECT, NULL },
119         { 0, CMD_ADD, N_("Append song to playlist") },
120         { 0, CMD_SAVE_PLAYLIST, NULL },
121         { 0, CMD_DELETE, N_("Delete playlist") },
122         { 0, CMD_GO_PARENT_DIRECTORY, NULL },
123         { 0, CMD_GO_ROOT_DIRECTORY, NULL },
124         { 0, CMD_SCREEN_UPDATE, NULL },
126 #ifdef ENABLE_SEARCH_SCREEN
127         { 0, CMD_NONE, NULL },
128         { 0, CMD_NONE, NULL },
129         { 1, CMD_NONE, N_("Search screen") },
130         { 2, CMD_NONE, NULL },
131         { 0, CMD_SCREEN_SEARCH, N_("Search") },
132         { 0, CMD_PLAY, N_("Select and play") },
133         { 0, CMD_SELECT, NULL },
134         { 0, CMD_ADD, N_("Append song to playlist") },
135         { 0, CMD_SELECT_ALL,     NULL },
136         { 0, CMD_SEARCH_MODE, NULL },
137 #endif
138 #ifdef ENABLE_LYRICS_SCREEN
139         { 0, CMD_NONE, NULL },
140         { 0, CMD_NONE, NULL },
141         { 1, CMD_NONE, N_("Lyrics screen") },
142         { 2, CMD_NONE, NULL },
143         { 0, CMD_SCREEN_LYRICS, N_("View Lyrics") },
144         { 0, CMD_SELECT, N_("(Re)load lyrics") },
145         { 0, CMD_INTERRUPT, N_("Interrupt retrieval") },
146         { 0, CMD_LYRICS_UPDATE, N_("Explicitly download lyrics") },
147         { 0, CMD_ADD, N_("Save lyrics") },
148 #endif
149 #ifdef ENABLE_OUTPUTS_SCREEN
150         { 0, CMD_NONE, NULL },
151         { 0, CMD_NONE, NULL },
152         { 1, CMD_NONE, N_("Outputs screen") },
153         { 2, CMD_NONE, NULL },
154         { 0, CMD_PLAY, N_("Enable/disable output") },
155 #endif
156 };
158 #define help_text_rows (sizeof(help_text) / sizeof(help_text[0]))
160 static list_window_t *lw;
162 static const char *
163 list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data)
165         static char buf[512];
167         if (idx >= help_text_rows)
168                 return NULL;
170         if (help_text[idx].highlight)
171                 *highlight = true;
173         if (help_text[idx].command == CMD_NONE) {
174                 if (help_text[idx].text)
175                         g_snprintf(buf, sizeof(buf), "      %s", _(help_text[idx].text));
176                 else if (help_text[idx].highlight == 2) {
177                         int i;
179                         for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
180                                 buf[i] = '-';
181                         buf[i] = '\0';
182                 } else
183                         g_strlcpy(buf, " ", sizeof(buf));
184                 return buf;
185         }
187         if (help_text[idx].text)
188                 g_snprintf(buf, sizeof(buf),
189                            "%20s : %s   ",
190                            get_key_names(help_text[idx].command, TRUE),
191                            _(help_text[idx].text));
192         else
193                 g_snprintf(buf, sizeof(buf),
194                            "%20s : %s   ",
195                            get_key_names(help_text[idx].command, TRUE),
196                            get_key_description(help_text[idx].command));
197         return buf;
200 static void
201 help_init(WINDOW *w, int cols, int rows)
203   lw = list_window_init(w, cols, rows);
204         lw->hide_cursor = true;
207 static void
208 help_resize(int cols, int rows)
210   lw->cols = cols;
211   lw->rows = rows;
214 static void
215 help_exit(void)
217   list_window_free(lw);
221 static const char *
222 help_title(G_GNUC_UNUSED char *str, G_GNUC_UNUSED size_t size)
224         return _("Help");
227 static void
228 help_paint(void)
230         list_window_paint(lw, list_callback, NULL);
233 static bool
234 help_cmd(G_GNUC_UNUSED mpdclient_t *c, command_t cmd)
236         if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
237                 list_window_paint(lw, list_callback, NULL);
238                 wrefresh(lw->w);
239                 return true;
240         }
242         lw->selected = lw->start+lw->rows;
243         if (screen_find(lw,  help_text_rows,
244                         cmd, list_callback, NULL)) {
245                 /* center the row */
246                 list_window_center(lw, help_text_rows, lw->selected);
247                 list_window_paint(lw, list_callback, NULL);
248                 wrefresh(lw->w);
249                 return true;
250         }
252         return false;
255 const struct screen_functions screen_help = {
256         .init = help_init,
257         .exit = help_exit,
258         .resize = help_resize,
259         .paint = help_paint,
260         .cmd = help_cmd,
261         .get_title = help_title,
262 };