Use is_console_session() to signal using system wcwidth()

The system version of `wcwidth()` reflects the capabilities of the
system's own virtual terminal's view of the width of the character in
question, while fish's enhanced version (`widechar_wcwidth`) is much too
smart for most login terminals, which generally barely support anything
beyond ASCII text.

If, at startup, it is detected that we are running under a physical
console rather than within a terminal emulator running in a desktop
environment, take that as a hint to use the system-provided `wcwidth`.
This commit is contained in:
Mahmoud Al-Qudsi 2019-01-29 20:00:09 -06:00
parent 4aded78fc9
commit da8e343076

View File

@ -279,6 +279,13 @@ int fish_wcswidth(const wchar_t *str, size_t n) { return wcswidth(str, n); }
#include "widecharwidth/widechar_width.h"
int fish_wcwidth(wchar_t wc) {
// The system version of wcwidth should accurately reflect the ability to represent characters
// in the console session, but knows nothing about the capabilities of other terminal emulators
// or ttys. Use it from the start only if we are logged in to the physical console.
if (is_console_session()) {
return wcwidth(wc);
}
// Check for VS16 which selects emoji presentation. This "promotes" a character like U+2764
// (width 1) to an emoji (probably width 2). So treat it as width 1 so the sums work. See #2652.
// VS15 selects text presentation.
@ -292,6 +299,7 @@ int fish_wcwidth(wchar_t wc) {
// we take the position that the typical way for them to show up is composed.
if (wc >= L'\u1160' && wc <= L'\u11FF') return 0;
int width = widechar_wcwidth(wc);
switch (width) {
case widechar_nonprint:
case widechar_combining: