Skip to content

Commit

Permalink
Create a dumb terminal on windows too, fixes #32.
Browse files Browse the repository at this point in the history
Prints a warning when creating a dumb terminal unless dumb(true) has been explicitely called.
  • Loading branch information
gnodet committed Nov 4, 2016
1 parent 216d28f commit ac603a2
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions src/main/java/org/jline/terminal/TerminalBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static TerminalBuilder builder() {
private String encoding;
private Boolean system;
private boolean jna = true;
private Boolean dumb;
private Attributes attributes;
private Size size;
private boolean nativeSignals = false;
Expand Down Expand Up @@ -89,6 +90,11 @@ public TerminalBuilder jna(boolean jna) {
return this;
}

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

public TerminalBuilder type(String type) {
this.type = type;
return this;
Expand Down Expand Up @@ -165,26 +171,34 @@ private Terminal doBuild() throws IOException {
if (attributes != null || size != null) {
Log.warn("Attributes and size fields are ignored when creating a system terminal");
}
IllegalStateException exception = new IllegalStateException("Unable to create a system terminal");
//
// Cygwin support
//
if (OSUtils.IS_CYGWIN) {
Pty pty = ExecPty.current();
return new PosixSysTerminal(name, type, pty, encoding, nativeSignals, signalHandler);
try {
Pty pty = ExecPty.current();
return new PosixSysTerminal(name, type, pty, encoding, nativeSignals, signalHandler);
} catch (IOException e) {
// Ignore if not a tty
Log.debug("Error creating exec based pty: ", e.getMessage(), e);
exception.addSuppressed(e);
}
}
else if (OSUtils.IS_WINDOWS) {
if (useJna()) {
try {
return new JnaWinSysTerminal(name, nativeSignals, signalHandler);
} catch (Throwable t) {
Log.debug("Error creating JNA based pty: ", t.getMessage(), t);
Log.debug("Error creating JNA based terminal: ", t.getMessage(), t);
exception.addSuppressed(t);
}
}
try {
return new JansiWinSysTerminal(name, nativeSignals, signalHandler);
} catch (NoClassDefFoundError e) {
throw new IllegalStateException("Unable to create a Windows based terminal " +
"because of missing dependencies. Add either JNA or JANSI to your classpath.", e);
} catch (Throwable t) {
Log.debug("Error creating JANSI based terminal: ", t.getMessage(), t);
exception.addSuppressed(t);
}
} else {
Pty pty = null;
Expand All @@ -194,25 +208,33 @@ else if (OSUtils.IS_WINDOWS) {
} catch (Throwable t) {
// ignore
Log.debug("Error creating JNA based pty: ", t.getMessage(), t);
exception.addSuppressed(t);
}
}
if (pty == null) {
try {
pty = ExecPty.current();
} catch (IOException e) {
} catch (Throwable t) {
// Ignore if not a tty
Log.debug("Error creating exec based pty: ", e.getMessage(), e);
Log.debug("Error creating exec based pty: ", t.getMessage(), t);
exception.addSuppressed(t);
}
}
if (pty != null) {
return new PosixSysTerminal(name, type, pty, encoding, nativeSignals, signalHandler);
} else {
return new DumbTerminal(name, type,
new FileInputStream(FileDescriptor.in),
new FileOutputStream(FileDescriptor.out),
encoding, signalHandler);
}
}
if (dumb == null || dumb) {
if (dumb == null) {
Log.warn("Creating a dumb terminal", exception);
}
return new DumbTerminal(name, type,
new FileInputStream(FileDescriptor.in),
new FileOutputStream(FileDescriptor.out),
encoding, signalHandler);
} else {
throw exception;
}
} else {
if (useJna()) {
try {
Expand Down

0 comments on commit ac603a2

Please sign in to comment.