Skip to content

Commit 399473a

Browse files
committed
Handle SGRs with multiple options
1 parent d386c6a commit 399473a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/main/java/org/fusesource/jansi/io/AnsiProcessor.java

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ protected boolean processEscapeCommand(ArrayList<Object> options, int command) t
128128
} else if (100 <= value && value <= 107) {
129129
processSetBackgroundColor(value - 100, true);
130130
} else if (value == 38 || value == 48) {
131+
if (!optionsIterator.hasNext()) {
132+
continue;
133+
}
131134
// extended color like `esc[38;5;<index>m` or `esc[38;2;<r>;<g>;<b>m`
132135
int arg2or5 = getNextOptionInt(optionsIterator);
133136
if (arg2or5 == 2) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.fusesource.jansi.io;
2+
3+
import org.fusesource.jansi.AnsiColors;
4+
import org.fusesource.jansi.AnsiMode;
5+
import org.fusesource.jansi.AnsiType;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.io.ByteArrayOutputStream;
9+
import java.io.IOException;
10+
import java.nio.charset.Charset;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
14+
class AnsiOutputStreamTest {
15+
@Test
16+
void canHandleSgrsWithMultipleOptions() throws IOException {
17+
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
18+
final AnsiOutputStream ansiOutput = new AnsiOutputStream(baos, AnsiMode.Strip, null, AnsiType.Emulation, AnsiColors.TrueColor, Charset.forName("UTF-8"), null, null, false);
19+
ansiOutput.write("\u001B[33mbanana_1 |\u001B[0m 19:59:14.353\u001B[0;38m [debug] Lager installed handler {lager_file_backend,\"banana.log\"} into lager_event\u001B[0m\n".getBytes());
20+
assertEquals("banana_1 | 19:59:14.353 [debug] Lager installed handler {lager_file_backend,\"banana.log\"} into lager_event\n", baos.toString());
21+
}
22+
}

0 commit comments

Comments
 (0)