@@ -94,19 +94,33 @@ func TestOverrideRuneWidthEastAsianWidth(t *testing.T) {
9494 rwCondition .EastAsianWidth = originalValue
9595 }()
9696
97+ // Box drawing characters (U+2500-U+257F) are now always reported as width 1,
98+ // regardless of the EastAsianWidth setting. This fixes alignment issues
99+ // that previously occurred when LANG was set to something like 'zh_CN.UTF-8'.
100+ // Previously, '╋' would be reported as width 2 when EastAsianWidth was true.
97101 OverrideRuneWidthEastAsianWidth (true )
98- assert .Equal (t , 2 , StringWidthWithoutEscSequences ("╋" ))
102+ assert .Equal (t , 1 , StringWidthWithoutEscSequences ("╋" ), "Box drawing character should always be width 1, even when EastAsianWidth is true" )
99103 OverrideRuneWidthEastAsianWidth (false )
100- assert .Equal (t , 1 , StringWidthWithoutEscSequences ("╋" ))
101-
102- // Note for posterity. We want the length of the box drawing character to
103- // be reported as 1. However, with an environment where LANG is set to
104- // something like 'zh_CN.UTF-8', the value being returned is 2, which breaks
105- // text alignment/padding logic in this library.
106- //
107- // If a future version of runewidth is able to address this internally and
108- // return 1 for the above, the function being tested can be marked for
109- // deprecation.
104+ assert .Equal (t , 1 , StringWidthWithoutEscSequences ("╋" ), "Box drawing character should always be width 1, even when EastAsianWidth is false" )
105+
106+ // Verify that block elements (U+2580-U+259F) are also handled correctly.
107+ // These are used in progress indicators and should always be width 1.
108+ OverrideRuneWidthEastAsianWidth (true )
109+ assert .Equal (t , 1 , StringWidthWithoutEscSequences ("█" ), "Block element should always be width 1, even when EastAsianWidth is true" )
110+ assert .Equal (t , 1 , StringWidthWithoutEscSequences ("▒" ), "Block element should always be width 1, even when EastAsianWidth is true" )
111+ assert .Equal (t , 1 , StringWidthWithoutEscSequences ("▓" ), "Block element should always be width 1, even when EastAsianWidth is true" )
112+ OverrideRuneWidthEastAsianWidth (false )
113+ assert .Equal (t , 1 , StringWidthWithoutEscSequences ("█" ), "Block element should always be width 1, even when EastAsianWidth is false" )
114+ assert .Equal (t , 1 , StringWidthWithoutEscSequences ("▒" ), "Block element should always be width 1, even when EastAsianWidth is false" )
115+ assert .Equal (t , 1 , StringWidthWithoutEscSequences ("▓" ), "Block element should always be width 1, even when EastAsianWidth is false" )
116+
117+ // Verify that actual East Asian characters are still handled correctly.
118+ // Note: The runewidth library reports 'ツ' as width 2 regardless of the
119+ // EastAsianWidth setting, as it's inherently a full-width character.
120+ OverrideRuneWidthEastAsianWidth (true )
121+ assert .Equal (t , 2 , StringWidthWithoutEscSequences ("ツ" ), "East Asian character should be width 2" )
122+ OverrideRuneWidthEastAsianWidth (false )
123+ assert .Equal (t , 2 , StringWidthWithoutEscSequences ("ツ" ), "East Asian character should be width 2" )
110124}
111125
112126func ExamplePad () {
0 commit comments