Code

Make delete_lyr_hd usable
[ncmpc.git] / src / screen_help.c
index 54b54f22b66dcba780dc763fa2d1a979186b5393..2ac90b774c30bcc125af11eb4a5e02e274b60ed2 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
 
  * This program is free software; you can redistribute it and/or modify
@@ -20,6 +20,8 @@
 #include "screen_help.h"
 #include "screen_interface.h"
 #include "screen_find.h"
+#include "paint.h"
+#include "charset.h"
 #include "config.h"
 #include "i18n.h"
 
@@ -54,7 +56,7 @@ static const struct help_text_row help_text[] = {
 
        { 0, CMD_SCREEN_PREVIOUS,NULL },
        { 0, CMD_SCREEN_NEXT, NULL },
-    { 0, CMD_SCREEN_SWAP, NULL },
+       { 0, CMD_SCREEN_SWAP, NULL },
        { 0, CMD_SCREEN_HELP, NULL },
        { 0, CMD_SCREEN_PLAY, NULL },
        { 0, CMD_SCREEN_FILE, NULL },
@@ -159,6 +161,7 @@ static const struct help_text_row help_text[] = {
        { 0, CMD_INTERRUPT, N_("Interrupt retrieval") },
        { 0, CMD_LYRICS_UPDATE, N_("Download lyrics for currently playing song") },
        { 0, CMD_SAVE_PLAYLIST, N_("Save lyrics") },
+       { 0, CMD_DELETE, N_("Delete saved lyrics") },
 #endif
 #ifdef ENABLE_OUTPUTS_SCREEN
        { 0, CMD_NONE, NULL },
@@ -182,46 +185,25 @@ static const struct help_text_row help_text[] = {
 static struct list_window *lw;
 
 static const char *
-list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char** second_column, G_GNUC_UNUSED void *data)
+list_callback(unsigned i, G_GNUC_UNUSED void *data)
 {
-       static char buf[512];
+       const struct help_text_row *row = &help_text[i];
 
-       assert(idx < G_N_ELEMENTS(help_text));
+       assert(i < G_N_ELEMENTS(help_text));
 
-       if (help_text[idx].highlight)
-               *highlight = true;
+       if (row->text != NULL)
+               return _(row->text);
 
-       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 (row->command != CMD_NONE)
+               return get_key_description(row->command);
 
-                       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].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;
+       return "";
 }
 
 static void
 help_init(WINDOW *w, int cols, int rows)
 {
-  lw = list_window_init(w, cols, rows);
+       lw = list_window_init(w, cols, rows);
        lw->hide_cursor = true;
        list_window_set_length(lw, G_N_ELEMENTS(help_text));
 }
@@ -235,7 +217,7 @@ help_resize(int cols, int rows)
 static void
 help_exit(void)
 {
-  list_window_free(lw);
+       list_window_free(lw);
 }
 
 
@@ -245,10 +227,43 @@ help_title(G_GNUC_UNUSED char *str, G_GNUC_UNUSED size_t size)
        return _("Help");
 }
 
+static void
+screen_help_paint_callback(WINDOW *w, unsigned i,
+                          unsigned y, unsigned width,
+                          G_GNUC_UNUSED bool selected,
+                          G_GNUC_UNUSED void *data)
+{
+       const struct help_text_row *row = &help_text[i];
+
+       assert(i < G_N_ELEMENTS(help_text));
+
+       row_color(w, row->highlight ? COLOR_LIST_BOLD : COLOR_LIST, false);
+
+       wclrtoeol(w);
+
+       if (row->command == CMD_NONE) {
+               if (row->text != NULL)
+                       mvwaddstr(w, y, 6, _(row->text));
+               else if (row->highlight == 2)
+                       mvwhline(w, y, 3, '-', width - 6);
+       } else {
+               const char *key = get_key_names(row->command, true);
+
+               if (utf8_width(key) < 20)
+                       wmove(w, y, 20 - utf8_width(key));
+               waddstr(w, key);
+               mvwaddch(w, y, 21, ':');
+               mvwaddstr(w, y, 23,
+                         row->text != NULL
+                         ? _(row->text)
+                         : get_key_description(row->command));
+       }
+}
+
 static void
 help_paint(void)
 {
-       list_window_paint(lw, list_callback, NULL);
+       list_window_paint2(lw, screen_help_paint_callback, NULL);
 }
 
 static bool