aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/grid.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/grid.c')
-rw-r--r--src/nvim/grid.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/nvim/grid.c b/src/nvim/grid.c
index 46f8a59710..efbeac4f3f 100644
--- a/src/nvim/grid.c
+++ b/src/nvim/grid.c
@@ -158,9 +158,9 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp)
/// attributes 'attr', and update chars[] and attrs[].
/// Note: only outputs within one row, message is truncated at grid boundary!
/// Note: if grid, row and/or col is invalid, nothing is done.
-void grid_puts(ScreenGrid *grid, char *text, int row, int col, int attr)
+int grid_puts(ScreenGrid *grid, char *text, int row, int col, int attr)
{
- grid_puts_len(grid, text, -1, row, col, attr);
+ return grid_puts_len(grid, text, -1, row, col, attr);
}
static ScreenGrid *put_dirty_grid = NULL;
@@ -197,22 +197,18 @@ void grid_put_schar(ScreenGrid *grid, int row, int col, char *schar, int attr)
/// like grid_puts(), but output "text[len]". When "len" is -1 output up to
/// a NUL.
-void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int attr)
+int grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int attr)
{
size_t off;
char *ptr = text;
int len = textlen;
int c;
size_t max_off;
- int mbyte_blen = 1;
- int mbyte_cells = 1;
- int u8c = 0;
int u8cc[MAX_MCO];
bool clear_next_cell = false;
int prev_c = 0; // previous Arabic character
int pc, nc, nc1;
int pcc[MAX_MCO];
- int need_redraw;
bool do_flush = false;
grid_adjust(&grid, &row, &col);
@@ -222,7 +218,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col,
if (grid->chars == NULL
|| row >= grid->rows || row < 0
|| col >= grid->cols || col < 0) {
- return;
+ return 0;
}
if (put_dirty_row == -1) {
@@ -234,6 +230,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col,
}
}
off = grid->line_offset[row] + (size_t)col;
+ int start_col = col;
// When drawing over the right half of a double-wide char clear out the
// left half. Only needed in a terminal.
@@ -249,13 +246,19 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col,
&& *ptr != NUL) {
c = (unsigned char)(*ptr);
// check if this is the first byte of a multibyte
- mbyte_blen = len > 0
+ int mbyte_blen = len > 0
? utfc_ptr2len_len(ptr, (int)((text + len) - ptr))
: utfc_ptr2len(ptr);
- u8c = len >= 0
+ int u8c = len >= 0
? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr))
: utfc_ptr2char(ptr, u8cc);
- mbyte_cells = utf_char2cells(u8c);
+ int mbyte_cells = utf_char2cells(u8c);
+ if (mbyte_cells > 2) {
+ mbyte_cells = 1;
+ u8c = 0xFFFD;
+ u8cc[0] = 0;
+ }
+
if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) {
// Do Arabic shaping.
if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) {
@@ -287,11 +290,11 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col,
schar_T buf;
schar_from_cc(buf, u8c, u8cc);
- need_redraw = schar_cmp(grid->chars[off], buf)
- || (mbyte_cells == 2 && grid->chars[off + 1][0] != 0)
- || grid->attrs[off] != attr
- || exmode_active
- || rdb_flags & RDB_NODELTA;
+ int need_redraw = schar_cmp(grid->chars[off], buf)
+ || (mbyte_cells == 2 && grid->chars[off + 1][0] != 0)
+ || grid->attrs[off] != attr
+ || exmode_active
+ || rdb_flags & RDB_NODELTA;
if (need_redraw) {
// When at the end of the text and overwriting a two-cell
@@ -340,6 +343,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col,
if (do_flush) {
grid_puts_line_flush(true);
}
+ return col - start_col;
}
/// End a group of grid_puts_len calls and send the screen buffer to the UI
@@ -497,7 +501,6 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle
size_t max_off_from;
size_t max_off_to;
int col = 0;
- bool redraw_this; // Does character need redraw?
bool redraw_next; // redraw_this for next character
bool clear_next = false;
int char_cells; // 1: normal char
@@ -559,7 +562,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle
if (col + 1 < endcol) {
char_cells = line_off2cells(linebuf_char, off_from, max_off_from);
}
- redraw_this = redraw_next;
+ bool redraw_this = redraw_next; // Does character need redraw?
redraw_next = grid_char_needs_redraw(grid, off_from + (size_t)char_cells,
off_to + (size_t)char_cells,
endcol - col - char_cells);
@@ -810,7 +813,6 @@ void grid_assign_handle(ScreenGrid *grid)
/// 'row', 'col' and 'end' are relative to the start of the region.
void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, int width)
{
- int i;
int j;
unsigned temp;
@@ -825,7 +827,7 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col,
// Shift line_offset[] line_count down to reflect the inserted lines.
// Clear the inserted lines.
- for (i = 0; i < line_count; i++) {
+ for (int i = 0; i < line_count; i++) {
if (width != grid->cols) {
// need to copy part of a line
j = end - 1 - i;
@@ -860,7 +862,6 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col,
void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, int width)
{
int j;
- int i;
unsigned temp;
int row_off = 0;
@@ -874,7 +875,7 @@ void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col,
// Now shift line_offset[] line_count up to reflect the deleted lines.
// Clear the inserted lines.
- for (i = 0; i < line_count; i++) {
+ for (int i = 0; i < line_count; i++) {
if (width != grid->cols) {
// need to copy part of a line
j = row + i;