Code

Use glib's str functions (g_strlcat, g_strlcpy, g_snprintf, g_strdup_vprintf)
[ncmpc.git] / src / screen_help.c
index 4d76ffe7fa3b6414d90061cb135827a4a6c9684b..94fe9ab5b35dde881d27f40a08bb2102005a12f9 100644 (file)
@@ -110,23 +110,6 @@ static help_text_row_t help_text[] =
   { 0, CMD_DELETE,         NULL },
   { 0, CMD_SCREEN_UPDATE,  NULL },
 
-  { 0, CMD_NONE, NULL },
-  { 0, CMD_NONE, NULL },
-  { 1, CMD_NONE, "ncmpc build information" },
-  { 2, CMD_NONE, NULL },
-  { 0, CMD_NONE, "             Version : " VERSION },
-  { 0, CMD_NONE, "  Configuration dirs : ~/.ncmpc, " SYSCONFDIR "/" PACKAGE },
-#ifdef ENABLE_NLS
-  { 0, CMD_NONE, "NLS support : yes" },
-#else
-  { 0, CMD_NONE, "NLS support : no" },
-#endif
-#ifdef ENABLE_KEYDEF_SCREEN
-  { 0, CMD_NONE, "Key Editor : yes" },
-#else
-  { 0, CMD_NONE, "Key Editor : no" },
-#endif
-
   { 0, CMD_NONE, NULL },
   {-1, CMD_NONE, NULL }
 };
@@ -138,7 +121,7 @@ static list_window_t *lw = NULL;
 static char *
 list_callback(int index, int *highlight, void *data)
 {
-  static char buf[256];
+  static char buf[512];
 
   if( help_text_rows<0 )
     {
@@ -154,30 +137,30 @@ list_callback(int index, int *highlight, void *data)
       if( help_text[index].command == CMD_NONE )
        {
          if( help_text[index].text )
-           snprintf(buf, 256, "%28s", _(help_text[index].text));
+           g_snprintf(buf, sizeof(buf), "%28s", _(help_text[index].text));
          else 
            if( help_text[index].highlight == 2 )
              {
                int i;
 
-               for(i=3; i<COLS-3 && i<256; i++)
+               for(i=3; i<COLS-3 && i<sizeof(buf); i++)
                  buf[i]='-';
                buf[i] = '\0';
              }
            else
-             strcpy(buf, " ");
+             g_strlcpy(buf, " ", sizeof(buf));
          return buf;
        }
       if( help_text[index].text )
-       snprintf(buf, 256
-                "%20s : %s   ", 
-                get_key_names(help_text[index].command, TRUE),
-                _(help_text[index].text));
+       g_snprintf(buf, sizeof(buf)
+                  "%20s : %s   ", 
+                  get_key_names(help_text[index].command, TRUE),
+                  _(help_text[index].text));
       else
-       snprintf(buf, 256
-                "%20s : %s   ", 
-                get_key_names(help_text[index].command, TRUE),
-                get_key_description(help_text[index].command));
+       g_snprintf(buf, sizeof(buf)
+                  "%20s : %s   ", 
+                  get_key_names(help_text[index].command, TRUE),
+                  get_key_description(help_text[index].command));
       return buf;
     }
 
@@ -188,6 +171,7 @@ static void
 help_init(WINDOW *w, int cols, int rows)
 {
   lw = list_window_init(w, cols, rows);
+  lw->flags = LW_HIDE_CURSOR;
 }
 
 static void
@@ -233,15 +217,56 @@ help_update(screen_t *screen, mpdclient_t *c)
 static int 
 help_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
 {
-  int retval;
+  lw->repaint=1;
+  switch(cmd)
+    {
+    case CMD_LIST_NEXT:
+      if( lw->start+lw->rows < help_text_rows )
+       lw->start++;
+      return 1;
+    case CMD_LIST_PREVIOUS:
+      if( lw->start >0 )
+       lw->start--;
+      return 1;
+    case CMD_LIST_FIRST:
+      lw->start = 0;
+      return 1;
+    case CMD_LIST_LAST:
+      lw->start = help_text_rows-lw->rows;
+      if( lw->start<0 )
+       lw->start = 0;
+      return 1;
+    case CMD_LIST_NEXT_PAGE:
+      lw->start = lw->start + lw->rows;
+      if( lw->start+lw->rows >= help_text_rows )
+       lw->start = help_text_rows-lw->rows;
+      if( lw->start<0 )
+       lw->start = 0;
+       return 1;
+    case CMD_LIST_PREVIOUS_PAGE:
+      lw->start = lw->start - lw->rows;
+      if( lw->start<0 )
+       lw->start = 0;
+      return 1;
+    default:
+      break;
+    }
 
-  retval = list_window_cmd(lw, help_text_rows, cmd);
-  if( !retval )
-    return screen_find(screen, c, 
-                      lw,  help_text_rows,
-                      cmd, list_callback);
+  lw->selected = lw->start+lw->rows;
+  if( screen_find(screen, c, 
+                 lw,  help_text_rows,
+                 cmd, list_callback) )
+    {
+      /* center the row */
+      lw->start = lw->selected-(lw->rows/2);
+      if( lw->start+lw->rows > help_text_rows )
+       lw->start = help_text_rows-lw->rows;
+      if( lw->start<0 )
+       lw->start=0;
+      return 1;
+    }
 
-  return retval;
+  return 0;
 }
 
 static list_window_t *