Fix docker run -it on windows

Signed-off-by: Vincent Demeester <vincent@demeester.fr>
This commit is contained in:
Vincent Demeester 2017-04-25 18:25:05 +02:00
parent e1101b1295
commit 8c014db302
3 changed files with 24 additions and 12 deletions

View file

@ -2,9 +2,11 @@ package command
import ( import (
"errors" "errors"
"github.com/docker/docker/pkg/term"
"io" "io"
"os"
"runtime" "runtime"
"github.com/docker/docker/pkg/term"
) )
// InStream is an input stream used by the DockerCli to read user input // InStream is an input stream used by the DockerCli to read user input
@ -22,6 +24,15 @@ func (i *InStream) Close() error {
return i.in.Close() return i.in.Close()
} }
// SetRawTerminal sets raw mode on the input terminal
func (i *InStream) SetRawTerminal() (err error) {
if os.Getenv("NORAW") != "" || !i.CommonStream.isTerminal {
return nil
}
i.CommonStream.state, err = term.SetRawTerminal(i.CommonStream.fd)
return err
}
// CheckTty checks if we are trying to attach to a container tty // CheckTty checks if we are trying to attach to a container tty
// from a non-tty client input stream, and if so, returns an error. // from a non-tty client input stream, and if so, returns an error.
func (i *InStream) CheckTty(attachStdin, ttyMode bool) error { func (i *InStream) CheckTty(attachStdin, ttyMode bool) error {

View file

@ -1,9 +1,11 @@
package command package command
import ( import (
"io"
"os"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/term" "github.com/docker/docker/pkg/term"
"io"
) )
// OutStream is an output stream used by the DockerCli to write normal program // OutStream is an output stream used by the DockerCli to write normal program
@ -17,6 +19,15 @@ func (o *OutStream) Write(p []byte) (int, error) {
return o.out.Write(p) return o.out.Write(p)
} }
// SetRawTerminal sets raw mode on the input terminal
func (o *OutStream) SetRawTerminal() (err error) {
if os.Getenv("NORAW") != "" || !o.CommonStream.isTerminal {
return nil
}
o.CommonStream.state, err = term.SetRawTerminalOutput(o.CommonStream.fd)
return err
}
// GetTtySize returns the height and width in characters of the tty // GetTtySize returns the height and width in characters of the tty
func (o *OutStream) GetTtySize() (uint, uint) { func (o *OutStream) GetTtySize() (uint, uint) {
if !o.isTerminal { if !o.isTerminal {

View file

@ -2,7 +2,6 @@ package command
import ( import (
"github.com/docker/docker/pkg/term" "github.com/docker/docker/pkg/term"
"os"
) )
// CommonStream is an input stream used by the DockerCli to read user input // CommonStream is an input stream used by the DockerCli to read user input
@ -22,15 +21,6 @@ func (s *CommonStream) IsTerminal() bool {
return s.isTerminal return s.isTerminal
} }
// SetRawTerminal sets raw mode on the input terminal
func (s *CommonStream) SetRawTerminal() (err error) {
if os.Getenv("NORAW") != "" || !s.isTerminal {
return nil
}
s.state, err = term.SetRawTerminal(s.fd)
return err
}
// RestoreTerminal restores normal mode to the terminal // RestoreTerminal restores normal mode to the terminal
func (s *CommonStream) RestoreTerminal() { func (s *CommonStream) RestoreTerminal() {
if s.state != nil { if s.state != nil {