Skip to content

Commit

Permalink
Fix Ansi outputting escape sequences when disabled, fixes #215
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jul 23, 2021
1 parent 3ba11e9 commit 01d68f0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/fusesource/jansi/Ansi.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,26 @@ public Ansi bgBright(Color color) {
return this;
}

@Override
public Ansi fg(int color) {
return this;
}

@Override
public Ansi fgRgb(int r, int g, int b) {
return this;
}

@Override
public Ansi bg(int color) {
return this;
}

@Override
public Ansi bgRgb(int r, int g, int b) {
return this;
}

@Override
public Ansi a(Attribute attribute) {
return this;
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/fusesource/jansi/AnsiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ public void testCursorUpLine(int n, String expected) {
assertAnsi(expected, new Ansi().cursorUpLine(n));
}

@Test
public void testColorDisabled() {
Ansi.setEnabled(false);
try {
assertEquals("test", Ansi.ansi().fg(32).a("t").fgRgb(0).a("e").bg(24).a("s").bgRgb(100).a("t").toString());
} finally {
Ansi.setEnabled(true);
}
}

private static void assertAnsi(String expected, Ansi actual) {
assertEquals(expected.replace("ESC", "\033"), actual.toString());
}
Expand Down

0 comments on commit 01d68f0

Please sign in to comment.