@@ -48,18 +48,15 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4848
4949// External:
5050
51+ #ifdef ENABLE_TESTS
52+ #include " testing.hpp"
53+ #endif
54+
5155// ----------------------------------------------------------------------------
5256
5357namespace
5458{
55- enum class full_width
56- {
57- off,
58- on,
59- automatic
60- };
61-
62- auto s_FullWidthState = full_width::off;
59+ auto s_FullWidthEnabled = false ;
6360
6461 enum class codepoint_width : signed char
6562 {
@@ -457,8 +454,14 @@ namespace
457454 }
458455
459456 [[nodiscard]]
460- auto is_fullwidth_needed ()
457+ auto is_fullwidth_supported ()
461458 {
459+ #ifdef ENABLE_TESTS
460+ if (is_test_run ())
461+ return true ;
462+ #endif
463+
464+ // FW works in VT (Win10+) and in classic grid mode with CJK locales (LVB)
462465 return console.IsVtSupported () || locale.is_cjk ();
463466 }
464467
@@ -484,9 +487,12 @@ namespace
484487 [[nodiscard]]
485488 bool is_legacy_rendering ()
486489 {
487- DWORD Mode;
488- static const auto IsRedirected = !console.GetMode (console.GetOutputHandle (), Mode);
489- return !IsRedirected && !console.IsVtActive ();
490+ #ifdef ENABLE_TESTS
491+ if (is_test_run ())
492+ return false ;
493+ #endif
494+
495+ return !console.IsVtActive ();
490496 }
491497}
492498
@@ -498,21 +504,10 @@ namespace char_width
498504 if (!is_bmp (Codepoint) && is_legacy_rendering ())
499505 return 2 ; // Classic grid mode, nothing we can do :(
500506
501- switch (s_FullWidthState)
502- {
503- default :
504- case full_width::off:
507+ if (!s_FullWidthEnabled || !is_fullwidth_supported ())
505508 return 1 ;
506509
507- case full_width::automatic:
508- if (!is_fullwidth_needed ())
509- return 1 ;
510-
511- [[fallthrough]];
512-
513- case full_width::on:
514- return static_cast <size_t >(get_width (Codepoint));
515- }
510+ return static_cast <size_t >(get_width (Codepoint));
516511 }
517512
518513 [[nodiscard]]
@@ -521,29 +516,15 @@ namespace char_width
521516 return get (Codepoint) > 1 ;
522517 }
523518
524- void enable (int const Value)
519+ void enable (bool const Value)
525520 {
526- switch (Value)
527- {
528- case BSTATE_UNCHECKED:
529- invalidate ();
530- s_FullWidthState = full_width::off;
531- break ;
532-
533- case BSTATE_CHECKED:
534- s_FullWidthState = full_width::on;
535- break ;
536-
537- case BSTATE_3STATE:
538- s_FullWidthState = full_width::automatic;
539- break ;
540- }
521+ s_FullWidthEnabled = Value;
541522 }
542523
543524 [[nodiscard]]
544525 bool is_enabled ()
545526 {
546- return s_FullWidthState != full_width::off ;
527+ return s_FullWidthEnabled ;
547528 }
548529
549530 void invalidate ()
0 commit comments