added windows compilation support for PTY

This commit is contained in:
sqshq 2019-07-01 23:17:21 -04:00
parent 9267fbc857
commit bc51750141
5 changed files with 45 additions and 12 deletions

14
data/int.go Normal file
View File

@ -0,0 +1,14 @@
package data
import "time"
const (
startupTimeout = 200 * time.Millisecond
minAwaitTimeout = 100 * time.Millisecond
maxAwaitTimeout = 1 * time.Second
)
type InteractiveShell interface {
init() error
execute() (string, error)
}

View File

@ -25,7 +25,11 @@ func (s *BasicInteractiveShell) init() error {
cmd := exec.Command("sh", "-c", s.item.initScripts[0])
enrichEnvVariables(cmd, s.variables)
cmd.Wait()
err := cmd.Wait()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
@ -78,6 +82,10 @@ func (s *BasicInteractiveShell) init() error {
func (s *BasicInteractiveShell) execute() (string, error) {
if s.stdin == nil {
return "", nil
}
_, err := io.WriteString(s.stdin, fmt.Sprintf(" %s\n", s.item.sampleScript))
if err != nil {
s.errCount++

View File

@ -12,15 +12,6 @@ import (
"time"
)
const (
startupTimeout = 200 * time.Millisecond
minAwaitTimeout = 100 * time.Millisecond
maxAwaitTimeout = 1 * time.Second
)
/**
* Experimental
*/
type PtyInteractiveShell struct {
item *Item
variables []string

20
data/int_pty_windows.go Normal file
View File

@ -0,0 +1,20 @@
package data
import (
"errors"
"time"
)
type PtyInteractiveShell struct {
item *Item
variables []string
timeout time.Duration
}
func (s *PtyInteractiveShell) init() error {
return errors.New("PTY mode is not supported on Windows")
}
func (s *PtyInteractiveShell) execute() (string, error) {
return "", errors.New("PTY mode is not supported on Windows")
}

View File

@ -18,8 +18,8 @@ type Item struct {
color *ui.Color
rateMs int
pty bool
basicShell *BasicInteractiveShell
ptyShell *PtyInteractiveShell
basicShell InteractiveShell
ptyShell InteractiveShell
}
func NewItems(cfgs []config.Item, rateMs int) []*Item {