diff --git a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java index 3d16cfec..a868f10a 100644 --- a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java +++ b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java @@ -35,34 +35,13 @@ public class AnsiConsole { public static final PrintStream system_out = System.out; - public static final PrintStream out; + public static final PrintStream out = new PrintStream( wrapOutputStream( system_out ) ); public static final PrintStream system_err = System.err; - public static final PrintStream err; + public static final PrintStream err = new PrintStream( wrapOutputStream( system_err, STDERR_FILENO ) ); private static int installed; - static - { - PrintStream jansiOut; - PrintStream jansiErr; - - try - { - jansiOut = new PrintStream( wrapOutputStream( system_out ) ); - jansiErr = new PrintStream( wrapOutputStream( system_err, STDERR_FILENO ) ); - } - catch ( final UnsatisfiedLinkError e ) - { - // Failure loading native library. - jansiOut = system_out; - jansiErr = system_err; - } - - out = jansiOut; - err = jansiErr; - } - private AnsiConsole() { } @@ -106,14 +85,12 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen 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(fileno); - if (!isXterm() && !forceColored && rc == 0) { + if (!isXterm() && !forceColored && isatty(fileno) == 0) { return new AnsiOutputStream(stream); } - - // These erros happen if the JNI lib is not available for your platform. - } catch (NoClassDefFoundError ignore) { - } catch (UnsatisfiedLinkError ignore) { + } catch (Throwable ignore) { + // These errors happen if the JNI lib is not available for your platform. + // But since we are on ANSI friendly platform, assume the user is on the console. } // By default we assume your Unix tty can handle ANSI codes.