Skip to content

Commit

Permalink
Let ncurses take care of expanding tabs by setting its TABSIZE variable
Browse files Browse the repository at this point in the history
Rename the default tab size from TABSIZE to TAB_SIZE, since it shadows
the public ncurses TABSIZE variable which controls how the waddch-family
expands tabs when drawing. This makes it possible to finally handle
tabsizes different from 8 for UTF-8.
  • Loading branch information
jonas committed Apr 17, 2008
1 parent edd085a commit 32751de
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions tig.c
Expand Up @@ -99,7 +99,7 @@ static size_t utf8_length(const char *string, size_t max_width, int *trimmed, bo
/* The default interval between line numbers. */
#define NUMBER_INTERVAL 5

#define TABSIZE 8
#define TAB_SIZE 8

#define SCALE_SPLIT_VIEW(height) ((height) * 2 / 3)

Expand Down Expand Up @@ -441,7 +441,7 @@ static bool opt_line_number = FALSE;
static bool opt_rev_graph = FALSE;
static bool opt_show_refs = TRUE;
static int opt_num_interval = NUMBER_INTERVAL;
static int opt_tab_size = TABSIZE;
static int opt_tab_size = TAB_SIZE;
static enum request opt_request = REQ_VIEW_MAIN;
static char opt_cmd[SIZEOF_STR] = "";
static char opt_path[SIZEOF_STR] = "";
Expand Down Expand Up @@ -2783,7 +2783,6 @@ view_driver(struct view *view, enum request request)
static bool
pager_draw(struct view *view, struct line *line, unsigned int lineno, bool selected)
{
static char spaces[] = " ";
char *text = line->data;
int col = 0;

Expand All @@ -2796,34 +2795,7 @@ pager_draw(struct view *view, struct line *line, unsigned int lineno, bool selec
if (!selected)
wattrset(view->win, get_line_attr(line->type));

if (opt_tab_size < TABSIZE) {
int col_offset = col;

col = 0;
while (text && col_offset + col < view->width) {
int cols_max = view->width - col_offset - col;
char *pos = text;
int cols;

if (*text == '\t') {
text++;
assert(sizeof(spaces) > TABSIZE);
pos = spaces;
cols = opt_tab_size - (col % opt_tab_size);

} else {
text = strchr(text, '\t');
cols = line ? text - pos : strlen(pos);
}

waddnstr(view->win, pos, MIN(cols, cols_max));
col += cols;
}

} else {
draw_text(view, text, view->width - col, TRUE, selected);
}

draw_text(view, text, view->width - col, TRUE, selected);
return TRUE;
}

Expand Down Expand Up @@ -5382,6 +5354,8 @@ init_display(void)
/* Enable keyboard mapping */
keypad(status_win, TRUE);
wbkgdset(status_win, get_line_attr(LINE_STATUS));

TABSIZE = opt_tab_size;
}

static char *
Expand Down

0 comments on commit 32751de

Please sign in to comment.