Skip to content

Commit

Permalink
Approximate istty() by checking System.console() != null. Closes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Apr 3, 2017
1 parent 9f469f0 commit c2def15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,15 @@ public static class Ansi {
static final String WHITE = "\u001B[37m";
static final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
static final boolean isXterm = System.getenv("TERM") != null && System.getenv("TERM").startsWith("xterm");

private static boolean forceAnsiOn() { return ansi != null && ansi; }
static final boolean ISATTY = calcTTY();
// http://stackoverflow.com/questions/1403772/how-can-i-check-if-a-java-programs-input-output-streams-are-connected-to-a-term
static final boolean calcTTY() {
try { return System.class.getDeclaredMethod("console").invoke(null) != null; }
catch (Throwable reflectionFailed) { return true; }
}
private static boolean ansiPossible() { return ISATTY && (!isWindows || isXterm); }
private static boolean forceAnsiOn() { return ansi != null && ansi; }
private static boolean forceAnsiOff() { return ansi != null && !ansi; }
private static boolean ansiPossible() { return !isWindows || isXterm; }
private static boolean enabled(String t) { return t.length() == 0 ? false
: forceAnsiOn() || (ansiPossible() && !forceAnsiOff()); }

Expand Down

0 comments on commit c2def15

Please sign in to comment.