Handle backspaces for visible width

This makes it so we treat backspaces as width -1, but never go below a
0 total width when talking about *lines*, like in screen or string
length --visible.

Fixes #8277.
This commit is contained in:
Fabian Homborg
2021-09-23 12:57:44 +02:00
parent 85ea9bf781
commit bb115c847e
5 changed files with 66 additions and 18 deletions

View File

@@ -310,3 +310,20 @@ wcstring join_strings(const wcstring_list_t &vals, wchar_t sep) {
void wcs2string_bad_char(wchar_t wc) {
FLOGF(char_encoding, L"Wide character U+%4X has no narrow representation", wc);
}
int fish_wcwidth_visible(wchar_t widechar) {
if (widechar == L'\b') return -1;
return std::max(0, fish_wcwidth(widechar));
}
int fish_wcswidth_visible(const wcstring &str) {
size_t res = 0;
for (wchar_t ch : str) {
if (ch == L'\b') {
res += -1;
} else {
res += std::max(0, fish_wcwidth(ch));
}
}
return res;
}