@@ -195,7 +195,7 @@ function restoreLocalTerminal(ttyState?: string | null, ttyPath?: string | null,
195195 try {
196196 if ( ttyPath ) {
197197 withTtyFd (
198- 'r' ,
198+ 'r+ ' ,
199199 ( fd ) => {
200200 spawnSync ( resetBinary , [ ] , { stdio : [ fd , fd , 'ignore' ] } ) ;
201201 } ,
@@ -204,7 +204,7 @@ function restoreLocalTerminal(ttyState?: string | null, ttyPath?: string | null,
204204 } else if ( process . stdin . isTTY ) {
205205 spawnSync ( resetBinary , [ ] , { stdio : [ 0 , 'ignore' , 'ignore' ] } ) ;
206206 } else {
207- withTtyFd ( 'r' , ( fd ) => {
207+ withTtyFd ( 'r+ ' , ( fd ) => {
208208 spawnSync ( resetBinary , [ ] , { stdio : [ fd , 'ignore' , 'ignore' ] } ) ;
209209 } , ttyPath ) ;
210210 }
@@ -219,9 +219,11 @@ function restoreLocalTerminal(ttyState?: string | null, ttyPath?: string | null,
219219 */
220220function captureTtyContext ( ) : TtyContext {
221221 const ttyPath = resolveTtyPath ( ) ;
222- // Normalize to a sane baseline first so we restore to a known-good state.
223- restoreLocalTerminal ( undefined , ttyPath ) ;
224222 const ttyState = captureTtyState ( ttyPath ) ;
223+ if ( ! ttyState ) {
224+ // Best effort fallback to recover a broken terminal when state capture fails.
225+ restoreLocalTerminal ( undefined , ttyPath ) ;
226+ }
225227 return { ttyPath , ttyState } ;
226228}
227229
0 commit comments