From a01fe264d43ecdf7ab969d4a431cec3f8f840986 Mon Sep 17 00:00:00 2001 From: mattirn Date: Fri, 24 Sep 2021 20:21:33 +0200 Subject: [PATCH] 3.19.0 Regression - Escape sequences are printed when using Git Bash in Windows Terminal, fixes #693 --- .../org/jline/terminal/TerminalBuilder.java | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java b/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java index 92939cba6..c4d8c9706 100644 --- a/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java +++ b/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2020, the original author or authors. + * Copyright (c) 2002-2021, the original author or authors. * * This software is distributable under the BSD license. See the terms of the * BSD license in the documentation provided with this software. @@ -333,27 +333,26 @@ private Terminal doBuild() throws IOException { Log.warn("Attributes and size fields are ignored when creating a system terminal"); } if (OSUtils.IS_WINDOWS) { - if (!OSUtils.IS_CYGWIN && !OSUtils.IS_MSYSTEM) { - boolean ansiPassThrough = OSUtils.IS_CONEMU; - if (tbs.hasJnaSupport()) { - try { - terminal = tbs.getJnaSupport().winSysTerminal(name, type, ansiPassThrough, encoding, codepage - , nativeSignals, signalHandler, paused); - } catch (Throwable t) { - Log.debug("Error creating JNA based terminal: ", t.getMessage(), t); - exception.addSuppressed(t); - } + boolean ansiPassThrough = OSUtils.IS_CONEMU; + if (tbs.hasJnaSupport()) { + try { + terminal = tbs.getJnaSupport().winSysTerminal(name, type, ansiPassThrough, encoding, codepage + , nativeSignals, signalHandler, paused); + } catch (Throwable t) { + Log.debug("Error creating JNA based terminal: ", t.getMessage(), t); + exception.addSuppressed(t); } - if (terminal == null && tbs.hasJansiSupport()) { - try { - terminal = tbs.getJansiSupport().winSysTerminal(name, type, ansiPassThrough, encoding, codepage - , nativeSignals, signalHandler, paused); - } catch (Throwable t) { - Log.debug("Error creating JANSI based terminal: ", t.getMessage(), t); - exception.addSuppressed(t); - } + } + if (terminal == null && tbs.hasJansiSupport()) { + try { + terminal = tbs.getJansiSupport().winSysTerminal(name, type, ansiPassThrough, encoding, codepage + , nativeSignals, signalHandler, paused); + } catch (Throwable t) { + Log.debug("Error creating JANSI based terminal: ", t.getMessage(), t); + exception.addSuppressed(t); } - } else if (exec) { + } + if (terminal == null && exec && (OSUtils.IS_CYGWIN || OSUtils.IS_MSYSTEM)) { // // Cygwin support // @@ -436,8 +435,8 @@ private Terminal doBuild() throws IOException { } if (!color && dumb == null) { if (Log.isDebugEnabled()) { - Log.warn("input is tty: {}", tbs.isConsoleInput()); - Log.warn("output is tty: {}", tbs.isConsoleOutput()); + 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)"); @@ -539,6 +538,8 @@ public static void setTerminalOverride(final Terminal terminal) { private static class TerminalBuilderSupport { private JansiSupport jansiSupport = null; private JnaSupport jnaSupport = null; + private boolean jnaFullSupport; + private boolean jansiFullSupport; private Pty pty = null; private boolean consoleOutput; @@ -547,8 +548,8 @@ private static class TerminalBuilderSupport { try { jnaSupport = load(JnaSupport.class); consoleOutput = jnaSupport.isConsoleOutput(); + jnaFullSupport = true; } catch (Throwable e) { - jnaSupport = null; Log.debug("jnaSupport.isConsoleOutput(): ", e); } } @@ -556,12 +557,12 @@ private static class TerminalBuilderSupport { try { jansiSupport = load(JansiSupport.class); consoleOutput = jansiSupport.isConsoleOutput(); + jansiFullSupport = true; } catch (Throwable e) { - jansiSupport = null; Log.debug("jansiSupport.isConsoleOutput(): ", e); } } - if (jnaSupport == null && jansiSupport == null) { + if (!jnaFullSupport && !jansiFullSupport) { try { pty = ExecPty.current(); consoleOutput = true; @@ -576,12 +577,12 @@ public boolean isConsoleOutput() { } public boolean isConsoleInput() { - if (pty != null) { - return true; - } else if (hasJnaSupport()) { + if (jnaFullSupport) { return jnaSupport.isConsoleInput(); - } else if (hasJansiSupport()) { + } else if (jansiFullSupport) { return jansiSupport.isConsoleInput(); + } else if (pty != null) { + return true; } else { return false; }