@@ -987,8 +987,47 @@ def read_pty_output(self):
987987 print (f"[PTY-DEBUG] ✓ Timeout monitor will now exit (REPL mode active)" )
988988 self .response_to_client (5000 , {"mode" : "repl" })
989989
990- # For PTY mode with native input(), we don't need INPUT_REQUEST markers
991- # The prompts appear naturally in the output stream
990+ # Check for matplotlib figures
991+ if "__MATPLOTLIB_FIGURE_START__" in buffer and "__MATPLOTLIB_FIGURE_END__" in buffer :
992+ start = buffer .index ("__MATPLOTLIB_FIGURE_START__" ) + len ("__MATPLOTLIB_FIGURE_START__" )
993+ end = buffer .index ("__MATPLOTLIB_FIGURE_END__" )
994+ figure_data = buffer [start :end ].strip ()
995+
996+ # Send figure to client
997+ self .response_to_client (3000 , {"figure" : figure_data })
998+
999+ # Clear the marker from buffer
1000+ buffer = buffer [end + len ("__MATPLOTLIB_FIGURE_END__" ):]
1001+
1002+ # CRITICAL: Check for INPUT_REQUEST markers from custom input() during script execution
1003+ if "__INPUT_REQUEST_START__" in buffer and "__INPUT_REQUEST_END__" in buffer :
1004+ # Extract the positions
1005+ marker_start = buffer .index ("__INPUT_REQUEST_START__" )
1006+ marker_end = buffer .index ("__INPUT_REQUEST_END__" ) + len ("__INPUT_REQUEST_END__" )
1007+
1008+ # Extract prompt from markers
1009+ prompt_start = marker_start + len ("__INPUT_REQUEST_START__" )
1010+ prompt_end = buffer .index ("__INPUT_REQUEST_END__" )
1011+ prompt = buffer [prompt_start :prompt_end ]
1012+
1013+ # Send any text before the marker
1014+ pre_marker = buffer [:marker_start ]
1015+ if pre_marker and pre_marker .strip ():
1016+ for line in pre_marker .split ("\n " ):
1017+ if line or line == "" :
1018+ self .response_to_client (0 , {"stdout" : line })
1019+
1020+ print (f"[PTY-DEBUG] Input request detected: { repr (prompt )} " )
1021+
1022+ # Pause timeout when waiting for user input
1023+ self .waiting_for_input = True
1024+
1025+ # Send input request signal to enable input field (with prompt for frontend)
1026+ # The frontend will display the prompt, so we don't need to send it separately
1027+ self .response_to_client (2000 , {"prompt" : prompt })
1028+
1029+ # Clear the processed part from buffer
1030+ buffer = buffer [marker_end :].lstrip ('\n ' )
9921031
9931032 # Send complete lines to client
9941033 while '\n ' in buffer or '\r ' in buffer :
0 commit comments