Code

forgot to add this
[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_FIND_NEXT, "Find again" },
36   { 0, CMD_NONE, " " },
37   { 0, CMD_SCREEN_NEXT,   "Change screen" },
38   { 0, CMD_SCREEN_HELP,   "Help screen" },
39   { 0, CMD_SCREEN_PLAY,   "Playlist screen" },
40   { 0, CMD_SCREEN_FILE,   "Browse screen" },
41   { 0, CMD_QUIT,          "Quit" },
42   { 0, CMD_NONE, " " },
43   { 0, CMD_NONE, " " },
44   { 1, CMD_NONE, "    Keys - Playlist screen " },
45   { 0, CMD_NONE, "  --------------------------" },
46   { 0, CMD_PLAY,    "Play selected entry" },
47   { 0, CMD_DELETE,  "Delete selected entry from platlist" },
48   { 0, CMD_SHUFFLE, "Shuffle playlist" },
49   { 0, CMD_CLEAR,   "Clear playlist" },
50   { 0, CMD_REPEAT,  "Toggle repeat mode" },
51   { 0, CMD_RANDOM,  "Toggle random mode" },
52   { 0, CMD_NONE, " " },
53   { 0, CMD_NONE, " " },
54   { 1, CMD_NONE, "    Keys - Browse screen " },
55   { 0, CMD_NONE, "  ------------------------" },
56   { 0, CMD_PLAY,   "Change to selected directory" },
57   { 0, CMD_SELECT, "Add/Remove selected file" },
58   { 0, CMD_NONE, " " },
59   { 0, CMD_NONE, " " },
60   { 1, CMD_NONE, " " PACKAGE " version " VERSION },
61   { 0, CMD_NONE, NULL }
62 };
64 static int help_text_rows = -1;
68 static char *
69 list_callback(int index, int *highlight, void *data)
70 {
71   static char buf[256];
73   if( help_text_rows<0 )
74     {
75       help_text_rows = 0;
76       while( help_text[help_text_rows].text )
77         help_text_rows++;
78     }
80   *highlight = 0;
81   if( index<help_text_rows )
82     {
83       *highlight = help_text[index].highlight;
84       if( help_text[index].command == CMD_NONE )
85         return help_text[index].text;
86       snprintf(buf, 256, 
87                "%20s : %s", 
88                command_get_keys(help_text[index].command),
89                help_text[index].text);
90       return buf;
91     }
93   return NULL;
94 }
97 void 
98 help_open(screen_t *screen, mpd_client_t *c)
99 {
102 void 
103 help_close(screen_t *screen, mpd_client_t *c)
107 void 
108 help_paint(screen_t *screen, mpd_client_t *c)
110   list_window_t *w = screen->helplist;
112   w->clear = 1;
113   list_window_paint(screen->helplist, list_callback, NULL);
114   wrefresh(screen->helplist->w);
117 void 
118 help_update(screen_t *screen, mpd_client_t *c)
119 {  
120   list_window_t *w = screen->helplist;
121  
122   if( w->repaint )
123     {
124       list_window_paint(screen->helplist, list_callback, NULL);
125       wrefresh(screen->helplist->w);
126       w->repaint = 0;
127     }
131 int 
132 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
134  switch(cmd)
135     {
136     case CMD_LIST_FIND:
137       if( screen->findbuf )
138         {
139           free(screen->findbuf);
140           screen->findbuf=NULL;
141         }
142       /* continue... */
143     case CMD_LIST_FIND_NEXT:
144       if( !screen->findbuf )
145         screen->findbuf=screen_readln(screen->status_window.w, "/");
146       if( list_window_find(screen->helplist,
147                            list_callback,
148                            c,
149                            screen->findbuf) == 0 )
150         {
151           screen->helplist->repaint  = 1;
152         }
153       else
154         {
155           screen_status_printf("Unable to find \'%s\'", screen->findbuf);
156           beep();
157         }
158       return 1;
159     default:
160       break;
161     }
162   return list_window_cmd(screen->helplist, help_text_rows, cmd);