Skip to content

Commit

Permalink
Improve fix for issue #55. If we can't load that natives for any reas…
Browse files Browse the repository at this point in the history
…on, fallback to better defaults.
  • Loading branch information
chirino committed Jun 20, 2016
1 parent f2afbfc commit fad337e
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fad337e

Please sign in to comment.