Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,13 +1079,6 @@ def run_code_and_maybe_finish(self, for_code=None):
if err:
indent = 0

# TODO This should be printed ABOVE the error that just happened
# instead or maybe just thrown away and not shown
if self.current_stdouterr_line:
self.display_lines.extend(paint.display_linize(
self.current_stdouterr_line, self.width))
self.current_stdouterr_line = ''

if self.rl_history.index == 0:
self._set_current_line(' ' * indent, update_completion=True)
else:
Expand Down Expand Up @@ -1137,11 +1130,27 @@ def clear_current_block(self, remove_from_history=True):
def get_current_block(self):
return '\n'.join(self.buffer + [self.current_line])

def move_current_stdouterr_line_up(self):
"""Append self.current_stdouterr_line to self.display_lines
then clean it."""
self.display_lines.extend(paint.display_linize(
self.current_stdouterr_line, self.width))
self.current_stdouterr_line = ''

def send_to_stdout(self, output):
"""Send unicode string to Repl stdout"""
if not output:
return
lines = output.split('\n')
if all(not line for line in lines):
# If the string consist only of newline characters,
# str.split returns one more empty strings.
lines = lines[:-1]
logger.debug('display_lines: %r', self.display_lines)
self.current_stdouterr_line += lines[0]
if lines[0]:
self.current_stdouterr_line += lines[0]
else:
self.move_current_stdouterr_line_up()
if len(lines) > 1:
self.display_lines.extend(paint.display_linize(
self.current_stdouterr_line, self.width, blank_line=True))
Expand All @@ -1157,9 +1166,17 @@ def send_to_stderr(self, error):

Must be able to handle FmtStrs because interpreter pass in
tracebacks already formatted."""
if not error:
return
lines = error.split('\n')
if all(not line for line in lines):
# If the string consist only of newline characters,
# str.split returns one more empty strings.
lines = lines[:-1]
if lines[-1]:
self.current_stdouterr_line += lines[-1]
else:
self.move_current_stdouterr_line_up()
self.display_lines.extend(sum((paint.display_linize(line, self.width,
blank_line=True)
for line in lines[:-1]), []))
Expand Down