Skip to content

Commit 2f866c4

Browse files
committed
#146 add support for ConEmu (used by cmder)
closes 146
1 parent fe749a5 commit 2f866c4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public class AnsiConsole {
4848

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

51+
/**
52+
* <a href="https://conemu.github.io">ConEmu</a> ANSI X3.64 support enabled,
53+
* used by <a href="https://cmder.net/">cmder</a>
54+
*/
55+
static final boolean IS_CON_EMU_ANSI = "ON".equals(System.getenv("ConEmuANSI"));
56+
5157
static final boolean IS_CYGWIN = IS_WINDOWS
5258
&& System.getenv("PWD") != null
5359
&& System.getenv("PWD").startsWith("/")
@@ -124,9 +130,10 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
124130
return new AnsiOutputStream(stream);
125131
}
126132

127-
if (IS_WINDOWS && !IS_CYGWIN && !IS_MINGW_XTERM) {
133+
if (IS_WINDOWS && !(IS_CON_EMU_ANSI || IS_CYGWIN || IS_MINGW_XTERM)) {
128134

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

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

205-
if (IS_WINDOWS && !IS_CYGWIN && !IS_MINGW_XTERM) {
212+
if (IS_WINDOWS && !(IS_CON_EMU_ANSI || IS_CYGWIN || IS_MINGW_XTERM)) {
206213

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

221-
// We must be on some Unix variant, including Cygwin or MSYS(2) on Windows...
229+
// We must be on some Unix variant or ANSI-enabled ConEmu, Cygwin or MSYS(2) on Windows...
222230
try {
223231
// If the jansi.force property is set, then we force to output
224232
// the ansi escapes for piping it into ansi color aware commands (e.g. less -r)

jansi/src/main/java/org/fusesource/jansi/AnsiMain.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public static void main(String... args) throws IOException {
8787

8888
System.out.println("IS_WINDOWS: " + AnsiConsole.IS_WINDOWS);
8989
if (AnsiConsole.IS_WINDOWS) {
90+
System.out.println("IS_CON_EMU_ANSI: " + AnsiConsole.IS_CON_EMU_ANSI);
9091
System.out.println("IS_CYGWIN: " + AnsiConsole.IS_CYGWIN);
9192
System.out.println("IS_MINGW_XTERM: " + AnsiConsole.IS_MINGW_XTERM);
9293
}

0 commit comments

Comments
 (0)