Skip to content

Commit 29eced7

Browse files
fix stdin.readline and rewind interaction
--HG-- branch : scroll-frontend extra : amend_source : ed791f80bd9a337dc571730b0ae3a38a7c389ba8
1 parent cbe01ab commit 29eced7

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

bpython/scrollfrontend/repl.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,33 +200,34 @@ def clean_up_current_line_for_exit(self):
200200
def process_event(self, e):
201201
"""Returns True if shutting down, otherwise mutates state of Repl object"""
202202

203+
if not isinstance(e, events.Event):
204+
self.last_events.append(e)
205+
self.last_events.pop(0)
206+
207+
result = None
203208
logging.debug("processing event %r", e)
204209
if isinstance(e, events.RefreshRequestEvent):
205210
assert self.refresh_requests > 0
206211
self.refresh_requests -= 1
207212
assert self.coderunner.code_is_waiting or self.reevaluating
208213
if self.coderunner.code_is_waiting:
209214
self.run_code_and_maybe_finish()
210-
if self.refresh_requests == 0 and self.reevaluating:
215+
if self.refresh_requests == 0 and self.reevaluating and not self.stdin.has_focus:
211216
self.reevaluate()
212-
return
213-
self.last_events.append(e)
214-
self.last_events.pop(0)
215-
if isinstance(e, events.SigIntEvent):
217+
elif isinstance(e, events.SigIntEvent):
216218
logging.debug('received sigint event')
217219
self.keyboard_interrupt()
218220
self.update_completion()
219221
return
220-
if isinstance(e, events.WindowChangeEvent):
222+
elif isinstance(e, events.WindowChangeEvent):
221223
logging.debug('window change to %d %d', e.width, e.height)
222224
self.width, self.height = e.width, e.height
223-
return
224-
if self.status_bar.has_focus:
225-
return self.status_bar.process_event(e)
226-
if self.stdin.has_focus:
227-
return self.stdin.process_event(e)
225+
elif self.status_bar.has_focus:
226+
result = self.status_bar.process_event(e)
227+
elif self.stdin.has_focus:
228+
result = self.stdin.process_event(e)
228229

229-
if e in self.rl_char_sequences:
230+
elif e in self.rl_char_sequences:
230231
self.cursor_offset_in_line, self._current_line = self.rl_char_sequences[e](self.cursor_offset_in_line, self._current_line)
231232
self.update_completion()
232233

@@ -296,6 +297,11 @@ def process_event(self, e):
296297
self.add_normal_character(e if len(e) == 1 else e[-1]) #strip control seq
297298
self.update_completion()
298299

300+
if self.reevaluating and self.refresh_requests == 0 and not self.stdin.has_focus:
301+
self.stuff_a_refresh_request()
302+
303+
return result
304+
299305
def on_enter(self, insert_into_history=True):
300306
self.cursor_offset_in_line = -1 # so the cursor isn't touching a paren
301307
self.unhighlight_paren() # in unhighlight_paren
@@ -752,7 +758,7 @@ def reprint_line(self, lineno, tokens):
752758
self.display_buffer[lineno] = bpythonparse(format(tokens, self.formatter))
753759
def reevaluate(self, insert_into_history=False):
754760
"""bpython.Repl.undo calls this"""
755-
#TODO This almost works, but events are necessary to keep it going!
761+
#TODO This almost works, but stdin.readline() doesn't work yet
756762
if not self.reevaluating:
757763
self.reevaluating = self.reevaluation_generator(insert_into_history=insert_into_history)
758764
try:
@@ -779,11 +785,7 @@ def reevaluation_generator(self, insert_into_history):
779785
for line in old_logical_lines:
780786
self._current_line = line
781787
self.on_enter(insert_into_history=insert_into_history)
782-
if self.refresh_requests > 0:
783-
yield line # use up remaining refresh requests
784-
else:
785-
self.stuff_a_refresh_request()
786-
yield line
788+
yield line
787789
self.cursor_offset_in_line = 0
788790
self._current_line = ''
789791

0 commit comments

Comments
 (0)