Skip to content

Commit

Permalink
JEP424 support
Browse files Browse the repository at this point in the history
Missing windows support
  • Loading branch information
gnodet committed Jun 14, 2022
1 parent 811de60 commit e537321
Show file tree
Hide file tree
Showing 23 changed files with 1,761 additions and 73 deletions.
20 changes: 20 additions & 0 deletions jline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@
<include>**/TTop.java</include>
<include>**/ConsoleEngineImpl.java</include>
</includes>
<excludes>
<exclude>**/jep424/*.java</exclude>
</excludes>
<compilerArgs>
<arg>-Xlint:all,-options</arg>
<arg>-Werror</arg>
Expand All @@ -328,6 +331,7 @@
<excludes>
<exclude>**/TTop.java</exclude>
<exclude>**/ConsoleEngineImpl.java</exclude>
<exclude>**/jep424/*.java</exclude>
</excludes>
<compilerArgs>
<arg>-Xlint:all,-options</arg>
Expand All @@ -337,6 +341,22 @@
</compilerArgs>
</configuration>
</execution>
<execution>
<id>jdk19</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>**/jep424/*.java</include>
</includes>
<release>19</release>
<compilerArgs>
<arg>-Xlint:all,-options</arg>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.1</version>
<configuration>
<showWarnings>true</showWarnings>
<compilerArgs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jline.terminal.Attributes;
import org.jline.terminal.Size;
import org.jline.terminal.impl.AbstractPty;
import org.jline.terminal.spi.JansiSupport;
import org.jline.terminal.spi.TerminalProvider;
import org.jline.terminal.spi.Pty;
import org.jline.utils.OSUtils;

Expand All @@ -25,8 +25,8 @@
import java.lang.reflect.Constructor;

import static org.fusesource.jansi.internal.CLibrary.TCSANOW;
import static org.jline.terminal.impl.jansi.JansiSupportImpl.JANSI_MAJOR_VERSION;
import static org.jline.terminal.impl.jansi.JansiSupportImpl.JANSI_MINOR_VERSION;
import static org.jline.terminal.impl.jansi.JansiTerminalProvider.JANSI_MAJOR_VERSION;
import static org.jline.terminal.impl.jansi.JansiTerminalProvider.JANSI_MINOR_VERSION;
import static org.jline.utils.ExecHelper.exec;

public abstract class JansiNativePty extends AbstractPty implements Pty {
Expand Down Expand Up @@ -173,7 +173,7 @@ protected static FileDescriptor newDescriptor(int fd) {
}
}

public static boolean isPosixSystemStream(JansiSupport.Stream stream) {
public static boolean isPosixSystemStream(TerminalProvider.Stream stream) {
switch (stream) {
case Input: return CLibrary.isatty(0) == 1;
case Output: return CLibrary.isatty(1) == 1;
Expand All @@ -182,7 +182,7 @@ public static boolean isPosixSystemStream(JansiSupport.Stream stream) {
}
}

public static String posixSystemStreamName(JansiSupport.Stream stream) {
public static String posixSystemStreamName(TerminalProvider.Stream stream) {
switch (stream) {
case Input: return CLibrary.ttyname(0);
case Output: return CLibrary.ttyname(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.jline.terminal.impl.jansi.linux.LinuxNativePty;
import org.jline.terminal.impl.jansi.osx.OsXNativePty;
import org.jline.terminal.impl.jansi.win.JansiWinSysTerminal;
import org.jline.terminal.spi.JansiSupport;
import org.jline.terminal.spi.Pty;
import org.jline.terminal.spi.TerminalProvider;
import org.jline.utils.OSUtils;

import java.io.IOException;
Expand All @@ -30,7 +30,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JansiSupportImpl implements JansiSupport {
public class JansiTerminalProvider implements TerminalProvider {

static final int JANSI_MAJOR_VERSION;
static final int JANSI_MINOR_VERSION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.jline.terminal.Cursor;
import org.jline.terminal.Size;
import org.jline.terminal.impl.AbstractWindowsTerminal;
import org.jline.terminal.spi.JansiSupport;
import org.jline.terminal.spi.TerminalProvider;
import org.jline.utils.InfoCmp;
import org.jline.utils.OSUtils;
Expand Down Expand Up @@ -66,7 +65,7 @@ public static JansiWinSysTerminal createTerminal(String name, String type, boole
if (type == null) {
type = OSUtils.IS_CONEMU ? TYPE_WINDOWS_CONEMU : TYPE_WINDOWS;
}
writer = new JansiWinConsoleWriter();
writer = newConsoleWriter();
} else {
if (Kernel32.GetConsoleMode(console, mode) == 0 ) {
throw new IOException("Failed to get console mode: " + getLastErrorMessage());
Expand All @@ -75,17 +74,17 @@ public static JansiWinSysTerminal createTerminal(String name, String type, boole
if (type == null) {
type = TYPE_WINDOWS_VTP;
}
writer = new JansiWinConsoleWriter();
writer = newConsoleWriter();
} else if (OSUtils.IS_CONEMU) {
if (type == null) {
type = TYPE_WINDOWS_CONEMU;
}
writer = new JansiWinConsoleWriter();
writer = newConsoleWriter();
} else {
if (type == null) {
type = TYPE_WINDOWS;
}
writer = new WindowsAnsiWriter(new BufferedWriter(new JansiWinConsoleWriter()));
writer = new WindowsAnsiWriter(new BufferedWriter(newConsoleWriter()));
}
}
if (Kernel32.GetConsoleMode(consoleIn, mode) == 0) {
Expand All @@ -100,7 +99,11 @@ public static JansiWinSysTerminal createTerminal(String name, String type, boole
return terminal;
}

public static boolean isWindowsSystemStream(JansiSupport.Stream stream) {
private static Writer newConsoleWriter() {
return new JansiWinConsoleWriter();
}

public static boolean isWindowsSystemStream(TerminalProvider.Stream stream) {
int[] mode = new int[1];
long console;
switch (stream) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (C) 2022 the original author(s).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
class = org.jline.terminal.impl.jansi.JansiTerminalProvider
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

import static org.junit.Assert.assertEquals;

public class JansiSupportImplTest {
public class JansiTerminalProviderTest
{

@Test
public void testJansiVersion() {
assertEquals(2, JansiSupportImpl.JANSI_MAJOR_VERSION);
assertEquals(4, JansiSupportImpl.JANSI_MINOR_VERSION);
assertEquals(2, JansiTerminalProvider.JANSI_MAJOR_VERSION);
assertEquals(4, JansiTerminalProvider.JANSI_MINOR_VERSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.jline.terminal.impl.PosixPtyTerminal;
import org.jline.terminal.impl.PosixSysTerminal;
import org.jline.terminal.impl.jna.win.JnaWinSysTerminal;
import org.jline.terminal.spi.JnaSupport;
import org.jline.terminal.spi.TerminalProvider;
import org.jline.terminal.spi.Pty;
import org.jline.utils.OSUtils;
Expand All @@ -24,7 +23,7 @@
import java.io.OutputStream;
import java.nio.charset.Charset;

public class JnaSupportImpl implements JnaSupport
public class JnaTerminalProvider implements TerminalProvider
{
@Override
public String name() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.jline.terminal.Cursor;
import org.jline.terminal.Size;
import org.jline.terminal.impl.AbstractWindowsTerminal;
import org.jline.terminal.spi.JnaSupport;
import org.jline.terminal.spi.TerminalProvider;
import org.jline.utils.InfoCmp;
import org.jline.utils.OSUtils;
Expand Down Expand Up @@ -69,7 +68,7 @@ public static JnaWinSysTerminal createTerminal(String name, String type, boolean
return terminal;
}

public static boolean isWindowsSystemStream(JnaSupport.Stream stream) {
public static boolean isWindowsSystemStream(TerminalProvider.Stream stream) {
try {
IntByReference mode = new IntByReference();
Pointer console;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (C) 2022 the original author(s).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
class = org.jline.terminal.impl.jna.JnaTerminalProvider
35 changes: 35 additions & 0 deletions terminal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,41 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<excludes>
<exclude>**/jep424/*.java</exclude>
</excludes>
<compilerArgs>
<arg>-Xlint:all,-options</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>jdk19</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>**/jep424/*.java</include>
</includes>
<release>19</release>
<compilerArgs>
<arg>-Xlint:all,-options</arg>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
30 changes: 24 additions & 6 deletions terminal/src/main/java/org/jline/terminal/TerminalBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
import org.jline.terminal.impl.AbstractTerminal;
import org.jline.terminal.impl.AbstractWindowsTerminal;
import org.jline.terminal.impl.DumbTerminal;
import org.jline.terminal.impl.ExecSupport;
import org.jline.terminal.spi.JansiSupport;
import org.jline.terminal.spi.JnaSupport;
import org.jline.terminal.spi.TerminalProvider;
import org.jline.utils.Log;
import org.jline.utils.OSUtils;
Expand All @@ -54,6 +51,7 @@ public final class TerminalBuilder {
public static final String PROP_JNA = "org.jline.terminal.jna";
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_JEP424 = "org.jline.terminal.jep424";
public static final String PROP_DUMB = "org.jline.terminal.dumb";
public static final String PROP_DUMB_COLOR = "org.jline.terminal.dumb.color";
public static final String PROP_OUTPUT = "org.jline.terminal.output";
Expand Down Expand Up @@ -120,6 +118,7 @@ public static TerminalBuilder builder() {
private Boolean jna;
private Boolean jansi;
private Boolean exec;
private Boolean jep424;
private Boolean dumb;
private Boolean color;
private Attributes attributes;
Expand Down Expand Up @@ -176,6 +175,11 @@ public TerminalBuilder exec(boolean exec) {
return this;
}

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

public TerminalBuilder dumb(boolean dumb) {
this.dumb = dumb;
return this;
Expand Down Expand Up @@ -360,15 +364,28 @@ private Terminal doBuild() throws IOException {
if (exec == null) {
exec = getBoolean(PROP_EXEC, true);
}
Boolean jep424 = this.jep424;
if (jep424 == null) {
jep424 = getBoolean(PROP_JEP424, true);
}
Boolean dumb = this.dumb;
if (dumb == null) {
dumb = getBoolean(PROP_DUMB, null);
}
IllegalStateException exception = new IllegalStateException("Unable to create a terminal");
List<TerminalProvider> providers = new ArrayList<>();
if (jep424) {
try {
TerminalProvider provider = TerminalProvider.load("jep424");
providers.add(provider);
} catch (Throwable t) {
Log.debug("Unable to load JEP424 support: ", t);
exception.addSuppressed(t);
}
}
if (jna) {
try {
TerminalProvider provider = load(JnaSupport.class);
TerminalProvider provider = TerminalProvider.load("jna");
providers.add(provider);
} catch (Throwable t) {
Log.debug("Unable to load JNA support: ", t);
Expand All @@ -377,7 +394,7 @@ private Terminal doBuild() throws IOException {
}
if (jansi) {
try {
TerminalProvider provider = load(JansiSupport.class);
TerminalProvider provider = TerminalProvider.load("jansi");
providers.add(provider);
} catch (Throwable t) {
Log.debug("Unable to load JANSI support: ", t);
Expand All @@ -387,7 +404,8 @@ private Terminal doBuild() throws IOException {
if (exec)
{
try {
providers.add(new ExecSupport());
TerminalProvider provider = TerminalProvider.load("exec");
providers.add(provider);
} catch (Throwable t) {
Log.debug("Unable to load EXEC support: ", t);
exception.addSuppressed(t);
Expand Down
Loading

0 comments on commit e537321

Please sign in to comment.