Code

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