summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3485ce2)
raw | patch | inline | side by side (parent: 3485ce2)
author | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 22 Apr 2008 12:08:34 +0000 (14:08 +0200) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 22 Apr 2008 12:27:36 +0000 (14:27 +0200) |
It will draw spaces if the passed string is NULL.
tig.c | patch | blob | history |
index d9bd9da7f8327627986a664fb8d6aeae8d0f8e8f..7144fdbbebc546be3e5600eaad5d07f08e364125 100644 (file)
--- a/tig.c
+++ b/tig.c
return len;
}
+static int
+draw_space(struct view *view, enum line_type type, int max, int spaces)
+{
+ static char space[] = " ";
+ int col = 0;
+
+ spaces = MIN(max, spaces);
+
+ while (spaces > 0) {
+ int len = MIN(spaces, sizeof(space) - 1);
+
+ col += draw_text(view, type, space, spaces, FALSE);
+ spaces -= len;
+ }
+
+ return col;
+}
+
static int
draw_lineno(struct view *view, unsigned int lineno, int max)
{
@@ -1576,30 +1594,33 @@ draw_graphic(struct view *view, enum line_type type, chtype graphic[], size_t si
return col;
}
+static int
+draw_field(struct view *view, enum line_type type, char *text, int len, int max_len, bool trim)
+{
+ int max = MIN(max_len, len);
+ int col;
+
+ if (text)
+ col = draw_text(view, type, text, max - 1, trim);
+ else
+ col = draw_space(view, type, max - 1, max - 1);
+
+ col += draw_space(view, LINE_DEFAULT, max - col, max - col);
+ return col;
+}
+
static int
draw_date(struct view *view, struct tm *time, int max)
{
char buf[DATE_COLS];
- int col;
+ char *date;
int timelen = 0;
- if (max > DATE_COLS)
- max = DATE_COLS;
if (time)
timelen = strftime(buf, sizeof(buf), DATE_FORMAT, time);
- if (!timelen) {
- memset(buf, ' ', sizeof(buf) - 1);
- buf[sizeof(buf) - 1] = 0;
- }
+ date = timelen ? buf : NULL;
- col = draw_text(view, LINE_DATE, buf, max, FALSE);
- if (col < max) {
- set_view_attr(view, LINE_DEFAULT);
- waddch(view->win, ' ');
- col++;
- }
-
- return col;
+ return draw_field(view, LINE_DATE, date, DATE_COLS, max, FALSE);
}
static bool
}
{
- int max = MIN(ID_COLS - 1, view->width - col);
+ int max = view->width - col;
- set_view_attr(view, LINE_BLAME_ID);
- if (id)
- draw_text(view, LINE_BLAME_ID, id, max, FALSE);
- col += ID_COLS;
+ col += draw_field(view, LINE_BLAME_ID, id, ID_COLS, max, FALSE);
if (col >= view->width)
return TRUE;
- wmove(view->win, lineno, col);
}
col += draw_lineno(view, lineno, view->width - col);