2019-01-28 08:30:31 -05:00
|
|
|
package streams
|
2017-03-30 20:21:14 -04:00
|
|
|
|
|
|
|
import (
|
2020-04-16 05:23:37 -04:00
|
|
|
"github.com/moby/term"
|
2017-03-30 20:21:14 -04:00
|
|
|
)
|
|
|
|
|
2019-01-28 08:30:31 -05:00
|
|
|
// commonStream is an input stream used by the DockerCli to read user input
|
|
|
|
type commonStream struct {
|
2017-03-30 20:21:14 -04:00
|
|
|
fd uintptr
|
|
|
|
isTerminal bool
|
|
|
|
state *term.State
|
|
|
|
}
|
|
|
|
|
|
|
|
// FD returns the file descriptor number for this stream
|
2019-01-28 08:30:31 -05:00
|
|
|
func (s *commonStream) FD() uintptr {
|
2017-03-30 20:21:14 -04:00
|
|
|
return s.fd
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsTerminal returns true if this stream is connected to a terminal
|
2019-01-28 08:30:31 -05:00
|
|
|
func (s *commonStream) IsTerminal() bool {
|
2017-03-30 20:21:14 -04:00
|
|
|
return s.isTerminal
|
|
|
|
}
|
|
|
|
|
|
|
|
// RestoreTerminal restores normal mode to the terminal
|
2019-01-28 08:30:31 -05:00
|
|
|
func (s *commonStream) RestoreTerminal() {
|
2017-03-30 20:21:14 -04:00
|
|
|
if s.state != nil {
|
|
|
|
term.RestoreTerminal(s.fd, s.state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetIsTerminal sets the boolean used for isTerminal
|
2019-01-28 08:30:31 -05:00
|
|
|
func (s *commonStream) SetIsTerminal(isTerminal bool) {
|
2017-03-30 20:21:14 -04:00
|
|
|
s.isTerminal = isTerminal
|
|
|
|
}
|