[vitunes] Re: [PATCH] add visual mode to vitunes

  • From: Ryan Flannery <ryan.flannery@xxxxxxxxx>
  • To: vitunes@xxxxxxxxxxxxx
  • Date: Thu, 10 Feb 2011 20:13:12 -0500

On Thu, Feb 10, 2011 at 8:03 PM, Ryan Flannery <ryan.flannery@xxxxxxxxx> wrote:
> Hi Daniel,
>
> On Thu, Feb 10, 2011 at 7:40 PM, Ryan Flannery <ryan.flannery@xxxxxxxxx> 
> wrote:
>> Hi Daniel!
>>
>> On Thu, Feb 10, 2011 at 7:18 PM, Daniel Walter <sahne> wrote:
>>> Hi all,
>>>
>>> I've hacked a visual mode patch for vitunes, which allows you to vim like 
>>> select files within a playlist and
>>> copy or delete/cut them.
>>
>> Sweeeeet!  I've been wanting something like this for a while!
>>
>>> It basically works like visual mode in vim, so you enable it via 'V' and 
>>> use either 'UP'/'DOWN' or 'j'/'k' to
>>> select the files you like to copy or delete.
>>>
>>> In this first version the is no support for jumping to the beginning or end 
>>> of a list, but I'm planning to
>>> integrate this within a few days.
>>
>> Hmm.. I'm thinking there might be an easier way to add support for all
>> of these (like gg, G, ^u, ^d, 123G, etc.), in one shot.
>>
>> What about the following:
>>
>> In the kba_visual, just do:
>> if (visual_selection_start == -1)
>>     visual_selection_start = ui.active->voffset + ui.active->crow;
>> else
>>     visual_selection_start = -1;
>>
>>
>> The visual_selection_end, I think, could always just be:
>>     ui.active->voffset + ui.active->crow;
>> so I wouldn't even track that.... just let the other keybinding
>> handlers modify that as they normally do.
>>
>>
>> In the paint code, a row gets the A_REVERSE wattron'd if and only if
>> the row is between
>>     visual_selection_start
>> and
>>     ui.active->voffset + ui.active->crow;
>> and the visual_selection_start is != -1 of course.
>>
>>
>> With that, yank could then be updated to use the
>> visual_selection_start (if != -1) and current row to get the
>> yank-portion.
>>
>>
>> Thoughts?
>>
>
> Attached is a diff with just the tracking and painting, which is
> rough, but I think it illustrates what I'm talking about.
>

And it appears freelists.org stripped my patch....  Here it is:



diff -r 3418951e8398 keybindings.c
--- a/keybindings.c     Thu Feb 10 16:46:22 2011 -0500
+++ b/keybindings.c     Thu Feb 10 20:00:34 2011 -0500
@@ -45,6 +45,7 @@
    { search_backward,         "search_backward" },
    { find_next_forward,       "find_next_forward" },
    { find_next_backward,      "find_next_backward" },
+   { visual,                  "visual" },
    { cut,                     "cut" },
    { yank,                    "yank" },
    { paste_after,             "paste_after" },
@@ -103,6 +104,7 @@
    {  search_backward,        kba_search,       { .direction = BACKWARDS }},
    {  find_next_forward,      kba_search_find,  { .direction = SAME }},
    {  find_next_backward,     kba_search_find,  { .direction = OPPOSITE }},
+   {  visual,                 kba_visual,       ARG_NOT_USED },
    {  cut,                    kba_cut,          ARG_NOT_USED },
    {  yank,                   kba_yank,         ARG_NOT_USED },
    {  paste_after,            kba_paste,        { .placement = AFTER }},
@@ -174,6 +176,8 @@
    { '?',               search_backward },
    { 'n',               find_next_forward },
    { 'N',               find_next_backward },
+   { 'v',               visual },
+   { 'V',               visual },
    { 'd',               cut },
    { 'y',               yank },
    { 'p',               paste_after },
@@ -873,6 +877,23 @@
    paint_error("Pattern not found: %s", mi_query_getraw());
 }

+
+void
+kba_visual(KbaArgs a UNUSED)
+{
+   if (ui.active == ui.library) {
+      paint_message("No visual mode in library window.  Sorry.");
+      return;
+   }
+
+   if (visual_mode_start == -1)
+      visual_mode_start = ui.active->voffset + ui.active->crow;
+   else
+      visual_mode_start = -1;
+
+   paint_playlist();
+}
+
 /*
  * TODO so much of the logic in cut() is similar with that of yank() above.
  * combine the two, use an Args parameter to determine if the operation is
diff -r 3418951e8398 keybindings.h
--- a/keybindings.h     Thu Feb 10 16:46:22 2011 -0500
+++ b/keybindings.h     Thu Feb 10 20:00:34 2011 -0500
@@ -56,6 +56,7 @@
    find_next_forward,
    find_next_backward,
    /* copy/cut/paste & undo/redo */
+   visual,
    cut,
    yank,
    paste_after,
@@ -126,6 +127,7 @@
 void kba_search(KbaArgs a);
 void kba_search_find(KbaArgs a);

+void kba_visual(KbaArgs a);
 void kba_cut(KbaArgs a);
 void kba_yank(KbaArgs a);
 void kba_paste(KbaArgs a);
diff -r 3418951e8398 paint.c
--- a/paint.c   Thu Feb 10 16:46:22 2011 -0500
+++ b/paint.c   Thu Feb 10 20:00:34 2011 -0500
@@ -271,6 +271,7 @@
 {
    playlist   *plist;
    bool        hasinfo;
+   bool        visual;
    char       *str;
    int         findex, row, col, colwidth;
    int         xoff, hoff, strhoff;
@@ -287,13 +288,22 @@
       /* get index of file to show */
       findex = row + ui.playlist->voffset;

+      /* determine if visual mode row */
+      visual = false;
+      if (visual_mode_start != -1 && ui.active == ui.playlist) {
+         if (visual_mode_start <= findex && findex <=
ui.active->voffset + ui.active->crow)
+            visual = true;
+         if (ui.active->voffset + ui.active->crow <= findex && findex
<= visual_mode_start)
+            visual = true;
+      }
+
       /* apply row attributes */
        wattron(ui.playlist->cwin, COLOR_PAIR(colors.playlist));

       if (plist == playing_playlist && findex == player.qidx)
          wattron(ui.playlist->cwin, COLOR_PAIR(colors.playing_playlist));

-      if (row == ui.playlist->crow && ui.active == ui.playlist)
+      if ((row == ui.playlist->crow && ui.active == ui.playlist) || visual)
          wattron(ui.playlist->cwin, A_REVERSE);

       if (findex >= plist->nfiles)
@@ -392,7 +402,7 @@
       if (findex >= plist->nfiles)
          wattroff(ui.playlist->cwin, COLOR_PAIR(colors.tildas_playlist));

-      if (row == ui.playlist->crow && ui.active == ui.playlist)
+      if ((row == ui.playlist->crow && ui.active == ui.playlist) || visual)
          wattroff(ui.playlist->cwin, A_REVERSE);

       if (plist == playing_playlist && findex == player.qidx)
diff -r 3418951e8398 vitunes.c
--- a/vitunes.c Thu Feb 10 16:46:22 2011 -0500
+++ b/vitunes.c Thu Feb 10 20:00:34 2011 -0500
@@ -26,6 +26,9 @@
 playlist *viewing_playlist;
 playlist *playing_playlist;

+/* visual mode start position */
+int visual_mode_start = -1;
+
 /* signal flags */
 volatile sig_atomic_t VSIG_QUIT = 0;            /* 1 = quit vitunes */
 volatile sig_atomic_t VSIG_RESIZE = 0;          /* 1 = resize display */
diff -r 3418951e8398 vitunes.h
--- a/vitunes.h Thu Feb 10 16:46:22 2011 -0500
+++ b/vitunes.h Thu Feb 10 20:00:34 2011 -0500
@@ -44,6 +44,7 @@
 /* record keeping  */
 extern playlist   *viewing_playlist;
 extern playlist   *playing_playlist;
+extern int         visual_mode_start;

 /* signal flags referenced elsewhere */
 extern volatile sig_atomic_t VSIG_QUIT;

Other related posts: