mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-27 03:51:22 -03:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user