Code

Refactor user input handling into separate function
authorJonas Fonseca <fonseca@diku.dk>
Sat, 17 Jan 2009 13:05:00 +0000 (14:05 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Wed, 21 Jan 2009 22:21:14 +0000 (23:21 +0100)
Fixes resizing while the prompt is open.

NEWS
tig.c

diff --git a/NEWS b/NEWS
index 9eb36d552066ef25ea18fd8719f6118f43109df7..59a36c487e0a3d4df88442a7515cfc5a9943fe49 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,11 @@ Release notes
 tig master
 ----------
 
+Incompatibilities:
+
+ - The screen-resize action has been deprecated. It had no real use for
+   users and was never meant to be exposed.
+
 Improvements:
 
  - Tree view: avoid flickering when updating.
diff --git a/tig.c b/tig.c
index 70845310300e9890d9d1ded8947fcc1ac281c234..32d2fb7d8a143a06883cc29523575ac9f99a5f7a 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -709,7 +709,6 @@ static int read_properties(struct io *io, const char *separators, int (*read)(ch
        REQ_GROUP("Misc") \
        REQ_(PROMPT,            "Bring up the prompt"), \
        REQ_(SCREEN_REDRAW,     "Redraw the screen"), \
-       REQ_(SCREEN_RESIZE,     "Resize the screen"), \
        REQ_(SHOW_VERSION,      "Show version information"), \
        REQ_(STOP_LOADING,      "Stop all loading views"), \
        REQ_(EDIT,              "Open in editor"), \
@@ -1116,9 +1115,6 @@ static struct keybinding default_keybindings[] = {
        { '@',          REQ_STAGE_NEXT },
        { ',',          REQ_TREE_PARENT },
        { 'e',          REQ_EDIT },
-
-       /* Using the ncurses SIGWINCH handler. */
-       { KEY_RESIZE,   REQ_SCREEN_RESIZE },
 };
 
 #define KEYMAP_INFO \
@@ -1552,7 +1548,7 @@ option_bind_command(int argc, const char *argv[])
 
        request = get_request(argv[2]);
        if (request == REQ_NONE) {
-               const char *obsolete[] = { "cherry-pick" };
+               const char *obsolete[] = { "cherry-pick", "screen-resize" };
                size_t namelen = strlen(argv[2]);
                int i;
 
@@ -3184,9 +3180,6 @@ view_driver(struct view *view, enum request request)
                report("tig-%s (built %s)", TIG_VERSION, __DATE__);
                return TRUE;
 
-       case REQ_SCREEN_RESIZE:
-               resize_display();
-               /* Fall-through */
        case REQ_SCREEN_REDRAW:
                redraw_display(TRUE);
                break;
@@ -5928,32 +5921,61 @@ init_display(void)
        }
 }
 
-static bool
-prompt_yesno(const char *prompt)
+static int
+get_input(bool prompting)
 {
-       enum { WAIT, STOP, CANCEL  } status = WAIT;
-       bool answer = FALSE;
-
-       while (status == WAIT) {
-               struct view *view;
-               int i, key;
+       struct view *view;
+       int i, key;
 
+       if (prompting)
                input_mode = TRUE;
 
+       while (true) {
                foreach_view (view, i)
                        update_view(view);
 
-               input_mode = FALSE;
+               /* Refresh, accept single keystroke of input */
+               key = wgetch(status_win);
+
+               /* wgetch() with nodelay() enabled returns ERR when
+                * there's no input. */
+               if (key == ERR) {
+                       doupdate();
+
+               } else if (key == KEY_RESIZE) {
+                       int height, width;
+
+                       getmaxyx(stdscr, height, width);
+
+                       /* Resize the status view and let the view driver take
+                        * care of resizing the displayed views. */
+                       resize_display();
+                       redraw_display(TRUE);
+                       wresize(status_win, 1, width);
+                       mvwin(status_win, height - 1, 0);
+                       wrefresh(status_win);
+
+               } else {
+                       input_mode = FALSE;
+                       return key;
+               }
+       }
+}
+
+static bool
+prompt_yesno(const char *prompt)
+{
+       enum { WAIT, STOP, CANCEL  } status = WAIT;
+       bool answer = FALSE;
+
+       while (status == WAIT) {
+               int key;
 
                mvwprintw(status_win, 0, 0, "%s [Yy]/[Nn]", prompt);
                wclrtoeol(status_win);
 
-               /* Refresh, accept single keystroke of input */
-               key = wgetch(status_win);
+               key = get_input(TRUE);
                switch (key) {
-               case ERR:
-                       break;
-
                case 'y':
                case 'Y':
                        answer = TRUE;
@@ -5988,21 +6010,12 @@ read_prompt(const char *prompt)
        int pos = 0;
 
        while (status == READING) {
-               struct view *view;
-               int i, key;
-
-               input_mode = TRUE;
-
-               foreach_view (view, i)
-                       update_view(view);
-
-               input_mode = FALSE;
+               int key;
 
                mvwprintw(status_win, 0, 0, "%s%.*s", prompt, pos, buf);
                wclrtoeol(status_win);
 
-               /* Refresh, accept single keystroke of input */
-               key = wgetch(status_win);
+               key = get_input(TRUE);
                switch (key) {
                case KEY_RETURN:
                case KEY_ENTER:
@@ -6021,9 +6034,6 @@ read_prompt(const char *prompt)
                        status = CANCEL;
                        break;
 
-               case ERR:
-                       break;
-
                default:
                        if (pos >= sizeof(buf)) {
                                report("Input string too long");
@@ -6464,23 +6474,9 @@ main(int argc, const char *argv[])
        }
 
        while (view_driver(display[current_view], request)) {
-               int key;
-               int i;
+               int key = get_input(FALSE);
 
-               foreach_view (view, i)
-                       update_view(view);
                view = display[current_view];
-
-               /* Refresh, accept single keystroke of input */
-               key = wgetch(status_win);
-
-               /* wgetch() with nodelay() enabled returns ERR when there's no
-                * input. */
-               if (key == ERR) {
-                       request = REQ_NONE;
-                       continue;
-               }
-
                request = get_keybinding(view->keymap, key);
 
                /* Some low-level request handling. This keeps access to
@@ -6524,19 +6520,6 @@ main(int argc, const char *argv[])
                                request = REQ_NONE;
                        break;
                }
-               case REQ_SCREEN_RESIZE:
-               {
-                       int height, width;
-
-                       getmaxyx(stdscr, height, width);
-
-                       /* Resize the status view and let the view driver take
-                        * care of resizing the displayed views. */
-                       wresize(status_win, 1, width);
-                       mvwin(status_win, height - 1, 0);
-                       wrefresh(status_win);
-                       break;
-               }
                default:
                        break;
                }