Skip to content

Commit

Permalink
Handle SGRs with multiple options
Browse files Browse the repository at this point in the history
  • Loading branch information
tszmytka committed Jan 3, 2021
1 parent d386c6a commit 399473a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/fusesource/jansi/io/AnsiProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ protected boolean processEscapeCommand(ArrayList<Object> options, int command) t
} else if (100 <= value && value <= 107) {
processSetBackgroundColor(value - 100, true);
} else if (value == 38 || value == 48) {
if (!optionsIterator.hasNext()) {
continue;
}
// extended color like `esc[38;5;<index>m` or `esc[38;2;<r>;<g>;<b>m`
int arg2or5 = getNextOptionInt(optionsIterator);
if (arg2or5 == 2) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/fusesource/jansi/io/AnsiOutputStreamTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.fusesource.jansi.io;

import org.fusesource.jansi.AnsiColors;
import org.fusesource.jansi.AnsiMode;
import org.fusesource.jansi.AnsiType;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;

import static org.junit.jupiter.api.Assertions.assertEquals;

class AnsiOutputStreamTest {
@Test
void canHandleSgrsWithMultipleOptions() throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final AnsiOutputStream ansiOutput = new AnsiOutputStream(baos, AnsiMode.Strip, null, AnsiType.Emulation, AnsiColors.TrueColor, Charset.forName("UTF-8"), null, null, false);
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());
assertEquals("banana_1 | 19:59:14.353 [debug] Lager installed handler {lager_file_backend,\"banana.log\"} into lager_event\n", baos.toString());
}
}

0 comments on commit 399473a

Please sign in to comment.