Skip to content

Commit

Permalink
JNA or jansi based system terminals do not support the main output st…
Browse files Browse the repository at this point in the history
…ream being redirected, fixes #156
  • Loading branch information
gnodet committed Aug 2, 2017
1 parent ddd7415 commit e2175b7
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,24 @@ public abstract class JansiNativePty implements Pty {

private final int master;
private final int slave;
private final int slaveOut;
private final String name;
private final FileDescriptor masterFD;
private final FileDescriptor slaveFD;
private final FileDescriptor slaveOutFD;

public JansiNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, String name) {
this(master, masterFD, slave, slaveFD, slave, slaveFD, name);
}

public JansiNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
this.master = master;
this.slave = slave;
this.slaveOut = slaveOut;
this.name = name;
this.masterFD = masterFD;
this.slaveFD = slaveFD;
this.slaveOutFD = slaveOutFD;
}

protected static String ttyname() throws IOException {
Expand Down Expand Up @@ -81,6 +89,10 @@ public int getSlave() {
return slave;
}

public int getSlaveOut() {
return slaveOut;
}

public String getName() {
return name;
}
Expand All @@ -93,6 +105,10 @@ public FileDescriptor getSlaveFD() {
return slaveFD;
}

public FileDescriptor getSlaveOutFD() {
return slaveOutFD;
}

public InputStream getMasterInput() {
return new FileInputStream(getMasterFD());
}
Expand All @@ -106,7 +122,7 @@ public InputStream getSlaveInput() {
}

public OutputStream getSlaveOutput() {
return new FileOutputStream(getSlaveFD());
return new FileOutputStream(getSlaveOutFD());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FreeBsdNativePty extends JansiNativePty {
public static FreeBsdNativePty current() throws IOException {
try {
String name = ttyname();
return new FreeBsdNativePty(-1, null, 0, FileDescriptor.in, name);
return new FreeBsdNativePty(-1, null, 0, FileDescriptor.in, 1, FileDescriptor.out, name);
} catch (IOException e) {
throw new IOException("Not a tty", e);
}
Expand All @@ -49,6 +49,9 @@ public FreeBsdNativePty(int master, FileDescriptor masterFD, int slave, FileDesc
super(master, masterFD, slave, slaveFD, name);
}

public FreeBsdNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
}
// CONSTANTS

private static final int VEOF = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class LinuxNativePty extends JansiNativePty {
public static LinuxNativePty current() throws IOException {
try {
String name = ttyname();
return new LinuxNativePty(-1, null, 0, FileDescriptor.in, name);
return new LinuxNativePty(-1, null, 0, FileDescriptor.in, 1, FileDescriptor.out, name);
} catch (IOException e) {
throw new IOException("Not a tty", e);
}
Expand All @@ -49,6 +49,9 @@ public LinuxNativePty(int master, FileDescriptor masterFD, int slave, FileDescri
super(master, masterFD, slave, slaveFD, name);
}

public LinuxNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
}
// CONSTANTS

private static final int VINTR = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class OsXNativePty extends JansiNativePty {
public static OsXNativePty current() throws IOException {
try {
String name = ttyname();
return new OsXNativePty(-1, null, 0, FileDescriptor.in, name);
return new OsXNativePty(-1, null, 0, FileDescriptor.in, 1, FileDescriptor.out, name);
} catch (IOException e) {
throw new IOException("Not a tty", e);
}
Expand All @@ -48,6 +48,9 @@ public OsXNativePty(int master, FileDescriptor masterFD, int slave, FileDescript
super(master, masterFD, slave, slaveFD, name);
}

public OsXNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
}
// CONSTANTS

private static final int VEOF = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SolarisNativePty extends JansiNativePty {
public static SolarisNativePty current() throws IOException {
try {
String name = ttyname();
return new SolarisNativePty(-1, null, 0, FileDescriptor.in, name);
return new SolarisNativePty(-1, null, 0, FileDescriptor.in, 1, FileDescriptor.out, name);
} catch (IOException e) {
throw new IOException("Not a tty", e);
}
Expand All @@ -34,6 +34,9 @@ public SolarisNativePty(int master, FileDescriptor masterFD, int slave, FileDesc
super(master, masterFD, slave, slaveFD, name);
}

public SolarisNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
}
// CONSTANTS

private static final int VINTR = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public abstract class JnaNativePty implements Pty {

private final int master;
private final int slave;
private final int slaveOut;
private final String name;
private final FileDescriptor masterFD;
private final FileDescriptor slaveFD;
private final FileDescriptor slaveOutFD;

public static JnaNativePty current() throws IOException {
if (Platform.isMac()) {
Expand Down Expand Up @@ -62,11 +64,17 @@ public static JnaNativePty open(Attributes attr, Size size) throws IOException {
}

protected JnaNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, String name) {
this(master, masterFD, slave, slaveFD, slave, slaveFD, name);
}

protected JnaNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
this.master = master;
this.slave = slave;
this.slaveOut = slaveOut;
this.name = name;
this.masterFD = masterFD;
this.slaveFD = slaveFD;
this.slaveOutFD = slaveOutFD;
}

@Override
Expand All @@ -87,6 +95,10 @@ public int getSlave() {
return slave;
}

public int getSlaveOut() {
return slaveOut;
}

public String getName() {
return name;
}
Expand All @@ -99,6 +111,10 @@ public FileDescriptor getSlaveFD() {
return slaveFD;
}

public FileDescriptor getSlaveOutFD() {
return slaveOutFD;
}

public InputStream getMasterInput() {
return new FileInputStream(getMasterFD());
}
Expand All @@ -112,7 +128,7 @@ public InputStream getSlaveInput() {
}

public OutputStream getSlaveOutput() {
return new FileOutputStream(getSlaveFD());
return new FileOutputStream(getSlaveOutFD());
}

protected static FileDescriptor newDescriptor(int fd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static FreeBsdNativePty current() throws IOException {
len++;
}
String name = new String(buf, 0, len);
return new FreeBsdNativePty(-1, null, slave, FileDescriptor.in, name);
return new FreeBsdNativePty(-1, null, slave, FileDescriptor.in, 1, FileDescriptor.out, name);
}

public static FreeBsdNativePty open(Attributes attr, Size size) throws IOException {
Expand All @@ -66,6 +66,10 @@ public FreeBsdNativePty(int master, FileDescriptor masterFD, int slave, FileDesc
super(master, masterFD, slave, slaveFD, name);
}

public FreeBsdNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
}

@Override
public Attributes getAttr() throws IOException {
termios termios = new termios();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static LinuxNativePty current() throws IOException {
len++;
}
String name = new String(buf, 0, len);
return new LinuxNativePty(-1, null, slave, FileDescriptor.in, name);
return new LinuxNativePty(-1, null, slave, FileDescriptor.in, 1, FileDescriptor.out, name);
}

public static LinuxNativePty open(Attributes attr, Size size) throws IOException {
Expand All @@ -66,6 +66,10 @@ public LinuxNativePty(int master, FileDescriptor masterFD, int slave, FileDescri
super(master, masterFD, slave, slaveFD, name);
}

public LinuxNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
}

@Override
public Attributes getAttr() throws IOException {
termios termios = new termios();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static OsXNativePty current() throws IOException {
len++;
}
String name = new String(buf, 0, len);
return new OsXNativePty(-1, null, slave, FileDescriptor.in, name);
return new OsXNativePty(-1, null, slave, FileDescriptor.in, 1, FileDescriptor.out, name);
}

public static OsXNativePty open(Attributes attr, Size size) throws IOException {
Expand All @@ -59,6 +59,10 @@ public OsXNativePty(int master, FileDescriptor masterFD, int slave, FileDescript
super(master, masterFD, slave, slaveFD, name);
}

public OsXNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
}

@Override
public Attributes getAttr() throws IOException {
termios termios = new termios();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static SolarisNativePty current() throws IOException {
len++;
}
String name = new String(buf, 0, len);
return new SolarisNativePty(-1, null, slave, FileDescriptor.in, name);
return new SolarisNativePty(-1, null, slave, FileDescriptor.in, 1, FileDescriptor.out, name);
}

public static SolarisNativePty open(Attributes attr, Size size) throws IOException {
Expand All @@ -58,6 +58,10 @@ public SolarisNativePty(int master, FileDescriptor masterFD, int slave, FileDesc
super(master, masterFD, slave, slaveFD, name);
}

public SolarisNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, int slaveOut, FileDescriptor slaveOutFD, String name) {
super(master, masterFD, slave, slaveFD, slaveOut, slaveOutFD, name);
}

@Override
public Attributes getAttr() throws IOException {
termios termios = new termios();
Expand Down

0 comments on commit e2175b7

Please sign in to comment.