@@ -168,7 +168,7 @@ def process_user_input(cw: CursesWriter, autos: Autos) -> str | None:
168168 cw .input_buffer += char
169169
170170
171- def parallel_ui (stdscr : curses .window , tempdir : str ):
171+ def parallel_ui (stdscr : curses .window , tempdir : str ) -> tuple [ str , str | None ] :
172172 cw = CursesWriter (stdscr = stdscr )
173173
174174 # Wait until the status file exists
@@ -194,24 +194,23 @@ def parallel_ui(stdscr: curses.window, tempdir: str):
194194 cw .stdscr .nodelay (False )
195195 while cw .stdscr .getch () not in [ord ('q' ), ord ('Q' )]:
196196 sleep (0.1 )
197- return 'quit'
197+ return 'quit' , None
198198
199199 # 4. Process user input
200200 screen_to_switch = process_user_input (cw = cw , autos = autos )
201201 if screen_to_switch :
202- # Important: End curses before an external program takes control of the terminal
203- curses .endwin ()
204- print (f"Switching to screen '{ screen_to_switch } '... (Return with <ctrl>+a d)" )
205- subprocess .run (['screen' , '-r' , screen_to_switch ])
206- return 'restart'
202+ return 'restart' , screen_to_switch
207203
208204 sleep (0.2 ) # Short pause to reduce CPU load
209205
210206
211207def screen_switch_loop (tempdir : str ):
212208 while True :
213209 try :
214- exit_reason = curses .wrapper (parallel_ui , tempdir )
210+ exit_reason , screen_to_switch = curses .wrapper (parallel_ui , tempdir )
211+ if screen_to_switch :
212+ print (f"Switching to screen '{ screen_to_switch } '... (Return with <ctrl>+a d)" )
213+ subprocess .run (['screen' , '-r' , screen_to_switch ])
215214 except curses .error as exc :
216215 LOG .error (f"Curses error: { exc } " )
217216 LOG .error ("Could not start the curses interface. Is the terminal compatible?" )
0 commit comments