diff --git a/container.go b/container.go index 71c408228..7a587b647 100644 --- a/container.go +++ b/container.go @@ -125,9 +125,10 @@ func (c *container) LoadTask(ctx context.Context, ioAttach IOAttach) (Task, erro response.Task.Stdout, response.Task.Stderr, }), - In: response.Task.Stdin, - Out: response.Task.Stdout, - Err: response.Task.Stderr, + In: response.Task.Stdin, + Out: response.Task.Stdout, + Err: response.Task.Stderr, + Terminal: response.Task.Terminal, } i, err := ioAttach(paths) if err != nil { diff --git a/io.go b/io.go index a1b22e3b6..e3c56d909 100644 --- a/io.go +++ b/io.go @@ -30,13 +30,17 @@ type IOCreation func() (*IO, error) type IOAttach func(*FifoSet) (*IO, error) func NewIO(stdin io.Reader, stdout, stderr io.Writer) IOCreation { + return NewIOWithTerminal(stdin, stdout, stderr, false) +} + +func NewIOWithTerminal(stdin io.Reader, stdout, stderr io.Writer, terminal bool) IOCreation { return func() (*IO, error) { paths, err := NewFifos() if err != nil { return nil, err } i := &IO{ - Terminal: false, + Terminal: terminal, Stdout: paths.Out, Stderr: paths.Err, Stdin: paths.In, @@ -46,13 +50,14 @@ func NewIO(stdin io.Reader, stdout, stderr io.Writer) IOCreation { out: stdout, err: stderr, } - closer, err := copyIO(paths, set, false) + closer, err := copyIO(paths, set, i.Terminal) if err != nil { return nil, err } i.closer = closer return i, nil } + } func WithAttach(stdin io.Reader, stdout, stderr io.Writer) IOAttach { @@ -61,7 +66,7 @@ func WithAttach(stdin io.Reader, stdout, stderr io.Writer) IOAttach { return nil, fmt.Errorf("cannot attach to existing fifos") } i := &IO{ - Terminal: false, + Terminal: paths.Terminal, Stdout: paths.Out, Stderr: paths.Err, Stdin: paths.In, @@ -71,7 +76,7 @@ func WithAttach(stdin io.Reader, stdout, stderr io.Writer) IOAttach { out: stdout, err: stderr, } - closer, err := copyIO(paths, set, false) + closer, err := copyIO(paths, set, i.Terminal) if err != nil { return nil, err } @@ -83,26 +88,12 @@ func WithAttach(stdin io.Reader, stdout, stderr io.Writer) IOAttach { // Stdio returns an IO implementation to be used for a task // that outputs the container's IO as the current processes Stdio func Stdio() (*IO, error) { - paths, err := NewFifos() - if err != nil { - return nil, err - } - set := &ioSet{ - in: os.Stdin, - out: os.Stdout, - err: os.Stderr, - } - closer, err := copyIO(paths, set, false) - if err != nil { - return nil, err - } - return &IO{ - Terminal: false, - Stdin: paths.In, - Stdout: paths.Out, - Stderr: paths.Err, - closer: closer, - }, nil + return NewIO(os.Stdin, os.Stdout, os.Stderr)() +} + +// StdioTerminal will setup the IO for the task to use a terminal +func StdioTerminal() (*IO, error) { + return NewIOWithTerminal(os.Stdin, os.Stdout, os.Stderr, true)() } // NewFifos returns a new set of fifos for the task @@ -127,6 +118,7 @@ type FifoSet struct { // Dir is the directory holding the task fifos Dir string In, Out, Err string + Terminal bool } type ioSet struct {