Ensure combining chars are zero-width regardless of wcwidth implementation
This commit is contained in:
@@ -271,7 +271,8 @@ void
|
||||
screen_draw(Screen *self, uint32_t och) {
|
||||
if (is_ignored_char(och)) return;
|
||||
uint32_t ch = och < 256 ? self->g_charset[och] : och;
|
||||
unsigned int char_width = safe_wcwidth(ch);
|
||||
bool is_cc = is_combining_char(ch);
|
||||
unsigned int char_width = is_cc ? 0 : safe_wcwidth(ch);
|
||||
if (self->columns - self->cursor->x < char_width) {
|
||||
if (self->modes.mDECAWM) {
|
||||
screen_carriage_return(self);
|
||||
@@ -1289,7 +1290,11 @@ screen_wcswidth(Screen UNUSED *self, PyObject *str) {
|
||||
void *data = PyUnicode_DATA(str);
|
||||
Py_ssize_t len = PyUnicode_GET_LENGTH(str), i;
|
||||
unsigned long ans = 0;
|
||||
for (i = 0; i < len; i++) ans += safe_wcwidth(PyUnicode_READ(kind, data, i));
|
||||
for (i = 0; i < len; i++) {
|
||||
char_type ch = PyUnicode_READ(kind, data, i);
|
||||
bool is_cc = is_combining_char(ch);
|
||||
ans += is_cc ? 0 : safe_wcwidth(ch);
|
||||
}
|
||||
return PyLong_FromUnsignedLong(ans);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user