mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-08 08:20:59 -04:00
extract: consume spaces following a tab
That is, we choose to copy the tab character, and not the spaces it represents. Most importantly, we don’t copy *both* the tab and the spaces.
This commit is contained in:
parent
94b549f93e
commit
4d56dd430b
1 changed files with 23 additions and 0 deletions
23
extract.c
23
extract.c
|
|
@ -9,6 +9,7 @@ struct extraction_context {
|
||||||
wchar_t *buf;
|
wchar_t *buf;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
|
size_t tab_spaces_left;
|
||||||
size_t empty_count;
|
size_t empty_count;
|
||||||
size_t newline_count;
|
size_t newline_count;
|
||||||
bool strip_trailing_empty;
|
bool strip_trailing_empty;
|
||||||
|
|
@ -191,8 +192,17 @@ extract_one(const struct terminal *term, const struct row *row,
|
||||||
}
|
}
|
||||||
ctx->empty_count = 0;
|
ctx->empty_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->tab_spaces_left = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cell->wc == L' ' && ctx->tab_spaces_left > 0) {
|
||||||
|
ctx->tab_spaces_left--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->tab_spaces_left = 0;
|
||||||
|
|
||||||
if (cell->wc == 0) {
|
if (cell->wc == 0) {
|
||||||
ctx->empty_count++;
|
ctx->empty_count++;
|
||||||
ctx->last_row = row;
|
ctx->last_row = row;
|
||||||
|
|
@ -231,6 +241,19 @@ extract_one(const struct terminal *term, const struct row *row,
|
||||||
if (!ensure_size(ctx, 1))
|
if (!ensure_size(ctx, 1))
|
||||||
goto err;
|
goto err;
|
||||||
ctx->buf[ctx->idx++] = cell->wc;
|
ctx->buf[ctx->idx++] = cell->wc;
|
||||||
|
|
||||||
|
if (cell->wc == L'\t') {
|
||||||
|
int next_tab_stop = term->cols - 1;
|
||||||
|
tll_foreach(term->tab_stops, it) {
|
||||||
|
if (it->item > col) {
|
||||||
|
next_tab_stop = it->item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xassert(next_tab_stop >= col);
|
||||||
|
ctx->tab_spaces_left = next_tab_stop - col;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->last_row = row;
|
ctx->last_row = row;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue