Skip to content

Commit

Permalink
Check isatty() separately for stdout and stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
udalov committed Jun 13, 2015
1 parent c3b76bc commit 0d398a5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.fusesource.jansi;

import static org.fusesource.jansi.internal.CLibrary.STDERR_FILENO;
import static org.fusesource.jansi.internal.CLibrary.STDOUT_FILENO;
import static org.fusesource.jansi.internal.CLibrary.isatty;

Expand All @@ -37,11 +38,15 @@ public class AnsiConsole {
public static final PrintStream out = new PrintStream(wrapOutputStream(system_out));

public static final PrintStream system_err = System.err;
public static final PrintStream err = new PrintStream(wrapOutputStream(system_err));
public static final PrintStream err = new PrintStream(wrapOutputStream(system_err, STDERR_FILENO));

private static int installed;

public static OutputStream wrapOutputStream(final OutputStream stream) {
return wrapOutputStream(stream, STDOUT_FILENO);
}

public static OutputStream wrapOutputStream(final OutputStream stream, int fileno) {

// If the jansi.passthrough property is set, then don't interpret
// any of the ansi sequences.
Expand Down Expand Up @@ -77,7 +82,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream) {
boolean forceColored = Boolean.getBoolean("jansi.force");
// If we can detect that stdout is not a tty.. then setup
// to strip the ANSI sequences..
int rc = isatty(STDOUT_FILENO);
int rc = isatty(fileno);
if( !forceColored && rc==0 ) {
return new AnsiOutputStream(stream);
}
Expand Down

0 comments on commit 0d398a5

Please sign in to comment.