Skip to content

Commit a34dc60

Browse files
small refactorings
--HG-- branch : scroll-frontend
1 parent 7f1493f commit a34dc60

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

bpython/scrollfrontend/repl.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#TODO proper raw_input (currently input isn't visible while typing, includes \r, and comes in as unicode in Python 2
4747
#TODO use events instead of length-one queues for interthread communication
4848

49+
#TODO raw_input should be bytes in python2
50+
#TODO ctlr-c handling at all times
51+
#TODO nicer passing of control between threads
52+
4953
from bpython.keys import cli_key_dispatch as key_dispatch
5054

5155
class FakeStdin(object):
@@ -104,7 +108,7 @@ class Repl(BpythonRepl):
104108
"""
105109

106110
## initialization, cleanup
107-
def __init__(self, locals_=None, config=None, stuff_a_refresh_request=None):
111+
def __init__(self, locals_=None, config=None, stuff_a_refresh_request=lambda: None):
108112
logging.debug("starting init")
109113
interp = code.InteractiveInterpreter(locals=locals_)
110114

@@ -407,18 +411,18 @@ def push(self, line, insert_into_history=True):
407411
elif line and ':' not in line and line.strip().startswith(('return', 'pass', 'raise', 'yield')):
408412
indent = max(0, indent - self.config.tab_length)
409413
logging.debug('running %r in interpreter', self.buffer)
410-
self.coderunner.load_code('\n'.join(self.buffer))
414+
code_to_run = '\n'.join(self.buffer)
411415
self.saved_indent = indent
412416
self.saved_line = line
413417

414-
#current line not added to display buffer if quitting
418+
#current line not added to display buffer if quitting #TODO I don't understand this comment
415419
if self.config.syntax:
416420
self.display_buffer.append(bpythonparse(format(self.tokenize(line), self.formatter)))
417421
else:
418422
self.display_buffer.append(fmtstr(line))
419423

420424
try:
421-
c = code.compile_command('\n'.join(self.buffer))
425+
c = bool(code.compile_command('\n'.join(self.buffer)))
422426
except (ValueError, SyntaxError, ValueError):
423427
c = error = True
424428
if c:
@@ -428,24 +432,21 @@ def push(self, line, insert_into_history=True):
428432
self.buffer = []
429433
self.cursor_offset_in_line = 0
430434

435+
self.coderunner.load_code(code_to_run)
431436
self.finish_command_if_done()
432437

433438
def finish_command_if_done(self):
434439
r = self.coderunner.run_code()
435440
if r:
436441
unfinished = r == 'unfinished'
437442
err = True #TODO implement this properly - via interp.write_error I suppose
438-
self.finish_command(self.saved_line, unfinished, self.saved_indent, err)
439-
440-
def finish_command(self, line, unfinished, indent, err):
441443

442-
done = not unfinished
443-
444-
if err:
445-
indent = 0
446-
self._current_line = ' '*indent
447-
self.cursor_offset_in_line = len(self._current_line)
448-
self.done = done
444+
indent = self.saved_indent
445+
if err:
446+
indent = 0
447+
self._current_line = ' '*indent
448+
self.cursor_offset_in_line = len(self._current_line)
449+
self.done = not unfinished
449450

450451
def unhighlight_paren(self):
451452
"""modify line in self.display_buffer to unhighlight a paren if possible

0 commit comments

Comments
 (0)