AttributedString extends AttributedCharSequence { public static AttributedString fromAnsi(String ansi) { return fromAnsi(ansi, 0); } AttributedString(CharSequence str);  AttributedString(CharSequence str, int start, int end);  AttributedString(CharSequence str, AttributedStyle s);  AttributedString(CharSequence str, int start, int end, AttributedStyle s);   AttributedString(char[] buffer, int[] style, int start, int end); static AttributedString fromAnsi(String ansi); static AttributedString fromAnsi(String ansi, int tabs); static AttributedString fromAnsi(String ansi, List<Integer> tabs); static String stripAnsi(String ansi); @Override int length(); @Override AttributedStyle styleAt(int index); @Override AttributedString subSequence(int start, int end); AttributedString styleMatches(Pattern pattern, AttributedStyle style); @Override boolean equals(Object o); @Override int hashCode(); static AttributedString join(AttributedString delimiter, AttributedString... elements); static AttributedString join(AttributedString delimiter, Iterable<AttributedString> elements); static final AttributedString EMPTY; static final AttributedString NEWLINE; }
@Test public void testRuns() { String ansi = "echo \033[1mfoo\033[0m \033[43mblue\033[0m "; AttributedString sb = AttributedString.fromAnsi(ansi); assertEquals(0, sb.runStart(2)); assertEquals(5, sb.runLimit(2)); assertEquals(5, sb.runStart(5)); assertEquals(8, sb.runLimit(6)); assertEquals(8, sb.runStart(8)); assertEquals(9, sb.runLimit(8)); assertEquals(9, sb.runStart(9)); assertEquals(13, sb.runLimit(9)); }
@Test public void testAnsi() { String ansi = "echo \033[1mfoo \033[43mblue\033[0m "; AttributedString str = AttributedString.fromAnsi(ansi); assertEquals(ansi, str.toAnsi()); }