refactor(grid): get rid of unbatched grid_puts and grid_putchar

This finalizes the long running refactor from the old TUI-focused grid
implementation where text-drawing cursor was not separated from the
visible cursor.

Still, the pattern of setting cursor position together with updating a
line was convenient. Introduce grid_line_cursor_goto() to still allow
this but now being explicit about it.

Only having batched drawing functions makes code involving drawing
a bit longer. But it is better to be explicit, and this highlights
cases where multiple small redraws can be grouped together. This was the
case for most of the changed places (messages, lastline, and :intro)
This commit is contained in:
bfredl
2023-10-05 14:44:13 +02:00
parent f67517bba3
commit a58bb21544
10 changed files with 105 additions and 152 deletions

View File

@@ -2827,7 +2827,7 @@ void intro_message(int colon)
}
if (*mesg != NUL) {
do_intro_line(row, mesg, 0);
do_intro_line((int)row, mesg, 0);
}
row++;
@@ -2838,14 +2838,13 @@ void intro_message(int colon)
}
}
static void do_intro_line(long row, char *mesg, int attr)
static void do_intro_line(int row, char *mesg, int attr)
{
char *p;
int l;
int clen;
// Center the message horizontally.
long col = vim_strsize(mesg);
int col = vim_strsize(mesg);
col = (Columns - col) / 2;
@@ -2853,21 +2852,18 @@ static void do_intro_line(long row, char *mesg, int attr)
col = 0;
}
grid_line_start(&default_grid, row);
// Split up in parts to highlight <> items differently.
for (p = mesg; *p != NUL; p += l) {
clen = 0;
for (l = 0;
p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>'));
l++) {
clen += ptr2cells(p + l);
l += utfc_ptr2len(p + l) - 1;
}
assert(row <= INT_MAX && col <= INT_MAX);
grid_puts(&default_grid, p, l, (int)row, (int)col,
*p == '<' ? HL_ATTR(HLF_8) : attr);
col += clen;
col += grid_line_puts(col, p, l, *p == '<' ? HL_ATTR(HLF_8) : attr);
}
grid_line_flush();
}
/// ":intro": clear screen, display intro screen and wait for return.