Skip to content

Commit 2bec24c

Browse files
committed
Pass tab-size parameter to drawing functions
The next patch wants to pass in a tab-size other than the global opt_tab_size, so let's add the parameters to enable that. The next commit really only cares about places where we render diff hunks. Hence, keep passing "opt_tab_size" (or for brevity, 0) to calls that never draw diff hunks anyway.
1 parent 9b69b60 commit 2bec24c

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

include/tig/draw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum align {
2525
ALIGN_RIGHT
2626
};
2727

28-
bool draw_text(struct view *view, enum line_type type, const char *string);
28+
bool draw_text(struct view *view, enum line_type type, const char *string, int tab_size);
2929
bool PRINTF_LIKE(3, 4) draw_formatted(struct view *view, enum line_type type, const char *format, ...);
3030
bool draw_graphic(struct view *view, enum line_type type, const chtype graphic[], size_t size, bool separator);
3131
bool draw_field(struct view *view, enum line_type type, const char *text, int width, enum align align, bool trim);

src/draw.c

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ set_view_attr(struct view *view, enum line_type type)
5555

5656
static bool
5757
draw_chars(struct view *view, enum line_type type, const char *string, int length,
58-
int max_width, bool use_tilde)
58+
int max_width, bool use_tilde, int tab_size)
5959
{
6060
int len = 0;
6161
int col = 0;
@@ -67,6 +67,8 @@ draw_chars(struct view *view, enum line_type type, const char *string, int lengt
6767

6868
if (length == -1)
6969
length = strlen(string);
70+
if (!tab_size)
71+
tab_size = opt_tab_size;
7072

7173
if (opt_iconv_out != ICONV_NONE) {
7274
string = encoding_iconv(opt_iconv_out, string, length);
@@ -75,7 +77,7 @@ draw_chars(struct view *view, enum line_type type, const char *string, int lengt
7577
length = strlen(string);
7678
}
7779

78-
len = utf8_length(&string, length, skip, &col, max_width, &trimmed, use_tilde, opt_tab_size);
80+
len = utf8_length(&string, length, skip, &col, max_width, &trimmed, use_tilde, tab_size);
7981

8082
set_view_attr(view, type);
8183
if (len > 0)
@@ -101,7 +103,7 @@ draw_space(struct view *view, enum line_type type, int max, int spaces)
101103
while (spaces > 0) {
102104
int len = MIN(spaces, sizeof(space) - 1);
103105

104-
if (draw_chars(view, type, space, -1, len, false))
106+
if (draw_chars(view, type, space, -1, len, false, 0))
105107
return true;
106108
spaces -= len;
107109
}
@@ -110,18 +112,18 @@ draw_space(struct view *view, enum line_type type, int max, int spaces)
110112
}
111113

112114
static bool
113-
draw_text_expanded(struct view *view, enum line_type type, const char *string, int length, int max_width, bool use_tilde)
115+
draw_text_expanded(struct view *view, enum line_type type, const char *string, int length, int max_width, bool use_tilde, int tab_size)
114116
{
115117
static char text[SIZEOF_STR];
116118

117119
if (length == -1)
118120
length = strlen(string);
119121

120122
do {
121-
size_t pos = string_expand(text, sizeof(text), string, length, opt_tab_size);
123+
size_t pos = string_expand(text, sizeof(text), string, length, tab_size);
122124
size_t col = view->col;
123125

124-
if (draw_chars(view, type, text, -1, max_width, use_tilde))
126+
if (draw_chars(view, type, text, -1, max_width, use_tilde, tab_size))
125127
return true;
126128
string += pos;
127129
length -= pos;
@@ -132,15 +134,15 @@ draw_text_expanded(struct view *view, enum line_type type, const char *string, i
132134
}
133135

134136
static inline bool
135-
draw_textn(struct view *view, enum line_type type, const char *string, int length)
137+
draw_textn(struct view *view, enum line_type type, const char *string, int length, int tab_size)
136138
{
137-
return draw_text_expanded(view, type, string, length, VIEW_MAX_LEN(view), false);
139+
return draw_text_expanded(view, type, string, length, VIEW_MAX_LEN(view), false, tab_size);
138140
}
139141

140142
bool
141-
draw_text(struct view *view, enum line_type type, const char *string)
143+
draw_text(struct view *view, enum line_type type, const char *string, int tab_size)
142144
{
143-
return draw_textn(view, type, string, -1);
145+
return draw_textn(view, type, string, -1, tab_size);
144146
}
145147

146148
static bool
@@ -157,14 +159,14 @@ draw_text_overflow(struct view *view, const char *text, enum line_type type,
157159
int trimmed = false;
158160
size_t len = utf8_length(&tmp, -1, 0, &text_width, max, &trimmed, false, 1);
159161

160-
if (draw_text_expanded(view, type, text, -1, text_width, max < overflow))
162+
if (draw_text_expanded(view, type, text, -1, text_width, max < overflow, opt_tab_size))
161163
return true;
162164

163165
text += len;
164166
type = LINE_OVERFLOW;
165167
}
166168

167-
if (*text && draw_text(view, type, text))
169+
if (*text && draw_text(view, type, text, 0))
168170
return true;
169171

170172
return VIEW_MAX_LEN(view) <= 0;
@@ -177,7 +179,7 @@ draw_formatted(struct view *view, enum line_type type, const char *format, ...)
177179
int retval;
178180

179181
FORMAT_BUFFER(text, sizeof(text), format, retval, true);
180-
return retval >= 0 ? draw_text(view, type, text) : VIEW_MAX_LEN(view) <= 0;
182+
return retval >= 0 ? draw_text(view, type, text, 0) : VIEW_MAX_LEN(view) <= 0;
181183
}
182184

183185
bool
@@ -227,7 +229,7 @@ draw_field(struct view *view, enum line_type type, const char *text, int width,
227229
}
228230
}
229231

230-
return draw_chars(view, type, text, -1, max - 1, trim)
232+
return draw_chars(view, type, text, -1, max - 1, trim, 0)
231233
|| draw_space(view, type, max - (view->col - col), max);
232234
}
233235

@@ -333,17 +335,17 @@ draw_lineno_custom(struct view *view, struct view_column *column, unsigned int l
333335
text = number;
334336
}
335337
if (text)
336-
draw_chars(view, LINE_LINE_NUMBER, text, -1, max, true);
338+
draw_chars(view, LINE_LINE_NUMBER, text, -1, max, true, 0);
337339
else
338340
draw_space(view, LINE_LINE_NUMBER, max, digits3);
339341

340342
switch (opt_line_graphics) {
341343
case GRAPHIC_ASCII:
342-
return draw_chars(view, LINE_DEFAULT, "| ", -1, 2, false);
344+
return draw_chars(view, LINE_DEFAULT, "| ", -1, 2, false, 0);
343345
case GRAPHIC_DEFAULT:
344346
return draw_graphic(view, LINE_DEFAULT, &separator, 1, true);
345347
case GRAPHIC_UTF_8:
346-
return draw_chars(view, LINE_DEFAULT, "│ ", -1, 2, false);
348+
return draw_chars(view, LINE_DEFAULT, "│ ", -1, 2, false, 0);
347349
}
348350

349351
return false;
@@ -381,7 +383,7 @@ draw_refs(struct view *view, struct view_column *column, const struct ref *refs)
381383
if (draw_formatted(view, type, "%s%s%s", format->start, ref->name, format->end))
382384
return true;
383385

384-
if (draw_text(view, LINE_DEFAULT, " "))
386+
if (draw_text(view, LINE_DEFAULT, " ", 0))
385387
return true;
386388
}
387389

@@ -415,15 +417,15 @@ draw_graph_utf8(void *view, const struct graph *graph, const struct graph_symbol
415417
{
416418
const char *chars = graph->symbol_to_utf8(symbol);
417419

418-
return draw_text(view, get_graph_color(color_id), chars + !!first);
420+
return draw_text(view, get_graph_color(color_id), chars + !!first, 0);
419421
}
420422

421423
static bool
422424
draw_graph_ascii(void *view, const struct graph *graph, const struct graph_symbol *symbol, int color_id, bool first)
423425
{
424426
const char *chars = graph->symbol_to_ascii(symbol);
425427

426-
return draw_text(view, get_graph_color(color_id), chars + !!first);
428+
return draw_text(view, get_graph_color(color_id), chars + !!first, 0);
427429
}
428430

429431
static bool
@@ -444,7 +446,7 @@ draw_graph(struct view *view, const struct graph *graph, const struct graph_canv
444446
};
445447

446448
graph->foreach_symbol(graph, canvas, fns[opt_line_graphics], view);
447-
return draw_text(view, LINE_DEFAULT, " ");
449+
return draw_text(view, LINE_DEFAULT, " ", 0);
448450
}
449451

450452
static bool
@@ -534,7 +536,7 @@ view_column_draw(struct view *view, struct line *line, unsigned int lineno)
534536
continue;
535537

536538
case VIEW_COLUMN_SECTION:
537-
if (draw_text(view, column->opt.section.type, column->opt.section.text))
539+
if (draw_text(view, column->opt.section.type, column->opt.section.text, 0))
538540
return true;
539541
continue;
540542

@@ -549,13 +551,13 @@ view_column_draw(struct view *view, struct line *line, unsigned int lineno)
549551
const char *text = column_data.text;
550552
size_t indent = 0;
551553

552-
if (line->wrapped && draw_text(view, LINE_DELIMITER, "+"))
554+
if (line->wrapped && draw_text(view, LINE_DELIMITER, "+", 0))
553555
return true;
554556

555557
if (line->graph_indent) {
556558
indent = get_graph_indent(text);
557559

558-
if (draw_text_expanded(view, LINE_DEFAULT, text, -1, indent, false))
560+
if (draw_text_expanded(view, LINE_DEFAULT, text, -1, indent, false, opt_tab_size))
559561
return true;
560562
text += indent;
561563
}
@@ -580,13 +582,13 @@ view_column_draw(struct view *view, struct line *line, unsigned int lineno)
580582
indent = 0;
581583
}
582584

583-
if (draw_textn(view, cell->type, text, length))
585+
if (draw_textn(view, cell->type, text, length, opt_tab_size))
584586
return true;
585587

586588
text += length;
587589
}
588590

589-
} else if (draw_text(view, type, text)) {
591+
} else if (draw_text(view, type, text, opt_tab_size)) {
590592
return true;
591593
}
592594
}

src/help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ help_draw(struct view *view, struct line *line, unsigned int lineno)
4646
keymap->hidden ? '+' : '-', keymap->name);
4747

4848
} else if (line->type == LINE_HELP_GROUP || !keymap) {
49-
draw_text(view, line->type, help->data.text);
49+
draw_text(view, line->type, help->data.text, 0);
5050

5151
} else if (help->request > REQ_RUN_REQUESTS) {
5252
struct run_request *req = get_run_request(help->request);
@@ -73,7 +73,7 @@ help_draw(struct view *view, struct line *line, unsigned int lineno)
7373
if (draw_field(view, LINE_HELP_ACTION, enum_name(req_info->name), state->name_width, ALIGN_LEFT, false))
7474
return true;
7575

76-
draw_text(view, LINE_DEFAULT, req_info->help);
76+
draw_text(view, LINE_DEFAULT, req_info->help, 0);
7777
}
7878

7979
return true;

0 commit comments

Comments
 (0)