3333
3434import coloredlogs
3535
36- from sandwine ._pty import pty_spawn_argv
3736from sandwine ._x11 import X11Display , X11Mode , create_x11_context , detect_and_require_nested_x11
3837
3938_logger = logging .getLogger (__name__ )
@@ -411,12 +410,24 @@ def create_bwrap_argv(config):
411410 if config .second_try :
412411 argv .add ('sh' , '-c' , '"$0" "$@" || exec "$0" "$@"' )
413412
414- # Add Wine
413+ # Add Wine and PTY
415414 if config .argv_0 is not None :
415+ # Add Wine
416+ inner_argv = []
416417 if config .with_wine :
417- argv .add ('wine' , config .argv_0 , * config .argv_1_plus )
418+ inner_argv .append ('wine' )
419+ inner_argv .append (config .argv_0 )
420+ inner_argv .extend (config .argv_1_plus )
421+
422+ # Add PTY
423+ if config .with_pty :
424+ # NOTE: This implementation is known to not support Ctrl+Z (SIGTSTP).
425+ # Implementing something with Ctrl+Z support is complex and planned for later.
426+ # The current approach is inspired by ptysolate by Jakub Wilk:
427+ # https://github.com/jwilk/ptysolate
428+ argv .add ('script' , '-e' , '-q' , '-c' , f'exec { shlex .join (inner_argv )} ' , '/dev/null' )
418429 else :
419- argv .add (config . argv_0 , * config . argv_1_plus )
430+ argv .add (* inner_argv )
420431 else :
421432 argv .add ('true' )
422433
@@ -431,13 +442,6 @@ def require_recent_bubblewrap():
431442 sys .exit (1 )
432443
433444
434- def spawn_argv (argv : list [str ], with_pty : bool ) -> int :
435- if not with_pty :
436- return subprocess .call (argv )
437-
438- return pty_spawn_argv (argv )
439-
440-
441445def main ():
442446 exit_code = 0
443447 try :
@@ -472,7 +476,7 @@ def main():
472476
473477 with x11context :
474478 try :
475- exit_code = spawn_argv (argv , with_pty = config . with_pty )
479+ exit_code = subprocess . call (argv )
476480 except FileNotFoundError :
477481 _logger .error (f'Command { argv [0 ]!r} is not available, aborting.' )
478482 exit_code = 127
0 commit comments