summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 19d872a)
raw | patch | inline | side by side (parent: 19d872a)
author | Jonas Fonseca <fonseca@diku.dk> | |
Fri, 4 Apr 2008 17:22:58 +0000 (19:22 +0200) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 22 Apr 2008 12:30:12 +0000 (14:30 +0200) |
Do it in the draw_* functions instead of all the view draw functions.
tig.c | patch | blob | history |
index 1ea408b3387dc04231d5476d02158601a92b22d8..9e4d7938adc51e73c4e2f56150c29e4bc11750ce 100644 (file)
--- a/tig.c
+++ b/tig.c
/* Drawing */
struct line *curline; /* Line currently being drawn. */
enum line_type curtype; /* Attribute currently used for drawing. */
+ unsigned long col; /* Column when drawing. */
/* Loading */
FILE *pipe;
}
static int
-draw_text(struct view *view, enum line_type type, const char *string,
- int max_len, bool use_tilde)
+draw_chars(struct view *view, enum line_type type, const char *string,
+ int max_len, bool use_tilde)
{
int len = 0;
int col = 0;
while (spaces > 0) {
int len = MIN(spaces, sizeof(space) - 1);
- col += draw_text(view, type, space, spaces, FALSE);
+ col += draw_chars(view, type, space, spaces, FALSE);
spaces -= len;
}
return col;
}
-static int
-draw_lineno(struct view *view, unsigned int lineno, int max)
+static bool
+draw_lineno(struct view *view, unsigned int lineno)
{
- static char fmt[] = "%1ld";
- char number[10] = " ";
+ char number[10];
int digits3 = view->digits < 3 ? 3 : view->digits;
int max_number = MIN(digits3, STRING_SIZE(number));
- bool showtrimmed = FALSE;
+ int max = view->width - view->col;
int col;
+ if (max < max_number)
+ max_number = max;
+
lineno += view->offset + 1;
if (lineno == 1 || (lineno % opt_num_interval) == 0) {
+ static char fmt[] = "%1ld";
+
if (view->digits <= 9)
fmt[1] = '0' + digits3;
if (!string_format(number, fmt, lineno))
number[0] = 0;
- showtrimmed = TRUE;
+ col = draw_chars(view, LINE_LINE_NUMBER, number, max_number, TRUE);
+ } else {
+ col = draw_space(view, LINE_LINE_NUMBER, max_number, max_number);
}
- if (max < max_number)
- max_number = max;
-
- col = draw_text(view, LINE_LINE_NUMBER, number, max_number, showtrimmed);
if (col < max) {
set_view_attr(view, LINE_DEFAULT);
waddch(view->win, line_graphics[LINE_GRAPHIC_VLINE]);
col++;
}
- if (col < max) {
- waddch(view->win, ' ');
- col++;
- }
- return col;
+ if (col < max)
+ col += draw_space(view, LINE_DEFAULT, max - col, 1);
+ view->col += col;
+
+ return view->width - view->col <= 0;
}
-static int
-draw_graphic(struct view *view, enum line_type type, chtype graphic[], size_t size, size_t max)
+static bool
+draw_text(struct view *view, enum line_type type, const char *string, bool trim)
+{
+ view->col += draw_chars(view, type, string, view->width - view->col, trim);
+ return view->width - view->col <= 0;
+}
+
+static bool
+draw_graphic(struct view *view, enum line_type type, chtype graphic[], size_t size)
{
+ int max = view->width - view->col;
int i;
- int col;
if (max < size)
size = max;
@@ -1586,32 +1596,32 @@ draw_graphic(struct view *view, enum line_type type, chtype graphic[], size_t si
for (i = 0; i < size; i++)
waddch(view->win, graphic[i]);
- col = size;
+ view->col += size;
if (size < max) {
waddch(view->win, ' ');
- col++;
+ view->col++;
}
- return col;
+ return view->width - view->col <= 0;
}
-static int
-draw_field(struct view *view, enum line_type type, char *text, int len, int max_len, bool trim)
+static bool
+draw_field(struct view *view, enum line_type type, char *text, int len, bool trim)
{
- int max = MIN(max_len, len);
+ int max = MIN(view->width - view->col, len);
int col;
if (text)
- col = draw_text(view, type, text, max - 1, trim);
+ col = draw_chars(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;
+ view->col += col + draw_space(view, LINE_DEFAULT, max - col, max - col);
+ return view->width - view->col <= 0;
}
-static int
-draw_date(struct view *view, struct tm *time, int max)
+static bool
+draw_date(struct view *view, struct tm *time)
{
char buf[DATE_COLS];
char *date;
timelen = strftime(buf, sizeof(buf), DATE_FORMAT, time);
date = timelen ? buf : NULL;
- return draw_field(view, LINE_DATE, date, DATE_COLS, max, FALSE);
+ return draw_field(view, LINE_DATE, date, DATE_COLS, FALSE);
}
static bool
line = &view->line[view->offset + lineno];
wmove(view->win, lineno, 0);
+ view->col = 0;
view->curline = line;
view->curtype = LINE_NONE;
line->selected = FALSE;
pager_draw(struct view *view, struct line *line, unsigned int lineno)
{
char *text = line->data;
- int col = 0;
- if (opt_line_number) {
- col += draw_lineno(view, lineno, view->width);
- if (col >= view->width)
- return TRUE;
- }
+ if (opt_line_number && draw_lineno(view, lineno))
+ return TRUE;
- draw_text(view, line->type, text, view->width - col, TRUE);
+ draw_text(view, line->type, text, TRUE);
return TRUE;
}
struct blame *blame = line->data;
struct tm *time = NULL;
char *id = NULL, *author = NULL;
- int col = 0;
if (blame->commit && *blame->commit->filename) {
id = blame->commit->id;
time = &blame->commit->time;
}
- if (opt_date) {
- col += draw_date(view, time, view->width);
- if (col >= view->width)
- return TRUE;
- }
-
- if (opt_author) {
- int max = view->width - col;
-
- col += draw_field(view, LINE_MAIN_AUTHOR, author, AUTHOR_COLS, max, TRUE);
- if (col >= view->width)
- return TRUE;
- }
+ if (opt_date && draw_date(view, time))
+ return TRUE;
- {
- int max = view->width - col;
+ if (opt_author &&
+ draw_field(view, LINE_MAIN_AUTHOR, author, AUTHOR_COLS, TRUE))
+ return TRUE;
- col += draw_field(view, LINE_BLAME_ID, id, ID_COLS, max, FALSE);
- if (col >= view->width)
- return TRUE;
- }
+ if (draw_field(view, LINE_BLAME_ID, id, ID_COLS, FALSE))
+ return TRUE;
- col += draw_lineno(view, lineno, view->width - col);
- if (col >= view->width)
+ if (draw_lineno(view, lineno))
return TRUE;
- col += draw_text(view, LINE_DEFAULT, blame->text, view->width - col, TRUE);
+ draw_text(view, LINE_DEFAULT, blame->text, TRUE);
return TRUE;
}
struct status *status = line->data;
enum line_type type;
char *text;
- int col = 0;
if (!status) {
switch (line->type) {
} else {
char buf[] = { status->status, ' ', ' ', ' ', 0 };
- col += draw_text(view, line->type, buf, view->width, TRUE);
+ if (draw_text(view, line->type, buf, TRUE))
+ return TRUE;
type = LINE_DEFAULT;
text = status->new.name;
}
- draw_text(view, type, text, view->width - col, TRUE);
+ draw_text(view, type, text, TRUE);
return TRUE;
}
main_draw(struct view *view, struct line *line, unsigned int lineno)
{
struct commit *commit = line->data;
- int col = 0;
if (!*commit->author)
return FALSE;
- if (opt_date) {
- col += draw_date(view, &commit->time, view->width);
- if (col >= view->width)
- return TRUE;
- }
-
- if (opt_author) {
- int max = view->width - col;
+ if (opt_date && draw_date(view, &commit->time))
+ return TRUE;
- col += draw_field(view, LINE_MAIN_AUTHOR, commit->author, AUTHOR_COLS, max, TRUE);
- if (col >= view->width)
- return TRUE;
- }
+ if (opt_author &&
+ draw_field(view, LINE_MAIN_AUTHOR, commit->author, AUTHOR_COLS, TRUE))
+ return TRUE;
- if (opt_rev_graph && commit->graph_size) {
- col += draw_graphic(view, LINE_MAIN_REVGRAPH,
- commit->graph, commit->graph_size,
- view->width - col);
- if (col >= view->width)
- return TRUE;
- }
+ if (opt_rev_graph && commit->graph_size &&
+ draw_graphic(view, LINE_MAIN_REVGRAPH, commit->graph, commit->graph_size))
+ return TRUE;
if (opt_show_refs && commit->refs) {
size_t i = 0;
else
type = LINE_MAIN_REF;
- col += draw_text(view, type, "[", view->width - col, TRUE);
- col += draw_text(view, type, commit->refs[i]->name, view->width - col, TRUE);
- col += draw_text(view, type, "]", view->width - col, TRUE);
+ if (draw_text(view, type, "[", TRUE) ||
+ draw_text(view, type, commit->refs[i]->name, TRUE) ||
+ draw_text(view, type, "]", TRUE))
+ return TRUE;
- col += draw_text(view, LINE_DEFAULT, " ", view->width - col, TRUE);
- if (col >= view->width)
+ if (draw_text(view, LINE_DEFAULT, " ", TRUE))
return TRUE;
} while (commit->refs[i++]->next);
}
- draw_text(view, LINE_DEFAULT, commit->title, view->width - col, TRUE);
+ draw_text(view, LINE_DEFAULT, commit->title, TRUE);
return TRUE;
}