@@ -25,9 +25,22 @@ public final class AnsiParser {
25
25
// implies FLAG_PARSE_DISABLE_SUBSCRIPT
26
26
public static final int FLAG_PARSE_DISABLE_ATTRIBUTES = 0x0002 ;
27
27
// Disable extra color customization other than foreground or background
28
+ // Useful to have consistent display across Android versions
28
29
public static final int FLAG_PARSE_DISABLE_EXTRAS_COLORS = 0x0004 ;
29
30
// Disable subscript and superscript text
30
31
public static final int FLAG_PARSE_DISABLE_SUBSCRIPT = 0x0008 ;
32
+ // Disable all attributes changes
33
+ public static final int FLAGS_DISABLE_ALL =
34
+ FLAG_PARSE_DISABLE_COLORS | FLAG_PARSE_DISABLE_ATTRIBUTES ;
35
+
36
+ /**
37
+ * Replace escape sequence using a control character by a normal escape sequence
38
+ * This allow to use {@link String#trim()} without the risk for the escape sequence
39
+ * to be elso trimmed
40
+ */
41
+ public static String patchEscapeSequence (String string ) {
42
+ return string .replace (ESCAPE2 , ESCAPE1 );
43
+ }
31
44
32
45
public static Spannable parseAsSpannable (@ NonNull String text ) {
33
46
return parseAsSpannable (text , null );
@@ -274,5 +287,9 @@ public static void setAnsiText(@NonNull TextView text,@NonNull String ansiText,
274
287
text .setText (parseAsSpannable (ansiText , parseFlags ));
275
288
}
276
289
290
+ public static String trimEscapeSequences (String string ) {
291
+ return parseAsSpannable (string , FLAGS_DISABLE_ALL ).toString ();
292
+ }
293
+
277
294
private AnsiParser () {}
278
295
}
0 commit comments