Skip to content

Commit

Permalink
Rename isCygwin() to isXterm()
Browse files Browse the repository at this point in the history
Strictly speaking this method does not check for Cygwin (as it e.g. does
not check to be on Windows) but only for XTerm (which in conjunction
with being on Windows is a sign of running under Cygwin).

Simplify the code a bit to get rid of the explicit null check long the
way.
  • Loading branch information
sschuberth committed Jun 15, 2016
1 parent a54d2b5 commit 25ed28f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Expand Up @@ -85,7 +85,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
}

String os = System.getProperty("os.name");
if (os.startsWith("Windows") && !isCygwin()) {
if (os.startsWith("Windows") && !isXterm()) {

// On windows we know the console does not interpret ANSI codes..
try {
Expand All @@ -107,7 +107,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
// If we can detect that stdout is not a tty.. then setup
// to strip the ANSI sequences..
int rc = isatty(fileno);
if (!isCygwin() && !forceColored && rc == 0) {
if (!isXterm() && !forceColored && rc == 0) {
return new AnsiOutputStream(stream);
}

Expand All @@ -129,9 +129,8 @@ public void close() throws IOException {
};
}

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

This comment has been minimized.

Copy link
@michael-o

michael-o Jun 20, 2016

Contributor

What about xterm-color? It would fail here.

This comment has been minimized.

Copy link
@sschuberth

sschuberth Jun 20, 2016

Author Contributor

I wasn't aware of that being a valid TERM value. So back to something like return term != null && term.startsWith("xterm");?

This comment has been minimized.

Copy link
@michael-o

michael-o Jun 20, 2016

Contributor

Yes. That will suffice, see here and here or here for xterm references. It might only apply to old systems where xterm does support colors by default.

}

/**
Expand Down

0 comments on commit 25ed28f

Please sign in to comment.