Skip to content

Commit

Permalink
3.19.0 Regression - Escape sequences are printed when using Git Bash …
Browse files Browse the repository at this point in the history
…in Windows Terminal, fixes #693
  • Loading branch information
mattirn committed Sep 27, 2021
1 parent 0670361 commit a01fe26
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions terminal/src/main/java/org/jline/terminal/TerminalBuilder.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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)");
Expand Down Expand Up @@ -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;

Expand All @@ -547,21 +548,21 @@ private static class TerminalBuilderSupport {
try {
jnaSupport = load(JnaSupport.class);
consoleOutput = jnaSupport.isConsoleOutput();
jnaFullSupport = true;
} catch (Throwable e) {
jnaSupport = null;
Log.debug("jnaSupport.isConsoleOutput(): ", e);
}
}
if (jansi) {
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;
Expand All @@ -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;
}
Expand Down

0 comments on commit a01fe26

Please sign in to comment.