summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 43fec22)
raw | patch | inline | side by side (parent: 43fec22)
author | Jonas Fonseca <fonseca@diku.dk> | |
Sat, 12 Mar 2011 00:24:36 +0000 (19:24 -0500) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Thu, 17 Mar 2011 01:18:54 +0000 (21:18 -0400) |
tig.c | patch | blob | history |
index c971ff754476630cbb858e6f9659ebf081cd9a19..e58a6b65f2f3e3c5e50f15c7c275f569fbdd11aa 100644 (file)
--- a/tig.c
+++ b/tig.c
#define VIEW_MAX_LEN(view) ((view)->width + (view)->yoffset - (view)->col)
-static int
+static bool
draw_chars(struct view *view, enum line_type type, const char *string,
int max_len, bool use_tilde)
{
size_t skip = view->yoffset > view->col ? view->yoffset - view->col : 0;
if (max_len <= 0)
- return 0;
+ return VIEW_MAX_LEN(view) <= 0;
len = utf8_length(&string, skip, &col, max_len, &trimmed, use_tilde, opt_tab_size);
}
}
- return col;
+ view->col += col;
+ return VIEW_MAX_LEN(view) <= 0;
}
-static int
+static bool
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_chars(view, type, space, len, FALSE);
+ if (draw_chars(view, type, space, len, FALSE))
+ return TRUE;
spaces -= len;
}
- return col;
+ return VIEW_MAX_LEN(view) <= 0;
}
static bool
do {
size_t pos = string_expand(text, sizeof(text), string, opt_tab_size);
- view->col += draw_chars(view, type, text, VIEW_MAX_LEN(view), TRUE);
+ if (draw_chars(view, type, text, VIEW_MAX_LEN(view), TRUE))
+ return TRUE;
string += pos;
- } while (*string && VIEW_MAX_LEN(view) > 0);
+ } while (*string);
return VIEW_MAX_LEN(view) <= 0;
}
draw_field(struct view *view, enum line_type type, const char *text, int len, bool trim)
{
int max = MIN(VIEW_MAX_LEN(view), len);
- int col;
+ int col = view->col;
- if (text)
- col = draw_chars(view, type, text, max - 1, trim);
- else
- col = draw_space(view, type, max - 1, max - 1);
+ if (!text)
+ return draw_space(view, type, max, max);
- view->col += col;
- view->col += draw_space(view, LINE_DEFAULT, max - col, max - col);
- return VIEW_MAX_LEN(view) <= 0;
+ return draw_chars(view, type, text, max - 1, trim)
+ || draw_space(view, LINE_DEFAULT, max - (view->col - col), max);
}
static bool
text = number;
}
if (text)
- view->col += draw_chars(view, LINE_LINE_NUMBER, text, max, TRUE);
+ draw_chars(view, LINE_LINE_NUMBER, text, max, TRUE);
else
- view->col += draw_space(view, LINE_LINE_NUMBER, max, digits3);
+ draw_space(view, LINE_LINE_NUMBER, max, digits3);
return draw_graphic(view, LINE_DEFAULT, &separator, 1, TRUE);
}