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__))
};
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;
}
/* 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) \
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 */
}
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);
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));
}
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
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;
}
}
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;
}
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))
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;
}
if (draw_lineno(view, lineno))
return TRUE;
- draw_text(view, LINE_DEFAULT, blame->text, TRUE);
+ draw_text(view, LINE_DEFAULT, blame->text);
return TRUE;
}
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;
}
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;
}
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;
}