From a2608151491d4ebc56533465e752a44a47bf4154 Mon Sep 17 00:00:00 2001 From: Yves Langisch Date: Mon, 12 Jan 2015 22:23:21 +0100 Subject: [PATCH] Detect cygwin --- .../main/java/org/fusesource/jansi/AnsiConsole.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java index 060a2645..e43679e1 100644 --- a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java +++ b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java @@ -24,6 +24,8 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.util.Map; +import java.util.Properties; /** * Provides consistent access to an ANSI aware console PrintStream. @@ -56,7 +58,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream) { } String os = System.getProperty("os.name"); - if( os.startsWith("Windows") ) { + if( os.startsWith("Windows") && !isCygwin()) { // On windows we know the console does not interpret ANSI codes.. try { @@ -78,6 +80,8 @@ public static OutputStream wrapOutputStream(final OutputStream stream) { // If we can detect that stdout is not a tty.. then setup // to strip the ANSI sequences.. int rc = isatty(STDOUT_FILENO); + if(isCygwin()) + rc=1; if( !forceColored && rc==0 ) { return new AnsiOutputStream(stream); } @@ -100,6 +104,11 @@ public void close() throws IOException { }; } + private static boolean isCygwin(){ + String term = System.getenv("TERM"); + return (term != null && term.equals("cygwin")); + } + /** * If the standard out natively supports ANSI escape codes, then this just * returns System.out, otherwise it will provide an ANSI aware PrintStream