From: Jonas Fonseca Date: Tue, 22 Apr 2008 11:18:48 +0000 (+0200) Subject: Refactor revgraph drawing into draw_graphic() X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3485ce24442160d83a37752046438761f254c477;p=tig.git Refactor revgraph drawing into draw_graphic() --- diff --git a/tig.c b/tig.c index 88e3220..d9bd9da 100644 --- a/tig.c +++ b/tig.c @@ -1552,6 +1552,30 @@ draw_lineno(struct view *view, unsigned int lineno, int max) return col; } +static int +draw_graphic(struct view *view, enum line_type type, chtype graphic[], size_t size, size_t max) +{ + int i; + int col; + + if (max < size) + size = max; + + set_view_attr(view, type); + /* Using waddch() instead of waddnstr() ensures that + * they'll be rendered correctly for the cursor line. */ + for (i = 0; i < size; i++) + waddch(view->win, graphic[i]); + + col = size; + if (size < max) { + waddch(view->win, ' '); + col++; + } + + return col; +} + static int draw_date(struct view *view, struct tm *time, int max) { @@ -4854,30 +4878,17 @@ main_draw(struct view *view, struct line *line, unsigned int lineno) col += AUTHOR_COLS; if (col >= view->width) return TRUE; + wmove(view->win, lineno, col); } if (opt_rev_graph && commit->graph_size) { - size_t graph_size = view->width - col; - size_t i; - - set_view_attr(view, LINE_MAIN_REVGRAPH); - wmove(view->win, lineno, col); - if (graph_size > commit->graph_size) - graph_size = commit->graph_size; - /* Using waddch() instead of waddnstr() ensures that - * they'll be rendered correctly for the cursor line. */ - for (i = 0; i < graph_size; i++) - waddch(view->win, commit->graph[i]); - - col += commit->graph_size + 1; + col += draw_graphic(view, LINE_MAIN_REVGRAPH, + commit->graph, commit->graph_size, + view->width - col); if (col >= view->width) return TRUE; - waddch(view->win, ' '); } - set_view_attr(view, LINE_DEFAULT); - wmove(view->win, lineno, col); - if (opt_show_refs && commit->refs) { size_t i = 0;