Improve title updating and remove flickering
[tig] / tig.c
diff --git a/tig.c b/tig.c
index 4ab9434..52abe0f 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -646,6 +646,7 @@ static unsigned int current_view;
 #define foreach_view(view, i) \
        for (i = 0; i < ARRAY_SIZE(display) && (view = display[i]); i++)
 
+#define displayed_views()      (display[1] != NULL ? 2 : 1)
 
 /**
  * Current head and commit ID
@@ -806,14 +807,27 @@ update_view_title(struct view *view)
        else
                wprintw(view->title, "[%s]", view->name);
 
-       if (view->lines) {
+       if (view->lines || view->pipe) {
+               unsigned int lines = view->lines
+                                  ? (view->lineno + 1) * 100 / view->lines
+                                  : 0;
+
                wprintw(view->title, " - %s %d of %d (%d%%)",
                        view->ops->type,
                        view->lineno + 1,
                        view->lines,
-                       (view->lineno + 1) * 100 / view->lines);
+                       lines);
+       }
+
+       if (view->pipe) {
+               time_t secs = time(NULL) - view->start_time;
+
+               /* Three git seconds are a long time ... */
+               if (secs > 2)
+                       wprintw(view->title, " %lds", secs);
        }
 
+
        wrefresh(view->title);
 }
 
@@ -847,11 +861,8 @@ resize_display(void)
        offset = 0;
 
        foreach_view (view, i) {
-               /* Keep the height of all view->win windows one larger than is
-                * required so that the cursor can wrap-around on the last line
-                * without scrolling the window. */
                if (!view->win) {
-                       view->win = newwin(view->height + 1, 0, offset, 0);
+                       view->win = newwin(view->height, 0, offset, 0);
                        if (!view->win)
                                die("Failed to create %s view", view->name);
 
@@ -862,7 +873,7 @@ resize_display(void)
                                die("Failed to create title window");
 
                } else {
-                       wresize(view->win, view->height + 1, view->width);
+                       wresize(view->win, view->height, view->width);
                        mvwin(view->win,   offset, 0);
                        mvwin(view->title, offset + view->height, 0);
                        wrefresh(view->win);
@@ -1216,8 +1227,6 @@ update_view(struct view *view)
                goto end;
 
        } else if (feof(view->pipe)) {
-               time_t secs = time(NULL) - view->start_time;
-
                if (view == VIEW(REQ_VIEW_HELP)) {
                        const char *msg = TIG_HELP;
 
@@ -1232,8 +1241,7 @@ update_view(struct view *view)
                        goto end;
                }
 
-               report("Loaded %d lines in %ld second%s", view->lines, secs,
-                      secs == 1 ? "" : "s");
+               report("");
                goto end;
        }
 
@@ -1261,7 +1269,8 @@ open_view(struct view *prev, enum request request, enum open_flags flags)
        bool split = !!(flags & OPEN_SPLIT);
        bool reload = !!(flags & OPEN_RELOAD);
        struct view *view = VIEW(request);
-       int nviews = display[1] ? 2 : 1;
+       int nviews = displayed_views();
+       struct view *base_view = display[0];
 
        if (view == prev && nviews == 1 && !reload) {
                report("Already in %s view", view->name);
@@ -1285,7 +1294,10 @@ open_view(struct view *prev, enum request request, enum open_flags flags)
                display[current_view] = view;
        }
 
-       if (nviews == 1 || display[1] == NULL)
+       /* Resize the view when switching between split- and full-screen,
+        * or when switching between two different full-screen views. */
+       if (nviews != displayed_views() ||
+           (nviews == 1 && base_view != display[0]))
                resize_display();
 
        if (split && prev->lineno - prev->offset >= prev->height) {
@@ -1312,7 +1324,7 @@ open_view(struct view *prev, enum request request, enum open_flags flags)
                /* Clear the old view and let the incremental updating refill
                 * the screen. */
                wclear(view->win);
-               report("Loading...");
+               report("");
        } else {
                redraw_view(view);
                if (view == VIEW(REQ_VIEW_HELP))
@@ -1389,7 +1401,7 @@ view_driver(struct view *view, enum request request)
 
        case REQ_VIEW_NEXT:
        {
-               int nviews = display[1] ? 2 : 1;
+               int nviews = displayed_views();
                int next_view = (current_view + 1) % nviews;
 
                if (next_view == current_view) {
@@ -1988,7 +2000,7 @@ unicode_width(unsigned long c)
            || c == 0x2329
            || c == 0x232a
            || (c >= 0x2e80  && c <= 0xa4cf && c != 0x303f)
-                                               /* CJK ... Yi */
+                                               /* CJK ... Yi */
            || (c >= 0xac00  && c <= 0xd7a3)    /* Hangul Syllables */
            || (c >= 0xf900  && c <= 0xfaff)    /* CJK Compatibility Ideographs */
            || (c >= 0xfe30  && c <= 0xfe6f)    /* CJK Compatibility Forms */
@@ -2572,6 +2584,9 @@ main(int argc, char *argv[])
  *   outside the current view causing bad wrapping. Same goes
  *   for title and status windows.
  *
+ * - The cursor can wrap-around on the last line and cause the
+ *   window to scroll.
+ *
  * TODO
  * ----
  * Features that should be explored.