@@ -33,11 +33,14 @@ def __init__(self, repl):
3333
3434 self .timer = Timer (0.1 , self .update_view_loop )
3535 self .timer .start ()
36- self .write_count = 0
3736 self .stop_flag = False
3837 self .output = ''
3938 # clean-up output, it really should be a part of skip_preambula
4039 self .get_output ()
40+ self .output_prefix_stripped = True
41+ self .expected_output_prefix = ''
42+ self .expected_output_len = 0
43+
4144
4245 def get_output (self ):
4346 while not self .stop_flag :
@@ -48,11 +51,18 @@ def get_output(self):
4851 return out
4952
5053 def send_input (self , input ):
51- self ._repl .write (input + '\n ' )
54+ # TODO: we should block here until we return output for previous command, should we?
55+
5256 # for multiline statements we should send 1 extra new line
5357 # https://stackoverflow.com/questions/13229066/how-to-end-a-multi-line-command-in-powershell
5458 if '\n ' in input :
55- self ._repl .write ('\n ' )
59+ input += '\n '
60+
61+ self .expected_output_prefix = input .replace ('\n ' , '\n >> ' ) + '\n '
62+ self .expected_output_len = len (self .expected_output_prefix )
63+ self .output_prefix_stripped = False
64+
65+ self ._repl .write (input + '\n ' )
5666
5767 def skip_preambula (self ):
5868 try :
@@ -93,5 +103,12 @@ def write(self, packet):
93103 self .stop_flag = True
94104 return
95105 self .output += packet
96- self .write_count += 1
97106
107+ if not self .output_prefix_stripped and len (self .output ) >= self .expected_output_len :
108+ if self .output [:self .expected_output_len ] != self .expected_output_prefix :
109+ print ("Unexpected prefix: %r : Expected %r" % (
110+ self .output [:self .expected_output_len ], self .expected_output_prefix
111+ ))
112+ else :
113+ self .output_prefix_stripped = True
114+ self .output = self .output [self .expected_output_len :]
0 commit comments