Skip to content

Commit de69895

Browse files
committed
fix: handling non-printable chars in SequenceIterator
1 parent 0e057d8 commit de69895

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

twinkle-ansi/src/main/java/org/codejive/twinkle/util/SequenceIterator.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,10 @@ public int width() {
115115
}
116116

117117
protected int calculateWidth(int cp) {
118-
// ANSI escapes and Control characters (except space) are 0 width
119-
if (cp == Ansi.ESC || (cp < 0x20 && cp != '\n' && cp != '\r') || cp == 0x7F) {
120-
return 0;
121-
}
122-
// Line breaks are handled as 0-width movements
123-
if (cp == '\n' || cp == '\r') {
118+
int type = Character.getType(cp);
119+
if (type == Character.CONTROL // Cc: Control characters (like \n, \t)
120+
|| type == Character.FORMAT // Cf: Format (like Zero Width Joiner)
121+
|| type == Character.UNASSIGNED) { // Cn: Unassigned (reserved)
124122
return 0;
125123
}
126124

0 commit comments

Comments
 (0)