Skip to content
Closed
Show file tree
Hide file tree
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
27 changes: 17 additions & 10 deletions jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ public class AnsiConsole {

static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");

static final boolean IS_CYGWIN = IS_WINDOWS
&& System.getenv("PWD") != null
&& System.getenv("PWD").startsWith("/")
&& !"cygwin".equals(System.getenv("TERM"));
/**
* true if console emulator supports ANSI, according to environement variable "ConEmuANSI"
* This env is standard in cmder (https://cmder.net/), conemu (https://conemu.github.io), ..
*
* Notice that being inside Cygwin (bash.exe) has nothing to do with the console terminal.
* You can open a plain old Windows terminal (cmd.exe), then start cygwin bash.
*/
static final boolean IS_CON_EMU_ANSI =
"ON".equals(System.getenv("ConEmuANSI"));

static final boolean IS_MINGW_XTERM = IS_WINDOWS
&& System.getenv("MSYSTEM") != null
Expand Down Expand Up @@ -124,9 +129,10 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
return new AnsiOutputStream(stream);
}

if (IS_WINDOWS && !IS_CYGWIN && !IS_MINGW_XTERM) {

// On windows we know the console does not interpret ANSI codes..
if (IS_WINDOWS && !IS_CON_EMU_ANSI && !IS_MINGW_XTERM) {
// On windows, when using default terminal (cmd.exe or power shell)
// but not special console emulator (cmder or conemu),
// we know the console does not interpret ANSI codes..
try {
jansiOutputType = JansiOutputType.WINDOWS;
return new WindowsAnsiOutputStream(stream, fileno == STDOUT_FILENO);
Expand Down Expand Up @@ -202,9 +208,10 @@ public static PrintStream wrapPrintStream(final PrintStream ps, int fileno) {
return new AnsiPrintStream(ps);
}

if (IS_WINDOWS && !IS_CYGWIN && !IS_MINGW_XTERM) {

// On windows we know the console does not interpret ANSI codes..
if (IS_WINDOWS && !IS_CON_EMU_ANSI && !IS_MINGW_XTERM) {
// On windows, when using default terminal (cmd.exe or power shell)
// but not special console emulator (cmder or conemu),
// we know the console does not interpret ANSI codes..
try {
jansiOutputType = JansiOutputType.WINDOWS;
return new WindowsAnsiPrintStream(ps, fileno == STDOUT_FILENO);
Expand Down
2 changes: 1 addition & 1 deletion jansi/src/main/java/org/fusesource/jansi/AnsiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public static void main(String... args) throws IOException {

System.out.println("IS_WINDOWS: " + AnsiConsole.IS_WINDOWS);
if (AnsiConsole.IS_WINDOWS) {
System.out.println("IS_CYGWIN: " + AnsiConsole.IS_CYGWIN);
System.out.println("IS_MINGW_XTERM: " + AnsiConsole.IS_MINGW_XTERM);
System.out.println("IS_CON_EMU_ANSI: " + AnsiConsole.IS_CON_EMU_ANSI);
}

System.out.println();
Expand Down