@@ -27,6 +27,7 @@ import (
2727 "github.com/docker/compose-cli/utils"
2828
2929 "github.com/compose-spec/compose-go/types"
30+ "github.com/docker/cli/cli/streams"
3031 moby "github.com/docker/docker/api/types"
3132 "github.com/docker/docker/pkg/stdcopy"
3233)
@@ -108,26 +109,40 @@ func (s *composeService) attachContainer(ctx context.Context, container moby.Con
108109 Service : container .Labels [serviceLabel ],
109110 })
110111
111- return s .attachContainerStreams (ctx , container .ID , service .Tty , nil , w )
112+ _ , err = s .attachContainerStreams (ctx , container .ID , service .Tty , nil , w )
113+ return err
112114}
113115
114- func (s * composeService ) attachContainerStreams (ctx context.Context , container string , tty bool , r io.Reader , w io.Writer ) error {
116+ func (s * composeService ) attachContainerStreams (ctx context.Context , container string , tty bool , r io.ReadCloser , w io.Writer ) (func (), error ) {
117+ var (
118+ in * streams.In
119+ restore = func () { /* noop */ }
120+ )
121+ if r != nil {
122+ in = streams .NewIn (r )
123+ restore = in .RestoreTerminal
124+ }
125+
115126 stdin , stdout , err := s .getContainerStreams (ctx , container )
116127 if err != nil {
117- return err
128+ return restore , err
118129 }
119130
120131 go func () {
121132 <- ctx .Done ()
122- stdout .Close () //nolint:errcheck
123- if stdin != nil {
124- stdin .Close () //nolint:errcheck
133+ if in != nil {
134+ in .Close () //nolint:errcheck
125135 }
136+ stdout .Close () //nolint:errcheck
126137 }()
127138
128- if r != nil && stdin != nil {
139+ if in != nil && stdin != nil {
140+ err := in .SetRawTerminal ()
141+ if err != nil {
142+ return restore , err
143+ }
129144 go func () {
130- io .Copy (stdin , r ) //nolint:errcheck
145+ io .Copy (stdin , in ) //nolint:errcheck
131146 }()
132147 }
133148
@@ -140,7 +155,7 @@ func (s *composeService) attachContainerStreams(ctx context.Context, container s
140155 }
141156 }()
142157 }
143- return nil
158+ return restore , nil
144159}
145160
146161func (s * composeService ) getContainerStreams (ctx context.Context , container string ) (io.WriteCloser , io.ReadCloser , error ) {
0 commit comments