Skip to content

Commit

Permalink
#146 add support for ConEmu (used by cmder)
Browse files Browse the repository at this point in the history
closes 146
  • Loading branch information
hboutemy committed Jun 28, 2019
1 parent fe749a5 commit 2f866c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 14 additions & 6 deletions jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public class AnsiConsole {

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

/**
* <a href="https://conemu.github.io">ConEmu</a> ANSI X3.64 support enabled,
* used by <a href="https://cmder.net/">cmder</a>
*/
static final boolean IS_CON_EMU_ANSI = "ON".equals(System.getenv("ConEmuANSI"));

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

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

// On windows we know the console does not interpret ANSI codes..
// On Windows, when no ANSI-capable terminal is used, we know the console does not natively interpret ANSI
// codes but we can use jansi-native Kernel32 API for console
try {
jansiOutputType = JansiOutputType.WINDOWS;
return new WindowsAnsiOutputStream(stream, fileno == STDOUT_FILENO);
Expand All @@ -140,7 +147,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
return new AnsiOutputStream(stream);
}

// We must be on some Unix variant, including Cygwin or MSYS(2) on Windows...
// We must be on some Unix variant or ANSI-enabled ConEmu, Cygwin or MSYS(2) on Windows...
try {
// If the jansi.force property is set, then we force to output
// the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
Expand Down Expand Up @@ -202,9 +209,10 @@ public static PrintStream wrapPrintStream(final PrintStream ps, int fileno) {
return new AnsiPrintStream(ps);
}

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

// On windows we know the console does not interpret ANSI codes..
// On Windows, when no ANSI-capable terminal is used, we know the console does not natively interpret ANSI
// codes but we can use jansi-native Kernel32 API for console
try {
jansiOutputType = JansiOutputType.WINDOWS;
return new WindowsAnsiPrintStream(ps, fileno == STDOUT_FILENO);
Expand All @@ -218,7 +226,7 @@ public static PrintStream wrapPrintStream(final PrintStream ps, int fileno) {
return new AnsiPrintStream(ps);
}

// We must be on some Unix variant, including Cygwin or MSYS(2) on Windows...
// We must be on some Unix variant or ANSI-enabled ConEmu, Cygwin or MSYS(2) on Windows...
try {
// If the jansi.force property is set, then we force to output
// the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
Expand Down
1 change: 1 addition & 0 deletions jansi/src/main/java/org/fusesource/jansi/AnsiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static void main(String... args) throws IOException {

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

0 comments on commit 2f866c4

Please sign in to comment.