diff --git a/src/env_dispatch.cpp b/src/env_dispatch.cpp index 67787d188..9503add75 100644 --- a/src/env_dispatch.cpp +++ b/src/env_dispatch.cpp @@ -149,11 +149,11 @@ static void handle_timezone(const wchar_t *env_var_name, const environment_t &va tzset(); } -/// Update the value of g_guessed_fish_emoji_width +/// Update the value of g_fish_emoji_width static void guess_emoji_width(const environment_t &vars) { if (auto width_str = vars.get(L"fish_emoji_width")) { int new_width = fish_wcstol(width_str->as_string().c_str()); - g_fish_emoji_width = std::max(0, new_width); + g_fish_emoji_width = std::min(2,std::max(1, new_width)); FLOGF(term_support, "'fish_emoji_width' preference: %d, overwriting default", g_fish_emoji_width); return; @@ -172,18 +172,18 @@ static void guess_emoji_width(const environment_t &vars) { if (term == L"Apple_Terminal" && version >= 400) { // Apple Terminal on High Sierra - g_guessed_fish_emoji_width = 2; + g_fish_emoji_width = 2; FLOGF(term_support, "default emoji width: 2 for %ls", term.c_str()); } else if (term == L"iTerm.app") { // iTerm2 now defaults to Unicode 9 sizes for anything after macOS 10.12. - g_guessed_fish_emoji_width = 2; + g_fish_emoji_width = 2; FLOGF(term_support, "default emoji width for iTerm: 2"); } else { // Default to whatever system wcwidth says to U+1F603, - // but only if it's at least 1. + // but only if it's at least 1 and at most 2. int w = wcwidth(L'😃'); - g_guessed_fish_emoji_width = w > 0 ? w : 1; - FLOGF(term_support, "default emoji width: %d", g_guessed_fish_emoji_width); + g_fish_emoji_width = std::min(2,std::max(1, w)); + FLOGF(term_support, "default emoji width: %d", g_fish_emoji_width); } } diff --git a/src/fallback.cpp b/src/fallback.cpp index 1e1385ab9..4b506a719 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -221,17 +221,12 @@ int killpg(int pgr, int sig) { int g_fish_ambiguous_width = 1; // Width of emoji characters. -int g_fish_emoji_width = 0; - // 1 is the typical emoji width in Unicode 8. -int g_guessed_fish_emoji_width = 1; +int g_fish_emoji_width = 1; static int fish_get_emoji_width(wchar_t c) { (void)c; - // Respect an explicit value. If we don't have one, use the guessed value. Do not try to fall - // back to wcwidth(), it's hopeless. - if (g_fish_emoji_width > 0) return g_fish_emoji_width; - return g_guessed_fish_emoji_width; + return g_fish_emoji_width; } // Big hack to use our versions of wcswidth where we know them to be broken, which is diff --git a/src/fallback.h b/src/fallback.h index 3d3ed771e..949d33469 100644 --- a/src/fallback.h +++ b/src/fallback.h @@ -21,9 +21,6 @@ extern int g_fish_ambiguous_width; /// painful this is. A value of 0 means to use the guessed value. extern int g_fish_emoji_width; -/// The guessed value of the emoji width based on TERM. -extern int g_guessed_fish_emoji_width; - /// fish's internal versions of wcwidth and wcswidth, which can use an internal implementation if /// the system one is busted. int fish_wcwidth(wchar_t wc);