|
18 | 18 | import java.nio.charset.Charset;
|
19 | 19 | import java.nio.charset.StandardCharsets;
|
20 | 20 | import java.nio.charset.UnsupportedCharsetException;
|
| 21 | +import java.nio.file.Paths; |
21 | 22 | import java.util.ArrayList;
|
22 | 23 | import java.util.Arrays;
|
23 | 24 | import java.util.Comparator;
|
@@ -491,30 +492,45 @@ private Terminal doBuild() throws IOException {
|
491 | 492 | // forced colored dumb terminal
|
492 | 493 | Boolean color = this.color;
|
493 | 494 | if (color == null) {
|
494 |
| - color = getBoolean(PROP_DUMB_COLOR, false); |
| 495 | + color = getBoolean(PROP_DUMB_COLOR, null); |
| 496 | + } |
| 497 | + if (dumb == null) { |
495 | 498 | // detect emacs using the env variable
|
496 |
| - if (!color) { |
| 499 | + if (color == null) { |
497 | 500 | String emacs = System.getenv("INSIDE_EMACS");
|
498 |
| - color = emacs != null && emacs.contains("comint"); |
| 501 | + if (emacs != null && emacs.contains("comint")) { |
| 502 | + color = true; |
| 503 | + } |
499 | 504 | }
|
500 | 505 | // detect Intellij Idea
|
501 |
| - if (!color) { |
502 |
| - String command = getParentProcessCommand(); |
503 |
| - color = command != null && command.contains("idea"); |
504 |
| - } |
505 |
| - if (!color) { |
506 |
| - color = system.get(TerminalProvider.Stream.Output) && System.getenv("TERM") != null; |
507 |
| - } |
508 |
| - if (!color && dumb == null) { |
509 |
| - if (Log.isDebugEnabled()) { |
510 |
| - Log.warn("input is tty: {}", system.get(TerminalProvider.Stream.Input)); |
511 |
| - Log.warn("output is tty: {}", system.get(TerminalProvider.Stream.Output)); |
512 |
| - Log.warn("error is tty: {}", system.get(TerminalProvider.Stream.Error)); |
513 |
| - Log.warn("Creating a dumb terminal", exception); |
| 506 | + if (color == null) { |
| 507 | + // using the env variable on windows |
| 508 | + String ideHome = System.getenv("IDE_HOME"); |
| 509 | + if (ideHome != null) { |
| 510 | + color = true; |
514 | 511 | } else {
|
515 |
| - Log.warn("Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)"); |
| 512 | + // using the parent process command on unix/mac |
| 513 | + String command = getParentProcessCommand(); |
| 514 | + if (command != null && command.endsWith("/idea")) { |
| 515 | + color = true; |
| 516 | + } |
516 | 517 | }
|
517 | 518 | }
|
| 519 | + if (color == null) { |
| 520 | + color = console != null && System.getenv("TERM") != null; |
| 521 | + } |
| 522 | + if (Log.isDebugEnabled()) { |
| 523 | + Log.warn("input is tty: {}", system.get(TerminalProvider.Stream.Input)); |
| 524 | + Log.warn("output is tty: {}", system.get(TerminalProvider.Stream.Output)); |
| 525 | + Log.warn("error is tty: {}", system.get(TerminalProvider.Stream.Error)); |
| 526 | + Log.warn("Creating a dumb terminal", exception); |
| 527 | + } else { |
| 528 | + Log.warn("Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)"); |
| 529 | + } |
| 530 | + } else { |
| 531 | + if (color == null) { |
| 532 | + color = false; |
| 533 | + } |
518 | 534 | }
|
519 | 535 | terminal = new DumbTerminal(name, color ? Terminal.TYPE_DUMB_COLOR : Terminal.TYPE_DUMB,
|
520 | 536 | new FileInputStream(FileDescriptor.in),
|
|
0 commit comments