Skip to content

Commit 6d69642

Browse files
gnodetmattirn
authored andcommitted
Add a color field on the TerminalBuilder to control the dumb terminal
1 parent a3bf295 commit 6d69642

1 file changed

Lines changed: 29 additions & 20 deletions

File tree

terminal/src/main/java/org/jline/terminal/TerminalBuilder.java

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public static TerminalBuilder builder() {
100100
private Boolean jansi;
101101
private Boolean exec;
102102
private Boolean dumb;
103+
private Boolean color;
103104
private Attributes attributes;
104105
private Size size;
105106
private boolean nativeSignals = false;
@@ -150,6 +151,11 @@ public TerminalBuilder type(String type) {
150151
return this;
151152
}
152153

154+
public TerminalBuilder color(boolean color) {
155+
this.color = color;
156+
return this;
157+
}
158+
153159
/**
154160
* Set the encoding to use for reading/writing from the console.
155161
* If {@code null} (the default value), JLine will automatically select
@@ -413,26 +419,29 @@ private Terminal doBuild() throws IOException {
413419
}
414420
if (terminal == null && (dumb == null || dumb)) {
415421
// forced colored dumb terminal
416-
boolean color = getBoolean(PROP_DUMB_COLOR, false);
417-
// detect emacs using the env variable
418-
if (!color) {
419-
color = System.getenv("INSIDE_EMACS") != null;
420-
}
421-
// detect Intellij Idea
422-
if (!color) {
423-
String command = getParentProcessCommand();
424-
color = command != null && command.contains("idea");
425-
}
426-
if (!color) {
427-
color = tbs.isConsoleOutput() && System.getenv("TERM") != null;
428-
}
429-
if (!color && dumb == null) {
430-
if (Log.isDebugEnabled()) {
431-
Log.warn("input is tty: {}", tbs.isConsoleInput());
432-
Log.warn("output is tty: {}", tbs.isConsoleOutput());
433-
Log.warn("Creating a dumb terminal", exception);
434-
} else {
435-
Log.warn("Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)");
422+
Boolean color = this.color;
423+
if (color == null) {
424+
color = getBoolean(PROP_DUMB_COLOR, false);
425+
// detect emacs using the env variable
426+
if (!color) {
427+
color = System.getenv("INSIDE_EMACS") != null;
428+
}
429+
// detect Intellij Idea
430+
if (!color) {
431+
String command = getParentProcessCommand();
432+
color = command != null && command.contains("idea");
433+
}
434+
if (!color) {
435+
color = tbs.isConsoleOutput() && System.getenv("TERM") != null;
436+
}
437+
if (!color && dumb == null) {
438+
if (Log.isDebugEnabled()) {
439+
Log.warn("input is tty: {}", tbs.isConsoleInput());
440+
Log.warn("output is tty: {}", tbs.isConsoleOutput());
441+
Log.warn("Creating a dumb terminal", exception);
442+
} else {
443+
Log.warn("Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)");
444+
}
436445
}
437446
}
438447
terminal = new DumbTerminal(name, color ? Terminal.TYPE_DUMB_COLOR : Terminal.TYPE_DUMB,

0 commit comments

Comments
 (0)