From da8e34307658b482532f66ae74165649fb893472 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 29 Jan 2019 20:00:09 -0600 Subject: [PATCH] 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`. --- src/fallback.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fallback.cpp b/src/fallback.cpp index 64bbc1920..870f81787 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -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: