From 2fe2415a400e7a7888c3f8df633cbaed680937fc Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Sat, 30 Nov 2024 23:41:21 +0000 Subject: [PATCH] Warn the user when the terminal uses grapheme clusters --- far/changelog | 5 ++++ far/char_width.cpp | 6 +++++ far/char_width.hpp | 3 +++ far/config.cpp | 14 +++++++++++ far/console.cpp | 17 +++++++++----- far/console.hpp | 1 + far/farlang.templ.m4 | 56 ++++++++++++++++++++++++++++++++++++++++++++ far/vbuild.m4 | 2 +- 8 files changed, 97 insertions(+), 7 deletions(-) diff --git a/far/changelog b/far/changelog index 8e59e5cc5d..5f198b8e40 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,8 @@ +-------------------------------------------------------------------------------- +drkns 2024-11-30 23:34:14+00:00 - build 6396 + +1. Warn the user when the terminal uses grapheme clusters. + -------------------------------------------------------------------------------- skipik 2024-11-26 17:23:11+03:00 - build 6395 diff --git a/far/char_width.cpp b/far/char_width.cpp index 7a2ec29193..52011215da 100644 --- a/far/char_width.cpp +++ b/far/char_width.cpp @@ -552,4 +552,10 @@ namespace char_width static const auto Result = console.GetWidthPreciseExpensive(U'𝖆'); return Result > 1; } + + bool is_grapheme_clusters_on() + { + static const auto Result = console.GetWidthPreciseExpensive(L"à"sv); + return Result == 1; + } } diff --git a/far/char_width.hpp b/far/char_width.hpp index 04f1f9c989..8a8bcf7dde 100644 --- a/far/char_width.hpp +++ b/far/char_width.hpp @@ -63,6 +63,9 @@ namespace char_width [[nodiscard]] bool is_half_width_surrogate_broken(); + + [[nodiscard]] + bool is_grapheme_clusters_on(); } #endif // CHAR_WIDTH_HPP_D66C86AC_3415_4FD1_89DA_0AB843FFEEB8 diff --git a/far/config.cpp b/far/config.cpp index 1024b77ada..151b298d35 100644 --- a/far/config.cpp +++ b/far/config.cpp @@ -378,6 +378,20 @@ void Options::InterfaceSettings() Panels->SetScreenPosition(); // $ 10.07.2001 SKV ! надо это делать, иначе если кейбар спрятали, будет полный рамс. Panels->Redraw(); + + if (FullWidthAwareRendering && char_width::is_grapheme_clusters_on()) + { + Message(FMSG_WARNING, msg(lng::MWarning), + { + msg(lng::MConfigFullWidthAwareRenderingGraphemeClustersDected1), + msg(lng::MConfigFullWidthAwareRenderingGraphemeClustersDected2), + msg(lng::MConfigFullWidthAwareRenderingGraphemeClustersDected3), + msg(lng::MConfigFullWidthAwareRenderingGraphemeClustersDected4), + }, + { + lng::MOk + }); + } } } diff --git a/far/console.cpp b/far/console.cpp index fed5e98318..30c7aabbac 100644 --- a/far/console.cpp +++ b/far/console.cpp @@ -2906,7 +2906,7 @@ namespace console_detail return ExternalConsole.Imports.pWriteOutput.operator bool(); } - size_t console::GetWidthPreciseExpensive(char32_t const Codepoint) + size_t console::GetWidthPreciseExpensive(string_view const Str) { // It ain't stupid if it works @@ -2944,21 +2944,26 @@ namespace console_detail } DWORD Written; - const auto Pair = encoding::utf16::to_surrogate(Codepoint); - const std::array Chars{ Pair.first, Pair.second }; - if (!WriteConsole(m_WidthTestScreen.native_handle(), Chars.data(), Pair.second? 2 : 1, &Written, {})) + if (!WriteConsole(m_WidthTestScreen.native_handle(), Str.data(), static_cast(Str.size()), &Written, {})) { LOGWARNING(L"WriteConsole(): {}"sv, os::last_error()); - return 1; + return Str.size(); } CONSOLE_SCREEN_BUFFER_INFO Info; if (!get_console_screen_buffer_info(m_WidthTestScreen.native_handle(), &Info)) - return 1; + return Str.size(); return Info.dwCursorPosition.X; } + size_t console::GetWidthPreciseExpensive(char32_t const Codepoint) + { + const auto Pair = encoding::utf16::to_surrogate(Codepoint); + const std::array Chars{ Pair.first, Pair.second }; + return GetWidthPreciseExpensive({ Chars.data(), Pair.second? 2uz : 1uz }); + } + void console::ClearWideCache() { m_WidthTestScreen = {}; diff --git a/far/console.hpp b/far/console.hpp index 9e1784fa93..76efff8a76 100644 --- a/far/console.hpp +++ b/far/console.hpp @@ -190,6 +190,7 @@ namespace console_detail bool ExternalRendererLoaded() const; [[nodiscard]] + size_t GetWidthPreciseExpensive(string_view Str); size_t GetWidthPreciseExpensive(char32_t Codepoint); void ClearWideCache(); diff --git a/far/farlang.templ.m4 b/far/farlang.templ.m4 index 05b51bbd4e..21dec61d2d 100644 --- a/far/farlang.templ.m4 +++ b/far/farlang.templ.m4 @@ -2871,6 +2871,62 @@ upd:"Рендерінг з урахуванням повної ширини" "Візуалізацыя з улікам поўнай шырыні" upd:"Fullwidth-aware rendering" +MConfigFullWidthAwareRenderingGraphemeClustersDected1 +upd:"It appears that your terminal supports Unicode grapheme clusters." +"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." +upd:"It appears that your terminal supports Unicode grapheme clusters." + +MConfigFullWidthAwareRenderingGraphemeClustersDected2 +upd:"Unfortunately, Far does not support them yet." +"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." +upd:"Unfortunately, Far does not support them yet." + +MConfigFullWidthAwareRenderingGraphemeClustersDected3 +upd:"For best experience it is recommended to switch to codepoint-based rendering." +"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." +upd:"For best experience it is recommended to switch to codepoint-based rendering." + +MConfigFullWidthAwareRenderingGraphemeClustersDected4 +upd:"Consult the documentation of your terminal for advice on how to do this." +"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." +upd:"Consult the documentation of your terminal for advice on how to do this." + MConfigClearType "Перер&исовка с поддержкой ClearType (может быть медленной)" "Cl&earType-friendly redraw (can be slow)" diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 9c18c9129d..dde853edca 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -6395 +6396