Code

Added find (in page) functionality.
authorKalle Wallin <kaw@linux.se>
Mon, 22 Mar 2004 18:10:23 +0000 (18:10 +0000)
committerKalle Wallin <kaw@linux.se>
Mon, 22 Mar 2004 18:10:23 +0000 (18:10 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@369 09075e82-0dd4-0310-85a5-a0d7c8717e4f

screen_file.c
screen_play.c
screen_utils.c
screen_utils.h

index 086290f745ef9c92e9da5afaf4db131ab74e9c85..c09682cc629e90122dd8cac18aff35d6183c3159 100644 (file)
@@ -333,6 +333,29 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
       list_window_previous_page(screen->filelist);
       screen->filelist->repaint  = 1;
       break;
+    case CMD_LIST_FIND:
+      if( screen->findbuf )
+       {
+         free(screen->findbuf);
+         screen->findbuf=NULL;
+       }
+      /* fall throw... */
+    case CMD_LIST_FIND_NEXT:
+      if( !screen->findbuf )
+       screen->findbuf=screen_readln(screen->status_window.w, "/");
+      if( list_window_find(screen->filelist,
+                          list_callback,
+                          c,
+                          screen->findbuf) == 0 )
+       {
+         screen->filelist->repaint  = 1;
+       }
+      else
+       {
+         screen_status_printf(c, "Unable to find \'%s\'", screen->findbuf);
+         beep();
+       }
+      break;
     default:
       return 0;
     }
index 161e611a3f1b68b7f251c395c0604f42f2856e22..5ba3839c8c3862e5178816dd0ca58270a229e1c4 100644 (file)
@@ -84,7 +84,6 @@ play_update(screen_t *screen, mpd_client_t *c)
 int
 play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
 {
-  char buf[256];
   mpd_Song *song;
 
   switch(cmd)
@@ -94,10 +93,9 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
       file_clear_highlight(c, song);
       mpd_sendDeleteCommand(c->connection, screen->playlist->selected);
       mpd_finishCommand(c->connection);
-      snprintf(buf, 256,
-              "Removed \'%s\' from playlist!",
-              mpc_get_song_name(song));               
-      screen_status_message(c, buf);
+      screen_status_printf(c, 
+                          "Removed \'%s\' from playlist!",
+                          mpc_get_song_name(song));
       break;
     case CMD_LIST_PREVIOUS:
       list_window_previous(screen->playlist);
@@ -122,6 +120,29 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
       list_window_previous_page(screen->playlist);
       screen->playlist->repaint  = 1;
       break;
+    case CMD_LIST_FIND:
+      if( screen->findbuf )
+       {
+         free(screen->findbuf);
+         screen->findbuf=NULL;
+       }
+      /* fall throw... */
+    case CMD_LIST_FIND_NEXT:
+      if( !screen->findbuf )
+       screen->findbuf=screen_readln(screen->status_window.w, "/");
+      if( list_window_find(screen->playlist,
+                          list_callback,
+                          c,
+                          screen->findbuf) == 0 )
+       {
+         screen->playlist->repaint  = 1;
+       }
+      else
+       {
+         screen_status_printf(c, "Unable to find \'%s\'", screen->findbuf);
+         beep();
+       }
+      break;
     default:
       return 0;
     }
index e100cbf5217b6045c9373b0a06e581e7fb760fc8..1647fffbb75d8b06facfabd523acfe5182b0ddbf 100644 (file)
@@ -13,6 +13,9 @@
 #include "command.h"
 #include "screen.h"
 
+#if 0
+#include <readline/readline.h>
+#endif
 
 
 list_window_t *
@@ -150,3 +153,51 @@ list_window_previous_page(list_window_t *lw)
   else
     list_window_first(lw);
 }
+
+int
+list_window_find(list_window_t *lw, 
+                list_window_callback_fn_t callback,
+                void *callback_data,
+                char *str)
+{
+  int i = lw->selected+1;
+
+  while( i< lw->rows )
+    {
+      int h;
+      char *label = (callback) (i,&h,callback_data);
+      
+      if( str && label && strstr(label, str) )
+       {
+         lw->selected = i;
+         return 0;
+       }
+      i++;
+    }
+  return 1;
+}
+
+
+char *
+screen_readln(WINDOW *w, char *prompt)
+{
+  char buf[256], *line = NULL;
+  int prompt_len = strlen(prompt);
+
+  wclear(w);  
+  wmove(w, 0, 0);
+  waddstr(w, prompt);
+  wmove(w, 0, prompt_len);
+  
+  echo();
+  curs_set(1);
+
+  if( wgetnstr(w, buf, 256) == OK )
+    line = strdup(buf);
+
+  noecho();
+  curs_set(0);
+
+  return line;
+}
+
index 7143832bf3c49d4c996f5d7574204426cfa61a4f..cddbe7e74f38d1595e23846ef2bbc5cc9fe4e601 100644 (file)
@@ -39,4 +39,10 @@ void list_window_first(list_window_t *lw);
 void list_window_last(list_window_t *lw, int length);
 void list_window_previous_page(list_window_t *lw);
 void list_window_next_page(list_window_t *lw, int length);
+int  list_window_find(list_window_t *lw, 
+                     list_window_callback_fn_t callback,
+                     void *callback_data,
+                     char *str);
 
+
+char *screen_readln(WINDOW *w, char *prompt);