From 6d696428782d32f17bd8c3d4a12c42b1a28d1ca5 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 1 Apr 2021 15:28:13 +0200 Subject: [PATCH] Add a color field on the TerminalBuilder to control the dumb terminal --- .../org/jline/terminal/TerminalBuilder.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java b/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java index 1b5432f91..92939cba6 100644 --- a/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java +++ b/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java @@ -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; @@ -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 @@ -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,