Skip to content

Commit 43ca2c3

Browse files
committed
Continue fullwidth-aware rendering
1 parent bad5ae4 commit 43ca2c3

File tree

9 files changed

+51
-51
lines changed

9 files changed

+51
-51
lines changed

far/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
--------------------------------------------------------------------------------
2+
drkns 2026-02-21 19:21:50+00:00 - build 6646
3+
4+
1. Continue fullwidth-aware rendering.
5+
16
--------------------------------------------------------------------------------
27
drkns 2026-02-19 21:12:02+00:00 - build 6645
38

far/char_width.cpp

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5357
namespace
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()

far/char_width.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace char_width
5454
[[nodiscard]]
5555
bool is_wide(codepoint Codepoint);
5656

57-
void enable(int Value);
57+
void enable(bool Value);
5858

5959
[[nodiscard]]
6060
bool is_enabled();

far/config.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,9 +1867,9 @@ Options::Options():
18671867
console.EnableVirtualTerminal(Value);
18681868
}));
18691869

1870-
FullWidthAwareRendering.SetCallback(option::notifier([](long long const Value)
1870+
FullWidthAwareRendering.SetCallback(option::notifier([](bool const Value)
18711871
{
1872-
char_width::enable(static_cast<int>(Value));
1872+
char_width::enable(Value);
18731873
}));
18741874

18751875
Clock.SetCallback(option::notifier([](bool const Value)

far/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ class Options: noncopyable
982982

983983
BoolOption VirtualTerminalRendering;
984984
Bool3Option ClearType;
985-
Bool3Option FullWidthAwareRendering;
985+
BoolOption FullWidthAwareRendering;
986986

987987
Bool3Option PgUpChangeDisk;
988988
BoolOption ShowDotsInRoot;

far/interf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ TEST_CASE("wide_chars")
19601960

19611961
const auto IsVtActive = console.IsVtActive();
19621962

1963-
char_width::enable(1);
1963+
char_width::enable(true);
19641964

19651965
for (const auto& i: Tests)
19661966
{
@@ -1980,7 +1980,7 @@ TEST_CASE("wide_chars")
19801980
}
19811981
}
19821982

1983-
char_width::enable(0);
1983+
char_width::enable(false);
19841984
}
19851985

19861986
TEST_CASE("tabs")

far/testing.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,18 @@ static bool is_ui_test_run(std::span<wchar_t const* const> const Args)
9090
return false;
9191
}
9292

93+
static bool s_IsTestRun;
94+
95+
static int run_tests(std::span<wchar_t const* const> const Args)
96+
{
97+
s_IsTestRun = true;
98+
return Catch::Session().run(static_cast<int>(Args.size()), Args.data());
99+
}
100+
93101
std::optional<int> testing_main(std::span<wchar_t const* const> const Args)
94102
{
95103
if (is_ui_test_run(Args.subspan(1)))
96-
return Catch::Session().run(static_cast<int>(Args.size()), Args.data());
104+
return run_tests(Args);
97105

98106
const auto ServiceTestIterator = std::ranges::find(Args, L"/service:test"sv);
99107
const auto IsBuildStep = ServiceTestIterator != Args.end();
@@ -138,7 +146,12 @@ std::optional<int> testing_main(std::span<wchar_t const* const> const Args)
138146

139147
locale = invariant_locale();
140148

141-
return Catch::Session().run(static_cast<int>(NewArgs.size()), NewArgs.data());
149+
return run_tests(NewArgs);
150+
}
151+
152+
bool is_test_run()
153+
{
154+
return s_IsTestRun;
142155
}
143156

144157
namespace

far/testing.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class generic_exception_matcher: public Catch::Matchers::MatcherGenericBase
9797
#endif
9898

9999
std::optional<int> testing_main(std::span<wchar_t const* const> Args);
100+
bool is_test_run();
100101

101102
#endif
102103

far/vbuild.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6645
1+
6646

0 commit comments

Comments
 (0)