Skip to content

Commit 9c33a91

Browse files
committed
Removed pty spawn to compile for windows. Broke the tty hack to another file to compile for windows
1 parent 57870d3 commit 9c33a91

File tree

5 files changed

+52
-27
lines changed

5 files changed

+52
-27
lines changed

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,3 @@
1717
[[constraint]]
1818
branch = "master"
1919
name = "github.com/amoghe/distillog"
20-
21-
[[constraint]]
22-
name = "github.com/kr/pty"
23-
version = "1.1.4"

inout/exec.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
package inout
22

33
import (
4-
"os"
4+
"io"
55
"os/exec"
66
"errors"
77
"strings"
8-
9-
"github.com/kr/pty"
108
)
119

12-
func NewExecArgs(args []string) (*os.File, error) {
10+
type RWC struct {
11+
io.Reader
12+
io.Writer
13+
io.Closer
14+
}
15+
16+
func NewReadWriteCloser(r io.Reader, w io.Writer, c io.Closer) io.ReadWriteCloser {
17+
return RWC{r, w, c}
18+
}
19+
20+
func NewExecArgs(args []string) (*RWC, error) {
1321
var c *exec.Cmd
1422

1523
if len(args) > 1 {
@@ -20,9 +28,14 @@ func NewExecArgs(args []string) (*os.File, error) {
2028
return nil, errors.New("No command given")
2129
}
2230

23-
return pty.Start(c)
31+
// TODO: Run it in a TTY
32+
// TODO: Combine Stderr
33+
si, _ := c.StdinPipe()
34+
so, _ := c.StdoutPipe()
35+
36+
return &RWC{so, si, nil}, c.Start()
2437
}
2538

26-
func NewExec(cmd string) (*os.File, error) {
39+
func NewExec(cmd string) (*RWC, error) {
2740
return NewExecArgs(strings.Split(cmd, " "))
2841
}

inout/tty.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package inout
22

33
import (
4-
"golang.org/x/sys/unix"
54
"github.com/mattn/go-tty"
65
)
76

@@ -18,22 +17,6 @@ func NewTty() (*Tty, error) {
1817
return tty, err
1918
}
2019

21-
func (this *Tty) EnableRawTty() {
22-
if this.reset == nil {
23-
Log.Warningln("[!] Entering RAW mode (Ctrl-c will go to remote) - press Alt-r to go back to normal")
24-
this.reset, _ = this.Raw()
25-
26-
// Very targeted fix for broken raw tty for non-tty output
27-
// Numbers are taken from github.com/mattn/go-tty/tty_linux.go
28-
29-
// ioctlReadTermios
30-
termios, _ := unix.IoctlGetTermios(int(this.Input().Fd()), 0x5401)
31-
termios.Oflag |= unix.OPOST
32-
// ioctlWriteTermios
33-
unix.IoctlSetTermios(int(this.Input().Fd()), 0x5402, termios)
34-
}
35-
}
36-
3720
func (this *Tty) DisableRawTty() {
3821
if this.reset != nil {
3922
Log.Infoln("[i] Exiting RAW mode (Ctrl-c will kill the program)")

inout/tty_unix.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// +build !windows
2+
3+
4+
package inout
5+
6+
import "golang.org/x/sys/unix"
7+
8+
func (this *Tty) EnableRawTty() {
9+
if this.reset == nil {
10+
Log.Warningln("[!] Entering RAW mode (Ctrl-c will go to remote) - press Alt-r to go back to normal")
11+
this.reset, _ = this.Raw()
12+
13+
// Very targeted fix for broken raw tty for non-tty output
14+
// Numbers are taken from github.com/mattn/go-tty/tty_linux.go
15+
16+
// ioctlReadTermios
17+
termios, _ := unix.IoctlGetTermios(int(this.Input().Fd()), 0x5401)
18+
termios.Oflag |= unix.OPOST
19+
// ioctlWriteTermios
20+
unix.IoctlSetTermios(int(this.Input().Fd()), 0x5402, termios)
21+
}
22+
}

inout/tty_windows.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// +build windows
2+
3+
4+
package inout
5+
6+
func (this *Tty) EnableRawTty() {
7+
if this.reset == nil {
8+
Log.Warningln("[!] Entering RAW mode (Ctrl-c will go to remote) - press Alt-r to go back to normal")
9+
this.reset, _ = this.Raw()
10+
}
11+
}

0 commit comments

Comments
 (0)