Skip to content

Commit b9ca72d

Browse files
authored
Fix emoji character width, fixes #683 (#713)
1 parent bef9396 commit b9ca72d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

terminal/src/main/java/org/jline/utils/WCWidth.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static int wcwidth(int ucs)
7070
(ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
7171
(ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */
7272
(ucs >= 0xffe0 && ucs <= 0xffe6) ||
73+
(ucs >= 0x1f000 && ucs <= 0x1feee) ||
7374
(ucs >= 0x20000 && ucs <= 0x2fffd) ||
7475
(ucs >= 0x30000 && ucs <= 0x3fffd))) ? 1 : 0);
7576
}
@@ -123,8 +124,8 @@ public static int wcwidth(int ucs)
123124
new Interval( 0x10A01, 0x10A03 ), new Interval( 0x10A05, 0x10A06 ), new Interval( 0x10A0C, 0x10A0F ),
124125
new Interval( 0x10A38, 0x10A3A ), new Interval( 0x10A3F, 0x10A3F ), new Interval( 0x1D167, 0x1D169 ),
125126
new Interval( 0x1D173, 0x1D182 ), new Interval( 0x1D185, 0x1D18B ), new Interval( 0x1D1AA, 0x1D1AD ),
126-
new Interval( 0x1D242, 0x1D244 ), new Interval( 0xE0001, 0xE0001 ), new Interval( 0xE0020, 0xE007F ),
127-
new Interval( 0xE0100, 0xE01EF )
127+
new Interval( 0x1D242, 0x1D244 ), new Interval( 0x1F3FB, 0x1F3FF ), new Interval( 0xE0001, 0xE0001 ),
128+
new Interval( 0xE0020, 0xE007F ), new Interval( 0xE0100, 0xE01EF )
128129
};
129130

130131
private static class Interval {

terminal/src/test/java/org/jline/utils/AttributedStringTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,19 @@ public void testColors() {
140140
public void testColumns() {
141141
AttributedString message = new AttributedString("👍");
142142
int messageLength = message.columnLength();
143-
assertEquals(1, messageLength);
143+
assertEquals(2, messageLength);
144144
AttributedString messageAgain = message.columnSubSequence(0, messageLength);
145145
assertEquals("👍", messageAgain.toString());
146+
147+
message = new AttributedString(
148+
"\uD83D\uDC46" +
149+
"\uD83D\uDC46\uD83C\uDFFB" +
150+
"\uD83D\uDC46\uD83C\uDFFC" +
151+
"\uD83D\uDC46\uD83C\uDFFD" +
152+
"\uD83D\uDC46\uD83C\uDFFE" +
153+
"\uD83D\uDC46\uD83C\uDFFF");
154+
messageLength = message.columnLength();
155+
assertEquals(12, messageLength);
146156
}
147157

148158
}

0 commit comments

Comments
 (0)