Add terminal support
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
e022cf3ad0
commit
887a149417
@ -128,6 +128,7 @@ func (c *container) LoadTask(ctx context.Context, ioAttach IOAttach) (Task, erro
|
|||||||
In: response.Task.Stdin,
|
In: response.Task.Stdin,
|
||||||
Out: response.Task.Stdout,
|
Out: response.Task.Stdout,
|
||||||
Err: response.Task.Stderr,
|
Err: response.Task.Stderr,
|
||||||
|
Terminal: response.Task.Terminal,
|
||||||
}
|
}
|
||||||
i, err := ioAttach(paths)
|
i, err := ioAttach(paths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
40
io.go
40
io.go
@ -30,13 +30,17 @@ type IOCreation func() (*IO, error)
|
|||||||
type IOAttach func(*FifoSet) (*IO, error)
|
type IOAttach func(*FifoSet) (*IO, error)
|
||||||
|
|
||||||
func NewIO(stdin io.Reader, stdout, stderr io.Writer) IOCreation {
|
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) {
|
return func() (*IO, error) {
|
||||||
paths, err := NewFifos()
|
paths, err := NewFifos()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
i := &IO{
|
i := &IO{
|
||||||
Terminal: false,
|
Terminal: terminal,
|
||||||
Stdout: paths.Out,
|
Stdout: paths.Out,
|
||||||
Stderr: paths.Err,
|
Stderr: paths.Err,
|
||||||
Stdin: paths.In,
|
Stdin: paths.In,
|
||||||
@ -46,13 +50,14 @@ func NewIO(stdin io.Reader, stdout, stderr io.Writer) IOCreation {
|
|||||||
out: stdout,
|
out: stdout,
|
||||||
err: stderr,
|
err: stderr,
|
||||||
}
|
}
|
||||||
closer, err := copyIO(paths, set, false)
|
closer, err := copyIO(paths, set, i.Terminal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
i.closer = closer
|
i.closer = closer
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithAttach(stdin io.Reader, stdout, stderr io.Writer) IOAttach {
|
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")
|
return nil, fmt.Errorf("cannot attach to existing fifos")
|
||||||
}
|
}
|
||||||
i := &IO{
|
i := &IO{
|
||||||
Terminal: false,
|
Terminal: paths.Terminal,
|
||||||
Stdout: paths.Out,
|
Stdout: paths.Out,
|
||||||
Stderr: paths.Err,
|
Stderr: paths.Err,
|
||||||
Stdin: paths.In,
|
Stdin: paths.In,
|
||||||
@ -71,7 +76,7 @@ func WithAttach(stdin io.Reader, stdout, stderr io.Writer) IOAttach {
|
|||||||
out: stdout,
|
out: stdout,
|
||||||
err: stderr,
|
err: stderr,
|
||||||
}
|
}
|
||||||
closer, err := copyIO(paths, set, false)
|
closer, err := copyIO(paths, set, i.Terminal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// Stdio returns an IO implementation to be used for a task
|
||||||
// that outputs the container's IO as the current processes Stdio
|
// that outputs the container's IO as the current processes Stdio
|
||||||
func Stdio() (*IO, error) {
|
func Stdio() (*IO, error) {
|
||||||
paths, err := NewFifos()
|
return NewIO(os.Stdin, os.Stdout, os.Stderr)()
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
// StdioTerminal will setup the IO for the task to use a terminal
|
||||||
set := &ioSet{
|
func StdioTerminal() (*IO, error) {
|
||||||
in: os.Stdin,
|
return NewIOWithTerminal(os.Stdin, os.Stdout, os.Stderr, true)()
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFifos returns a new set of fifos for the task
|
// 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 is the directory holding the task fifos
|
||||||
Dir string
|
Dir string
|
||||||
In, Out, Err string
|
In, Out, Err string
|
||||||
|
Terminal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ioSet struct {
|
type ioSet struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user