From dc5f8a5c527e7bf6197117271913fbe8580b0666 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 15 Feb 2009 17:35:34 +0100 Subject: [PATCH] Refactor draw_lineno to use draw_graphic --- tig.c | 68 +++++++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/tig.c b/tig.c index 6bf13ec..148b6b6 100644 --- a/tig.c +++ b/tig.c @@ -1843,7 +1843,7 @@ enum line_graphic { LINE_GRAPHIC_VLINE }; -static int line_graphics[] = { +static chtype line_graphics[] = { /* LINE_GRAPHIC_VLINE: */ '|' }; @@ -1912,47 +1912,6 @@ draw_space(struct view *view, enum line_type type, int max, int spaces) return col; } -static bool -draw_lineno(struct view *view, unsigned int lineno) -{ - size_t skip = view->yoffset > view->col ? view->yoffset - view->col : 0; - char number[10]; - int digits3 = view->digits < 3 ? 3 : view->digits; - int max_number = MIN(digits3, STRING_SIZE(number)); - 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; - col = draw_chars(view, LINE_LINE_NUMBER, number, max_number, TRUE); - } else { - col = draw_space(view, LINE_LINE_NUMBER, max_number, max_number); - } - - if (col < max && skip <= col) { - set_view_attr(view, LINE_DEFAULT); - waddch(view->win, line_graphics[LINE_GRAPHIC_VLINE]); - } - col++; - - view->col += col; - if (col < max && skip <= col) - col = draw_space(view, LINE_DEFAULT, max - col, 1); - view->col++; - - return view->width + view->yoffset <= view->col; -} - static bool draw_text(struct view *view, enum line_type type, const char *string, bool trim) { @@ -2061,6 +2020,31 @@ draw_mode(struct view *view, mode_t mode) return draw_field(view, LINE_MODE, str, STRING_SIZE("-rw-r--r-- "), FALSE); } +static bool +draw_lineno(struct view *view, unsigned int lineno) +{ + char number[10]; + int digits3 = view->digits < 3 ? 3 : view->digits; + int max = MIN(view->width + view->yoffset - view->col, digits3); + char *text = NULL; + + 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)) + text = number; + } + if (text) + view->col += draw_chars(view, LINE_LINE_NUMBER, text, max, TRUE); + else + view->col += draw_space(view, LINE_LINE_NUMBER, max, digits3); + return draw_graphic(view, LINE_DEFAULT, &line_graphics[LINE_GRAPHIC_VLINE], 1); +} + static bool draw_view_line(struct view *view, unsigned int lineno) { -- 2.32.0.93.g670b81a890