ui/ncurses: implement global keys
authorJeremy Kerr <jk@ozlabs.org>
Fri, 17 May 2013 02:26:05 +0000 (10:26 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 21 May 2013 07:29:43 +0000 (15:29 +0800)
Add process_global_keys to handle global key events. Using this,
implement ctrl+l to refresh.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
ui/ncurses/nc-cui.c

index 3f8995eba809c92b46417e2c70be529dbab2fdc5..d091331b9656ce1a5635f08b73d64fd5b0e5fcbc 100644 (file)
@@ -199,6 +199,19 @@ struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr)
        return old;
 }
 
+static bool process_global_keys(struct cui *cui, int key)
+{
+       switch (key) {
+       case 0xc:
+               if (cui->current && cui->current->main_ncw) {
+                       redrawwin(cui->current->main_ncw);
+                       wrefresh(cui->current->main_ncw);
+               }
+               return true;
+       }
+       return false;
+}
+
 /**
  * cui_process_key - Process input on stdin.
  */
@@ -216,6 +229,9 @@ static int cui_process_key(void *arg)
                if (c == ERR)
                        break;
 
+               if (process_global_keys(cui, c))
+                       continue;
+
                cui->current->process_key(cui->current, c);
        }