Skip to content

Commit

Permalink
Tidy up a bit, add real emacs support and remove requirement on java9
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Mar 7, 2018
1 parent 1b10052 commit 1be52a1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<jna.version>4.2.2</jna.version>
Expand Down
12 changes: 0 additions & 12 deletions terminal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>

<parent>
<groupId>org.jline</groupId>
Expand Down
40 changes: 25 additions & 15 deletions terminal/src/main/java/org/jline/terminal/TerminalBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Optional;
import java.util.ServiceLoader;

import org.jline.terminal.impl.AbstractPosixTerminal;
Expand Down Expand Up @@ -49,6 +50,7 @@ public final class TerminalBuilder {
public static final String PROP_JANSI = "org.jline.terminal.jansi";
public static final String PROP_EXEC = "org.jline.terminal.exec";
public static final String PROP_DUMB = "org.jline.terminal.dumb";
public static final String PROP_DUMB_COLOR = "org.jline.terminal.dumb.color";

/**
* Returns the default system terminal.
Expand Down Expand Up @@ -346,21 +348,16 @@ private Terminal doBuild() throws IOException {
}
}
if (dumb == null || dumb) {
boolean color = false;
try {
ProcessHandle parent = ProcessHandle.current().parent().orElse(null);
if (parent != null) {
String command = parent.info().command().orElse(null);
if (command != null) {
if (command.contains("emacs")
|| command.contains("idea")
|| command.contains("eclipse")) {
color = true;
}
}
}
} catch (Throwable t) {
// ignore
// 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 && dumb == null) {
if (Log.isDebugEnabled()) {
Expand Down Expand Up @@ -404,6 +401,19 @@ private Terminal doBuild() throws IOException {
}
}

private static String getParentProcessCommand() {
try {
Class<?> phClass = Class.forName("java.lang.ProcessHandler");
Object current = phClass.getMethod("current").invoke(null);
Object parent = ((Optional<?>) phClass.getMethod("parent").invoke(current)).orElse(null);
Object info = phClass.getMethod("info").invoke(parent);
Object command = ((Optional<?>) info.getClass().getMethod("command").invoke(info)).orElse(null);
return (String) command;
} catch (Throwable t) {
return null;
}
}

private static Boolean getBoolean(String name, Boolean def) {
try {
String str = System.getProperty(name);
Expand Down

0 comments on commit 1be52a1

Please sign in to comment.