Files
docker-cli/components/engine/cli/command/stream.go
Ignacio Capurro 0b4ffdab67 Unit tests for cli/commands/image (except build and tag)
Signed-off-by: Ignacio Capurro <icapurrofagian@gmail.com>
Upstream-commit: b2551c619d30f163c3ab8c9ee53cdb09bfbeaa55
Component: engine
2017-04-23 12:27:39 -05:00

45 lines
1018 B
Go

package command
import (
"github.com/docker/docker/pkg/term"
"os"
)
// CommonStream is an input stream used by the DockerCli to read user input
type CommonStream struct {
fd uintptr
isTerminal bool
state *term.State
}
// FD returns the file descriptor number for this stream
func (s *CommonStream) FD() uintptr {
return s.fd
}
// IsTerminal returns true if this stream is connected to a terminal
func (s *CommonStream) IsTerminal() bool {
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
func (s *CommonStream) RestoreTerminal() {
if s.state != nil {
term.RestoreTerminal(s.fd, s.state)
}
}
// SetIsTerminal sets the boolean used for isTerminal
func (s *CommonStream) SetIsTerminal(isTerminal bool) {
s.isTerminal = isTerminal
}