@@ -3,14 +3,13 @@ use async_stream::try_stream;
3
3
use bollard:: container:: LogOutput ;
4
4
use bollard:: errors:: Error ;
5
5
use bytes:: Bytes ;
6
- use std:: future:: pending;
7
6
use std:: io;
8
7
use std:: pin:: Pin ;
9
- use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt } ;
8
+ use tokio:: io:: { AsyncRead , AsyncWrite , AsyncWriteExt } ;
10
9
use tokio:: signal:: unix:: { signal, SignalKind } ;
11
10
use tokio:: task:: JoinHandle ;
12
11
use tokio_stream:: { empty, Stream , StreamExt } ;
13
- use tokio_util:: io:: { ReaderStream , StreamReader } ;
12
+ use tokio_util:: io:: ReaderStream ;
14
13
15
14
pub ( super ) enum IoStreamSource {
16
15
Container ( String ) ,
@@ -38,13 +37,22 @@ impl IoStream {
38
37
while let Some ( output) = self . output . next ( ) . await {
39
38
result. push_str ( & output?. to_string ( ) ) ;
40
39
}
41
- return Ok ( result) ;
40
+ Ok ( result)
42
41
}
43
42
44
43
pub fn pipe_std ( self ) -> JoinHandle < ( ) > {
45
- let stdin = stdin ( ) ;
46
- let stdout = stdout ( ) ;
47
- let stderr = stderr ( ) ;
44
+ let stdin = Box :: pin ( crate :: util:: tty_mode_guard:: TtyModeGuard :: new (
45
+ tokio:: io:: stdin ( ) ,
46
+ |mode| {
47
+ // Switch input to raw mode, but don't touch output modes (as it can also be connected
48
+ // to stdout and stderr).
49
+ let outmode = mode. output_modes ;
50
+ mode. make_raw ( ) ;
51
+ mode. output_modes = outmode;
52
+ } ,
53
+ ) ) ;
54
+ let stdout = Box :: pin ( tokio:: io:: stdout ( ) ) ;
55
+ let stderr = Box :: pin ( tokio:: io:: stderr ( ) ) ;
48
56
49
57
let resize_stream = try_stream ! {
50
58
let mut stream = signal( SignalKind :: window_change( ) ) ?;
@@ -144,45 +152,6 @@ impl IoStream {
144
152
}
145
153
}
146
154
147
- fn stdin ( ) -> Pin < Box < dyn tokio:: io:: AsyncRead + Send > > {
148
- if let Ok ( stdin) = try_stdin ( ) {
149
- stdin
150
- } else {
151
- let stream = async_stream:: stream! {
152
- yield pending:: <std:: io:: Result <bytes:: BytesMut >>( ) . await ;
153
- } ;
154
- Box :: pin ( StreamReader :: new ( stream) )
155
- }
156
- }
157
-
158
- fn try_stdin ( ) -> Result < Pin < Box < dyn AsyncRead + Send > > > {
159
- let mut stdin = crate :: util:: tty_mode_guard:: TtyModeGuard :: new ( tokio:: io:: stdin ( ) , |mode| {
160
- // Switch input to raw mode, but don't touch output modes (as it can also be connected
161
- // to stdout and stderr).
162
- let outmode = mode. output_modes ;
163
- mode. make_raw ( ) ;
164
- mode. output_modes = outmode;
165
- } ) ?;
166
- let stream = async_stream:: stream! {
167
- loop {
168
- let mut buf = bytes:: BytesMut :: with_capacity( 1024 ) ;
169
- match stdin. read_buf( & mut buf) . await {
170
- Ok ( _) => yield Ok ( buf) ,
171
- Err ( err) => yield Err ( err) ,
172
- }
173
- }
174
- } ;
175
- Ok ( Box :: pin ( StreamReader :: new ( stream) ) )
176
- }
177
-
178
- fn stdout ( ) -> Pin < Box < dyn tokio:: io:: AsyncWrite + Send > > {
179
- Box :: pin ( tokio:: io:: stdout ( ) )
180
- }
181
-
182
- fn stderr ( ) -> Pin < Box < dyn tokio:: io:: AsyncWrite + Send > > {
183
- Box :: pin ( tokio:: io:: stderr ( ) )
184
- }
185
-
186
155
async fn resize_tty (
187
156
docker : & bollard:: Docker ,
188
157
source : & IoStreamSource ,
@@ -194,14 +163,14 @@ async fn resize_tty(
194
163
height : rows,
195
164
width : cols,
196
165
} ;
197
- docker. resize_container_tty ( & id, options) . await ?;
166
+ docker. resize_container_tty ( id, options) . await ?;
198
167
}
199
168
IoStreamSource :: Exec ( id) => {
200
169
let options = bollard:: exec:: ResizeExecOptions {
201
170
height : rows,
202
171
width : cols,
203
172
} ;
204
- docker. resize_exec ( & id, options) . await ?;
173
+ docker. resize_exec ( id, options) . await ?;
205
174
}
206
175
} ;
207
176
Ok ( ( ) )
0 commit comments