Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect cygwin #32

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
Expand All @@ -100,6 +104,11 @@ public void close() throws IOException {
};
}

private static boolean isCygwin(){
String term = System.getenv("TERM");
return (term != null && term.equals("cygwin"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no Cygwin expert, but I've been testing JLine2/Jansi on Cygwin for Jython 2.7. On mintty, which is the default terminal for current Cygwin, TERM is "xterm"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also believe this should say "xterm", which is what TERM is set to in MSYS(2) / Git for Windows, too. I'll post a follow-up PR which fixes this.

}

/**
* If the standard out natively supports ANSI escape codes, then this just
* returns System.out, otherwise it will provide an ANSI aware PrintStream
Expand Down