#define SIZEOF_STR 1024 /* Default string size. */
#define SIZEOF_REF 256 /* Size of symbolic or SHA1 ID. */
+#define SIZEOF_REV 41 /* Holds a SHA-1 and an ending NUL */
#define SIZEOF_REVGRAPH 19 /* Size of revision ancestry graphics. */
/* This color name can be used to refer to the default term colors. */
struct ref {
char *name; /* Ref name; tag or head names are shortened. */
- char id[41]; /* Commit SHA1 ID */
+ char id[SIZEOF_REV]; /* Commit SHA1 ID */
unsigned int tag:1; /* Is it a tag? */
unsigned int next:1; /* For ref lists: are there more refs? */
};
{
struct line *line;
bool selected = (view->offset + lineno == view->lineno);
+ bool draw_ok;
assert(view_is_displayed(view));
wclrtoeol(view->win);
}
- return view->ops->draw(view, line, lineno, selected);
+ scrollok(view->win, FALSE);
+ draw_ok = view->ops->draw(view, line, lineno, selected);
+ scrollok(view->win, TRUE);
+
+ return draw_ok;
}
static void
static void
update_view_title(struct view *view)
{
- assert(view_is_displayed(view));
-
- if (view == display[current_view])
- wbkgdset(view->title, get_line_attr(LINE_TITLE_FOCUS));
- else
- wbkgdset(view->title, get_line_attr(LINE_TITLE_BLUR));
-
- werase(view->title);
- wmove(view->title, 0, 0);
+ char buf[SIZEOF_STR];
+ char state[SIZEOF_STR];
+ size_t bufpos = 0, statelen = 0;
- if (*view->ref)
- wprintw(view->title, "[%s] %s", view->name, view->ref);
- else
- wprintw(view->title, "[%s]", view->name);
+ assert(view_is_displayed(view));
if (view->lines || view->pipe) {
unsigned int view_lines = view->offset + view->height;
? MIN(view_lines, view->lines) * 100 / view->lines
: 0;
- wprintw(view->title, " - %s %d of %d (%d%%)",
- view->ops->type,
- view->lineno + 1,
- view->lines,
- lines);
+ string_format_from(state, &statelen, "- %s %d of %d (%d%%)",
+ view->ops->type,
+ view->lineno + 1,
+ view->lines,
+ lines);
+
+ if (view->pipe) {
+ time_t secs = time(NULL) - view->start_time;
+
+ /* Three git seconds are a long time ... */
+ if (secs > 2)
+ string_format_from(state, &statelen, " %lds", secs);
+ }
}
- if (view->pipe) {
- time_t secs = time(NULL) - view->start_time;
+ string_format_from(buf, &bufpos, "[%s]", view->name);
+ if (*view->ref && bufpos < view->width) {
+ size_t refsize = strlen(view->ref);
+ size_t minsize = bufpos + 1 + /* abbrev= */ 7 + 1 + statelen;
+
+ if (minsize < view->width)
+ refsize = view->width - minsize + 7;
+ string_format_from(buf, &bufpos, " %.*s", refsize, view->ref);
+ }
- /* Three git seconds are a long time ... */
- if (secs > 2)
- wprintw(view->title, " %lds", secs);
+ if (statelen && bufpos < view->width) {
+ string_format_from(buf, &bufpos, " %s", state);
}
+ if (view == display[current_view])
+ wbkgdset(view->title, get_line_attr(LINE_TITLE_FOCUS));
+ else
+ wbkgdset(view->title, get_line_attr(LINE_TITLE_BLUR));
+
+ werase(view->title);
+ mvwaddnstr(view->title, 0, 0, buf, bufpos);
wmove(view->title, 0, view->width - 1);
wrefresh(view->title);
}
}
static void
-update_display_cursor(void)
+update_display_cursor(struct view *view)
{
- struct view *view = display[current_view];
-
/* Move the cursor to the right-most column of the cursor line.
*
* XXX: This could turn out to be a bit expensive, but it ensures that
*/
struct commit {
- char id[41]; /* SHA1 ID. */
+ char id[SIZEOF_REV]; /* SHA1 ID. */
char title[75]; /* First line of the commit message. */
char author[75]; /* Author of the commit. */
struct tm time; /* Date from the author ident. */
}
update_view_title(view);
- update_display_cursor();
+ update_display_cursor(view);
}
/* Controls when nodelay should be in effect when polling user input. */