Skip to content

Commit

Permalink
Add a color field on the TerminalBuilder to control the dumb terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored and mattirn committed Apr 24, 2021
1 parent a3bf295 commit 6d69642
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions terminal/src/main/java/org/jline/terminal/TerminalBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static TerminalBuilder builder() {
private Boolean jansi;
private Boolean exec;
private Boolean dumb;
private Boolean color;
private Attributes attributes;
private Size size;
private boolean nativeSignals = false;
Expand Down Expand Up @@ -150,6 +151,11 @@ public TerminalBuilder type(String type) {
return this;
}

public TerminalBuilder color(boolean color) {
this.color = color;
return this;
}

/**
* Set the encoding to use for reading/writing from the console.
* If {@code null} (the default value), JLine will automatically select
Expand Down Expand Up @@ -413,26 +419,29 @@ private Terminal doBuild() throws IOException {
}
if (terminal == null && (dumb == null || dumb)) {
// forced colored dumb terminal
boolean color = getBoolean(PROP_DUMB_COLOR, false);
// detect emacs using the env variable
if (!color) {
color = System.getenv("INSIDE_EMACS") != null;
}
// detect Intellij Idea
if (!color) {
String command = getParentProcessCommand();
color = command != null && command.contains("idea");
}
if (!color) {
color = tbs.isConsoleOutput() && System.getenv("TERM") != null;
}
if (!color && dumb == null) {
if (Log.isDebugEnabled()) {
Log.warn("input is tty: {}", tbs.isConsoleInput());
Log.warn("output is tty: {}", tbs.isConsoleOutput());
Log.warn("Creating a dumb terminal", exception);
} else {
Log.warn("Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)");
Boolean color = this.color;
if (color == null) {
color = getBoolean(PROP_DUMB_COLOR, false);
// detect emacs using the env variable
if (!color) {
color = System.getenv("INSIDE_EMACS") != null;
}
// detect Intellij Idea
if (!color) {
String command = getParentProcessCommand();
color = command != null && command.contains("idea");
}
if (!color) {
color = tbs.isConsoleOutput() && System.getenv("TERM") != null;
}
if (!color && dumb == null) {
if (Log.isDebugEnabled()) {
Log.warn("input is tty: {}", tbs.isConsoleInput());
Log.warn("output is tty: {}", tbs.isConsoleOutput());
Log.warn("Creating a dumb terminal", exception);
} else {
Log.warn("Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)");
}
}
}
terminal = new DumbTerminal(name, color ? Terminal.TYPE_DUMB_COLOR : Terminal.TYPE_DUMB,
Expand Down

0 comments on commit 6d69642

Please sign in to comment.