Code

Adding crop feature in ncmpc
[ncmpc.git] / src / screen_help.c
index 05b735eccc2c6c33f4ba85865d8479da1c3accf4..79b8fa722ef146a9e638be46515285f42644da07 100644 (file)
@@ -57,9 +57,6 @@ static help_text_row_t help_text[] =
 #ifdef ENABLE_SEARCH_SCREEN
   { 0, CMD_SCREEN_SEARCH,  NULL },
 #endif
-#ifdef ENABLE_CLOCK_SCREEN
-  { 0, CMD_SCREEN_CLOCK,   NULL },
-#endif
 #ifdef ENABLE_KEYDEF_SCREEN
   { 0, CMD_SCREEN_KEYDEF,  NULL },
 #endif
@@ -70,6 +67,7 @@ static help_text_row_t help_text[] =
   { 2, CMD_NONE,           NULL },
   { 0, CMD_STOP,           NULL },
   { 0, CMD_PAUSE,          NULL },
+  { 0, CMD_CROP, NULL },
   { 0, CMD_TRACK_NEXT,     NULL },
   { 0, CMD_TRACK_PREVIOUS, NULL },
   { 0, CMD_SEEK_FORWARD,   NULL },
@@ -151,37 +149,37 @@ list_callback(unsigned idx, int *highlight, mpd_unused void *data)
 {
        static char buf[512];
 
-       *highlight = 0;
-       if (idx < help_text_rows) {
-               *highlight = help_text[idx].highlight > 0;
-               if (help_text[idx].command == CMD_NONE) {
-                       if (help_text[idx].text)
-                               g_snprintf(buf, sizeof(buf), "      %s", _(help_text[idx].text));
-                       else if (help_text[idx].highlight == 2) {
-                               int i;
+       if (idx >= help_text_rows)
+               return NULL;
 
-                               for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
-                                       buf[i] = '-';
-                               buf[i] = '\0';
-                       } else
-                               g_strlcpy(buf, " ", sizeof(buf));
-                       return buf;
-               }
+       if (help_text[idx].highlight)
+               *highlight = 1;
 
+       if (help_text[idx].command == CMD_NONE) {
                if (help_text[idx].text)
-                       g_snprintf(buf, sizeof(buf),
-                                  "%20s : %s   ",
-                                  get_key_names(help_text[idx].command, TRUE),
-                                  _(help_text[idx].text));
-               else
-                       g_snprintf(buf, sizeof(buf),
-                                  "%20s : %s   ",
-                                  get_key_names(help_text[idx].command, TRUE),
-                                  get_key_description(help_text[idx].command));
+                       g_snprintf(buf, sizeof(buf), "      %s", _(help_text[idx].text));
+               else if (help_text[idx].highlight == 2) {
+                       int i;
+
+                       for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
+                               buf[i] = '-';
+                       buf[i] = '\0';
+               } else
+                       g_strlcpy(buf, " ", sizeof(buf));
                return buf;
        }
 
-       return NULL;
+       if (help_text[idx].text)
+               g_snprintf(buf, sizeof(buf),
+                          "%20s : %s   ",
+                          get_key_names(help_text[idx].command, TRUE),
+                          _(help_text[idx].text));
+       else
+               g_snprintf(buf, sizeof(buf),
+                          "%20s : %s   ",
+                          get_key_names(help_text[idx].command, TRUE),
+                          get_key_description(help_text[idx].command));
+       return buf;
 }
 
 static void
@@ -219,22 +217,14 @@ help_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c)
        wrefresh(lw->w);
 }
 
-static void
-help_update(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c)
-{
-       if (lw->repaint) {
-               list_window_paint(lw, list_callback, NULL);
-               wrefresh(lw->w);
-               lw->repaint = 0;
-       }
-}
-
-
 static int
 help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd)
 {
-       if (list_window_scroll_cmd(lw, help_text_rows, cmd))
+       if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
+               list_window_paint(lw, list_callback, NULL);
+               wrefresh(lw->w);
                return 1;
+       }
 
        lw->selected = lw->start+lw->rows;
        if (screen_find(screen,
@@ -242,6 +232,8 @@ help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd)
                        cmd, list_callback, NULL)) {
                /* center the row */
                list_window_center(lw, help_text_rows, lw->selected);
+               list_window_paint(lw, list_callback, NULL);
+               wrefresh(lw->w);
                return 1;
        }
 
@@ -253,7 +245,6 @@ const struct screen_functions screen_help = {
        .exit = help_exit,
        .resize = help_resize,
        .paint = help_paint,
-       .update = help_update,
        .cmd = help_cmd,
        .get_title = help_title,
 };