Skip to content

Commit

Permalink
Leverage Clibrary.ttyname method
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 27, 2017
1 parent 5463fd6 commit e92c739
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,14 @@ public JansiNativePty(int master, FileDescriptor masterFD, int slave, FileDescri
}

protected static String ttyname() throws IOException {
if (JANSI_MAJOR_VERSION > 1 || JANSI_MAJOR_VERSION == 1 && JANSI_MINOR_VERSION >= 16) {
String name = CLibrary.ttyname(0);
if (name != null) {
name = name.trim();
}
if (name == null || name.isEmpty()) {
throw new IOException("Not a tty");
}
return name;
} else {
try {
String name = exec(true, OSUtils.TTY_COMMAND);
return name.trim();
} catch (IOException e) {
throw new IOException("Not a tty", e);
}
String name = CLibrary.ttyname(0);
if (name != null) {
name = name.trim();
}
if (name == null || name.isEmpty()) {
throw new IOException("Not a tty");
}
return name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
*/
package org.jline.terminal.impl.jansi;

import org.fusesource.jansi.internal.CLibrary;
import org.fusesource.jansi.Ansi;
import org.jline.terminal.Terminal;
import org.jline.terminal.impl.jansi.freebsd.FreeBsdNativePty;
import org.jline.terminal.impl.jansi.linux.LinuxNativePty;
import org.jline.terminal.impl.jansi.osx.OsXNativePty;
import org.jline.terminal.impl.jansi.solaris.SolarisNativePty;
import org.jline.terminal.impl.jansi.win.JansiWinSysTerminal;
import org.jline.terminal.spi.JansiSupport;
import org.jline.terminal.spi.Pty;
Expand All @@ -29,7 +28,7 @@ public class JansiSupportImpl implements JansiSupport {
static {
int major = 0, minor = 0;
try {
String v = CLibrary.class.getPackage().getImplementationVersion();
String v = Ansi.class.getPackage().getImplementationVersion();
if (v != null) {
Matcher m = Pattern.compile("([0-9]+)\\.([0-9]+)([\\.-]\\S+)?").matcher(v);
if (m.matches()) {
Expand All @@ -53,7 +52,9 @@ public Pty current() throws IOException {
}
}
else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) {
return OsXNativePty.current();
if (JANSI_MAJOR_VERSION > 0) {
return OsXNativePty.current();
}
}
else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) {
// Solaris is not supported by jansi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.EnumMap;
import java.util.EnumSet;

import static org.jline.utils.ExecHelper.exec;

public class LinuxNativePty extends JansiNativePty {

public static LinuxNativePty current() throws IOException {
Expand Down

0 comments on commit e92c739

Please sign in to comment.