Code

Remove draw_text()s trim parameter
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index fd19f5403e8351618b37e2e1a97bcc1af9a6906b..8933e3092a47bc62860430f2fa920dce978eb4a5 100644 (file)
--- a/tig.c
+++ b/tig.c
 /* ncurses(3): Must be defined to have extended wide-character functions. */
 #define _XOPEN_SOURCE_EXTENDED
 
-#ifdef HAVE_NCURSESW_NCURSES_H
+#ifdef HAVE_NCURSESW_H
 #include <ncursesw/ncurses.h>
 #else
-#ifdef HAVE_NCURSES_NCURSES_H
-#include <ncurses/ncurses.h>
-#else
 #include <ncurses.h>
 #endif
-#endif
 
 #if __GNUC__ >= 3
 #define __NORETURN __attribute__((__noreturn__))
@@ -1920,24 +1916,21 @@ option_color_command(int argc, const char *argv[])
                };
                int index;
 
-               if (!map_enum(&index, obsolete, argv[0])) {
+               if (!map_enum(&index, obsolete, argv[0]))
                        return OPT_ERR_UNKNOWN_COLOR_NAME;
-               }
                info = &line_info[index];
        }
 
        if (!set_color(&info->fg, argv[1]) ||
-           !set_color(&info->bg, argv[2])) {
+           !set_color(&info->bg, argv[2]))
                return OPT_ERR_UNKNOWN_COLOR;
-       }
 
        info->attr = 0;
        while (argc-- > 3) {
                int attr;
 
-               if (!set_attribute(&attr, argv[argc])) {
+               if (!set_attribute(&attr, argv[argc]))
                        return OPT_ERR_UNKNOWN_ATTRIBUTE;
-               }
                info->attr |= attr;
        }
 
@@ -2208,6 +2201,8 @@ struct view_ops;
 
 /* The display array of active views and the index of the current view. */
 static struct view *display[2];
+static WINDOW *display_win[2];
+static WINDOW *display_title[2];
 static unsigned int current_view;
 
 #define foreach_displayed_view(view, i) \
@@ -2251,7 +2246,6 @@ struct view {
 
        int height, width;      /* The width and height of the main window */
        WINDOW *win;            /* The main window */
-       WINDOW *title;          /* The title window living below the main window */
 
        /* Navigation */
        unsigned long offset;   /* Offset of the window top */
@@ -2439,14 +2433,14 @@ draw_space(struct view *view, enum line_type type, int max, int spaces)
 }
 
 static bool
-draw_text(struct view *view, enum line_type type, const char *string, bool trim)
+draw_text(struct view *view, enum line_type type, const char *string)
 {
        char text[SIZEOF_STR];
 
        do {
                size_t pos = string_expand(text, sizeof(text), string, opt_tab_size);
 
-               view->col += draw_chars(view, type, text, view->width + view->yoffset - view->col, trim);
+               view->col += draw_chars(view, type, text, view->width + view->yoffset - view->col, TRUE);
                string += pos;
        } while (*string && view->width + view->yoffset > view->col);
 
@@ -2638,6 +2632,7 @@ update_view_title(struct view *view)
        char buf[SIZEOF_STR];
        char state[SIZEOF_STR];
        size_t bufpos = 0, statelen = 0;
+       WINDOW *window = display[0] == view ? display_title[0] : display_title[1];
 
        assert(view_is_displayed(view));
 
@@ -2678,13 +2673,13 @@ update_view_title(struct view *view)
        }
 
        if (view == display[current_view])
-               wbkgdset(view->title, get_line_attr(LINE_TITLE_FOCUS));
+               wbkgdset(window, get_line_attr(LINE_TITLE_FOCUS));
        else
-               wbkgdset(view->title, get_line_attr(LINE_TITLE_BLUR));
+               wbkgdset(window, get_line_attr(LINE_TITLE_BLUR));
 
-       mvwaddnstr(view->title, 0, 0, buf, bufpos);
-       wclrtoeol(view->title);
-       wnoutrefresh(view->title);
+       mvwaddnstr(window, 0, 0, buf, bufpos);
+       wclrtoeol(window);
+       wnoutrefresh(window);
 }
 
 static int
@@ -2728,23 +2723,25 @@ resize_display(void)
        offset = 0;
 
        foreach_displayed_view (view, i) {
-               if (!view->win) {
-                       view->win = newwin(view->height, 0, offset, 0);
-                       if (!view->win)
+               if (!display_win[i]) {
+                       display_win[i] = newwin(view->height, 0, offset, 0);
+                       if (!display_win[i])
                                die("Failed to create %s view", view->name);
 
-                       scrollok(view->win, FALSE);
+                       scrollok(display_win[i], FALSE);
 
-                       view->title = newwin(1, 0, offset + view->height, 0);
-                       if (!view->title)
+                       display_title[i] = newwin(1, 0, offset + view->height, 0);
+                       if (!display_title[i])
                                die("Failed to create title window");
 
                } else {
-                       wresize(view->win, view->height, view->width);
-                       mvwin(view->win,   offset, 0);
-                       mvwin(view->title, offset + view->height, 0);
+                       wresize(display_win[i], view->height, view->width);
+                       mvwin(display_win[i],   offset, 0);
+                       mvwin(display_title[i], offset + view->height, 0);
                }
 
+               view->win = display_win[i];
+
                offset += view->height + 1;
        }
 }
@@ -4046,7 +4043,7 @@ pager_draw(struct view *view, struct line *line, unsigned int lineno)
        if (opt_line_number && draw_lineno(view, lineno))
                return TRUE;
 
-       draw_text(view, line->type, line->data, TRUE);
+       draw_text(view, line->type, line->data);
        return TRUE;
 }
 
@@ -4670,7 +4667,7 @@ tree_draw(struct view *view, struct line *line, unsigned int lineno)
        struct tree_entry *entry = line->data;
 
        if (line->type == LINE_TREE_HEAD) {
-               if (draw_text(view, line->type, "Directory path /", TRUE))
+               if (draw_text(view, line->type, "Directory path /"))
                        return TRUE;
        } else {
                if (draw_mode(view, entry->mode))
@@ -4682,8 +4679,8 @@ tree_draw(struct view *view, struct line *line, unsigned int lineno)
                if (opt_date && draw_date(view, &entry->time))
                        return TRUE;
        }
-       if (draw_text(view, line->type, entry->name, TRUE))
-               return TRUE;
+
+       draw_text(view, line->type, entry->name);
        return TRUE;
 }
 
@@ -5172,7 +5169,7 @@ blame_draw(struct view *view, struct line *line, unsigned int lineno)
        if (draw_lineno(view, lineno))
                return TRUE;
 
-       draw_text(view, LINE_DEFAULT, blame->text, TRUE);
+       draw_text(view, LINE_DEFAULT, blame->text);
        return TRUE;
 }
 
@@ -5390,7 +5387,7 @@ branch_draw(struct view *view, struct line *line, unsigned int lineno)
        if (opt_author && draw_author(view, branch->author))
                return TRUE;
 
-       draw_text(view, type, branch->ref == &branch_all ? "All branches" : branch->ref->name, TRUE);
+       draw_text(view, type, branch->ref == &branch_all ? "All branches" : branch->ref->name);
        return TRUE;
 }
 
@@ -5859,13 +5856,13 @@ status_draw(struct view *view, struct line *line, unsigned int lineno)
                static char buf[] = { '?', ' ', ' ', ' ', 0 };
 
                buf[0] = status->status;
-               if (draw_text(view, line->type, buf, TRUE))
+               if (draw_text(view, line->type, buf))
                        return TRUE;
                type = LINE_DEFAULT;
                text = status->new.name;
        }
 
-       draw_text(view, type, text, TRUE);
+       draw_text(view, type, text);
        return TRUE;
 }
 
@@ -6817,17 +6814,17 @@ main_draw(struct view *view, struct line *line, unsigned int lineno)
                        else
                                type = LINE_MAIN_REF;
 
-                       if (draw_text(view, type, "[", TRUE) ||
-                           draw_text(view, type, ref->name, TRUE) ||
-                           draw_text(view, type, "]", TRUE))
+                       if (draw_text(view, type, "[") ||
+                           draw_text(view, type, ref->name) ||
+                           draw_text(view, type, "]"))
                                return TRUE;
 
-                       if (draw_text(view, LINE_DEFAULT, " ", TRUE))
+                       if (draw_text(view, LINE_DEFAULT, " "))
                                return TRUE;
                }
        }
 
-       draw_text(view, LINE_DEFAULT, commit->title, TRUE);
+       draw_text(view, LINE_DEFAULT, commit->title);
        return TRUE;
 }