@@ -179,8 +179,7 @@ public function end($data = null)
179179 $ this ->ending = true ;
180180
181181 // clear readline output, close input and end output
182- $ this ->readline ->setInput ('' )->setPrompt ('' )->clear ();
183- $ this ->restoreTtyMode ();
182+ $ this ->readline ->setInput ('' )->setPrompt ('' );
184183 $ this ->input ->close ();
185184 $ this ->output ->end ();
186185 }
@@ -195,8 +194,7 @@ public function close()
195194 $ this ->closed = true ;
196195
197196 // clear readline output and then close
198- $ this ->readline ->setInput ('' )->setPrompt ('' )->clear ()->close ();
199- $ this ->restoreTtyMode ();
197+ $ this ->readline ->setInput ('' )->setPrompt ('' );
200198 $ this ->input ->close ();
201199 $ this ->output ->close ();
202200 }
@@ -227,6 +225,8 @@ public function handleEnd()
227225 /** @internal */
228226 public function handleCloseInput ()
229227 {
228+ $ this ->restoreTtyMode ();
229+
230230 if (!$ this ->output ->isWritable ()) {
231231 $ this ->close ();
232232 }
@@ -249,9 +249,9 @@ private function restoreTtyMode()
249249 // remove dummy readline handler to turn to default input mode
250250 $ this ->usesExtReadlineHandler = false ;
251251 readline_callback_handler_remove ();
252- } elseif ($ this ->originalTtyMode !== null && $ this ->isTty ()) {
252+ } elseif ($ this ->originalTtyMode !== null && is_resource ( STDIN ) && $ this ->isTty ()) {
253253 // Reset stty so it behaves normally again
254- shell_exec (sprintf ( 'stty %s ' , $ this ->originalTtyMode ));
254+ shell_exec ('stty ' . escapeshellarg ( $ this ->originalTtyMode ));
255255 $ this ->originalTtyMode = null ;
256256 }
257257
@@ -344,15 +344,10 @@ private function isTty()
344344 // For what it's worth, checking for device gid 5 (tty) is less reliable.
345345 // @link http://man7.org/linux/man-pages/man7/inode.7.html
346346 // @link https://www.kernel.org/doc/html/v4.11/admin-guide/devices.html#terminal-devices
347- if (is_resource (STDIN )) {
348- $ stat = fstat (STDIN );
349- $ mode = isset ($ stat ['mode ' ]) ? ($ stat ['mode ' ] & 0170000 ) : 0 ;
350- $ major = isset ($ stat ['dev ' ]) ? (($ stat ['dev ' ] >> 8 ) & 0xff ) : 0 ;
347+ $ stat = fstat (STDIN );
348+ $ mode = isset ($ stat ['mode ' ]) ? ($ stat ['mode ' ] & 0170000 ) : 0 ;
349+ $ major = isset ($ stat ['dev ' ]) ? (($ stat ['dev ' ] >> 8 ) & 0xff ) : 0 ;
351350
352- if ($ mode === 0020000 && $ major >= 2 && $ major <= 143 && ($ major <=5 || $ major >= 128 )) {
353- return true ;
354- }
355- }
356- return false ;
351+ return ($ mode === 0020000 && $ major >= 2 && $ major <= 143 && ($ major <=5 || $ major >= 128 ));
357352 }
358353}
0 commit comments