Commit 12c9cbfb54b1e0a9b79ba23b5197f92ba881c40a

Introduce draw_field() helper for drawing main and blame fields

It will draw spaces if the passed string is NULL.

Commit diff

tig.c

 
15161516}
15171517
15181518static int
1519draw_space(struct view *view, enum line_type type, int max, int spaces)
1520{
1521 static char space[] = " ";
1522 int col = 0;
1523
1524 spaces = MIN(max, spaces);
1525
1526 while (spaces > 0) {
1527 int len = MIN(spaces, sizeof(space) - 1);
1528
1529 col += draw_text(view, type, space, spaces, FALSE);
1530 spaces -= len;
1531 }
1532
1533 return col;
1534}
1535
1536static int
15191537draw_lineno(struct view *view, unsigned int lineno, int max)
15201538{
15211539 static char fmt[] = "%1ld";
15951595}
15961596
15971597static int
1598draw_field(struct view *view, enum line_type type, char *text, int len, int max_len, bool trim)
1599{
1600 int max = MIN(max_len, len);
1601 int col;
1602
1603 if (text)
1604 col = draw_text(view, type, text, max - 1, trim);
1605 else
1606 col = draw_space(view, type, max - 1, max - 1);
1607
1608 col += draw_space(view, LINE_DEFAULT, max - col, max - col);
1609 return col;
1610}
1611
1612static int
15981613draw_date(struct view *view, struct tm *time, int max)
15991614{
16001615 char buf[DATE_COLS];
1601 int col;
1616 char *date;
16021617 int timelen = 0;
16031618
1604 if (max > DATE_COLS)
1605 max = DATE_COLS;
16061619 if (time)
16071620 timelen = strftime(buf, sizeof(buf), DATE_FORMAT, time);
1608 if (!timelen) {
1609 memset(buf, ' ', sizeof(buf) - 1);
1610 buf[sizeof(buf) - 1] = 0;
1611 }
1621 date = timelen ? buf : NULL;
16121622
1613 col = draw_text(view, LINE_DATE, buf, max, FALSE);
1614 if (col < max) {
1615 set_view_attr(view, LINE_DEFAULT);
1616 waddch(view->win, ' ');
1617 col++;
1618 }
1619
1620 return col;
1623 return draw_field(view, LINE_DATE, date, DATE_COLS, max, FALSE);
16211624}
16221625
16231626static bool
36773677 }
36783678
36793679 {
3680 int max = MIN(ID_COLS - 1, view->width - col);
3680 int max = view->width - col;
36813681
3682 set_view_attr(view, LINE_BLAME_ID);
3683 if (id)
3684 draw_text(view, LINE_BLAME_ID, id, max, FALSE);
3685 col += ID_COLS;
3682 col += draw_field(view, LINE_BLAME_ID, id, ID_COLS, max, FALSE);
36863683 if (col >= view->width)
36873684 return TRUE;
3688 wmove(view->win, lineno, col);
36893685 }
36903686
36913687 col += draw_lineno(view, lineno, view->width - col);
toggle raw diff