@@ -111,19 +111,27 @@ impl Stdin {
111111 if utf8. position ( ) as usize == utf8. get_ref ( ) . len ( ) {
112112 let mut utf16 = vec ! [ 0u16 ; 0x1000 ] ;
113113 let mut num = 0 ;
114+ let mut input_control = readconsole_input_control ( CTRL_Z_MASK ) ;
114115 cvt ( unsafe {
115116 c:: ReadConsoleW ( handle,
116117 utf16. as_mut_ptr ( ) as c:: LPVOID ,
117118 utf16. len ( ) as u32 ,
118119 & mut num,
119- ptr :: null_mut ( ) )
120+ & mut input_control as c :: PCONSOLE_READCONSOLE_CONTROL )
120121 } ) ?;
121122 utf16. truncate ( num as usize ) ;
122123 // FIXME: what to do about this data that has already been read?
123- let data = match String :: from_utf16 ( & utf16) {
124+ let mut data = match String :: from_utf16 ( & utf16) {
124125 Ok ( utf8) => utf8. into_bytes ( ) ,
125126 Err ( ..) => return Err ( invalid_encoding ( ) ) ,
126127 } ;
128+ if let Output :: Console ( _) = self . handle {
129+ if let Some ( & last_byte) = data. last ( ) {
130+ if last_byte == CTRL_Z {
131+ data. pop ( ) ;
132+ }
133+ }
134+ }
127135 * utf8 = Cursor :: new ( data) ;
128136 }
129137
@@ -206,6 +214,18 @@ fn invalid_encoding() -> io::Error {
206214 io:: Error :: new ( io:: ErrorKind :: InvalidData , "text was not valid unicode" )
207215}
208216
217+ fn readconsole_input_control ( wakeup_mask : c:: ULONG ) -> c:: CONSOLE_READCONSOLE_CONTROL {
218+ c:: CONSOLE_READCONSOLE_CONTROL {
219+ nLength : :: mem:: size_of :: < c:: CONSOLE_READCONSOLE_CONTROL > ( ) as c:: ULONG ,
220+ nInitialChars : 0 ,
221+ dwCtrlWakeupMask : wakeup_mask,
222+ dwControlKeyState : 0 ,
223+ }
224+ }
225+
226+ const CTRL_Z : u8 = 0x1A ;
227+ const CTRL_Z_MASK : c:: ULONG = 0x4000000 ; //1 << 0x1A
228+
209229pub const EBADF_ERR : i32 = :: sys:: c:: ERROR_INVALID_HANDLE as i32 ;
210230// The default buffer capacity is 64k, but apparently windows
211231// doesn't like 64k reads on stdin. See #13304 for details, but the
0 commit comments