display: skip zero-width characters on a Linux console, to avoid a mess

This is a workaround for the VT not being able to handle zero-width
characters properly, displaying them mistakenly as visible characters.

This avoids https://savannah.gnu.org/bugs/?52954.

The problem has existed since forever, but has become noticeable
since the capability for line numbers was added in version 2.7.1.
This commit is contained in:
Benno Schulenberg 2020-01-15 17:28:14 +01:00
parent 2148e857e5
commit f47ef539db

View File

@ -1939,13 +1939,21 @@ char *display_string(const char *buf, size_t column, size_t span,
continue;
}
/* Determine whether the character takes zero, one, or two columns. */
charwidth = wcwidth(wc);
#ifdef __linux__
/* On a Linux console, skip zero-width characters, as it would show
* them WITH a width, thus messing up the display. See bug #52954. */
if (on_a_vt && charwidth == 0) {
buf += charlength;
continue;
}
#endif
/* For any valid character, just copy its bytes. */
for (; charlength > 0; charlength--)
converted[index++] = *(buf++);
/* Determine whether the character occupies one or two columns. */
charwidth = wcwidth(wc);
/* If the codepoint is unassigned, assume a width of one. */
column += (charwidth < 0 ? 1 : charwidth);