@@ -9,38 +9,42 @@ import (
99 "github.com/moby/term"
1010)
1111
12- // In is an input stream used by the DockerCli to read user input
12+ // In is an input stream to read user input. It implements [io.ReadCloser]
13+ // with additional utilities, such as putting the terminal in raw mode.
1314type In struct {
1415 commonStream
1516 in io.ReadCloser
1617}
1718
19+ // Read implements the [io.Reader] interface.
1820func (i * In ) Read (p []byte ) (int , error ) {
1921 return i .in .Read (p )
2022}
2123
22- // Close implements the Closer interface
24+ // Close implements the [io. Closer] interface.
2325func (i * In ) Close () error {
2426 return i .in .Close ()
2527}
2628
27- // SetRawTerminal sets raw mode on the input terminal
29+ // SetRawTerminal sets raw mode on the input terminal. It is a no-op if In
30+ // is not a TTY, or if the "NORAW" environment variable is set to a non-empty
31+ // value.
2832func (i * In ) SetRawTerminal () (err error ) {
29- if os .Getenv ("NORAW" ) != "" || ! i . commonStream . isTerminal {
33+ if ! i . isTerminal || os .Getenv ("NORAW" ) != "" {
3034 return nil
3135 }
32- i .commonStream . state , err = term .SetRawTerminal (i . commonStream .fd )
36+ i .state , err = term .SetRawTerminal (i .fd )
3337 return err
3438}
3539
36- // CheckTty checks if we are trying to attach to a container tty
37- // from a non-tty client input stream, and if so, returns an error.
40+ // CheckTty checks if we are trying to attach to a container TTY
41+ // from a non-TTY client input stream, and if so, returns an error.
3842func (i * In ) CheckTty (attachStdin , ttyMode bool ) error {
3943 // In order to attach to a container tty, input stream for the client must
4044 // be a tty itself: redirecting or piping the client standard input is
4145 // incompatible with `docker run -t`, `docker exec -t` or `docker attach`.
4246 if ttyMode && attachStdin && ! i .isTerminal {
43- eText : = "the input device is not a TTY"
47+ const eText = "the input device is not a TTY"
4448 if runtime .GOOS == "windows" {
4549 return errors .New (eText + ". If you are using mintty, try prefixing the command with 'winpty'" )
4650 }
@@ -49,8 +53,9 @@ func (i *In) CheckTty(attachStdin, ttyMode bool) error {
4953 return nil
5054}
5155
52- // NewIn returns a new In object from a ReadCloser
56+ // NewIn returns a new [In] from an [io. ReadCloser].
5357func NewIn (in io.ReadCloser ) * In {
54- fd , isTerminal := term .GetFdInfo (in )
55- return & In {commonStream : commonStream {fd : fd , isTerminal : isTerminal }, in : in }
58+ i := & In {in : in }
59+ i .fd , i .isTerminal = term .GetFdInfo (in )
60+ return i
5661}
0 commit comments