Skip to content

Commit 81c2197

Browse files
fix #370
1 parent f8b56d1 commit 81c2197

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,6 @@ def on_enter(self, insert_into_history=True):
594594
self.unhighlight_paren() # in unhighlight_paren
595595
self.highlighted_paren = None
596596

597-
self.rl_history.append(self.current_line)
598-
self.rl_history.last()
599597
self.history.append(self.current_line)
600598
self.push(self.current_line, insert_into_history=insert_into_history)
601599

@@ -1038,6 +1036,10 @@ def paint(self, about_to_exit=False, user_quit=False):
10381036
arr = FSArray(0, width)
10391037
#TODO test case of current line filling up the whole screen (there aren't enough rows to show it)
10401038

1039+
current_line = paint.paint_current_line(min_height, width, self.current_cursor_line)
1040+
# needs to happen before we calculate contents of history because calculating
1041+
# self.current_cursor_line has the side effect of unhighlighting parens in buffer
1042+
10411043
def move_screen_up(current_line_start_row):
10421044
# move screen back up a screen minus a line
10431045
while current_line_start_row < 0:
@@ -1084,12 +1086,8 @@ def move_screen_up(current_line_start_row):
10841086
history = paint.paint_history(current_line_start_row, width, self.lines_for_display)
10851087
arr[:history.height,:history.width] = history
10861088

1087-
1088-
1089-
10901089
self.inconsistent_history = False
10911090

1092-
current_line = paint.paint_current_line(min_height, width, self.current_cursor_line)
10931091
if user_quit: # quit() or exit() in interp
10941092
current_line_start_row = current_line_start_row - current_line.height
10951093
logger.debug("---current line row slice %r, %r", current_line_start_row, current_line_start_row + current_line.height)
@@ -1223,11 +1221,14 @@ def _set_current_line(self, line, update_completion=True, reset_rl_history=True,
12231221
self.rl_history.reset()
12241222
if clear_special_mode:
12251223
self.special_mode = None
1224+
self.unhighlight_paren()
12261225
current_line = property(_get_current_line, _set_current_line, None,
12271226
"The current line")
12281227
def _get_cursor_offset(self):
12291228
return self._cursor_offset
12301229
def _set_cursor_offset(self, offset, update_completion=True, reset_rl_history=False, clear_special_mode=True):
1230+
if self._cursor_offset == offset:
1231+
return
12311232
if update_completion:
12321233
self.update_completion()
12331234
if reset_rl_history:
@@ -1236,6 +1237,7 @@ def _set_cursor_offset(self, offset, update_completion=True, reset_rl_history=Fa
12361237
self.incremental_search_mode = None
12371238
self._cursor_offset = offset
12381239
self.update_completion()
1240+
self.unhighlight_paren()
12391241
cursor_offset = property(_get_cursor_offset, _set_cursor_offset, None,
12401242
"The current cursor offset from the front of the line")
12411243
def echo(self, msg, redraw=True):

bpython/test/test_curtsies_painting.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_run_line(self):
6262
orig_stdout = sys.stdout
6363
sys.stdout = self.repl.stdout
6464
[self.repl.add_normal_character(c) for c in '1 + 1']
65-
self.repl.on_enter()
65+
self.repl.on_enter(insert_into_history=False)
6666
screen = fsarray([u'>>> 1 + 1', '2', 'Welcome to'])
6767
self.assert_paint_ignoring_formatting(screen, (1, 1))
6868
finally:
@@ -105,7 +105,8 @@ def enter(self, line=None):
105105
if line is not None:
106106
self.repl.current_line = line
107107
with output_to_repl(self.repl):
108-
self.repl.on_enter()
108+
self.repl.on_enter(insert_into_history=False)
109+
self.assertEqual(self.repl.rl_history.entries, [''])
109110
self.send_refreshes()
110111

111112
def undo(self):
@@ -432,7 +433,7 @@ def test_cursor_stays_at_bottom_of_screen(self):
432433
self.repl.width = 50
433434
self.repl.current_line = "__import__('random').__name__"
434435
with output_to_repl(self.repl):
435-
self.repl.on_enter()
436+
self.repl.on_enter(insert_into_history=False)
436437
screen = [u">>> __import__('random').__name__",
437438
u"'random'"]
438439
self.assert_paint_ignoring_formatting(screen)
@@ -451,15 +452,28 @@ def test_cursor_stays_at_bottom_of_screen(self):
451452
u">>> "]
452453
self.assert_paint_ignoring_formatting(screen, (2, 4))
453454

454-
def test_unhighlight_paren_bug(self):
455-
"""infobox showing up during intermediate render was causing this to fail, #371"""
455+
def test_unhighlight_paren_bugs(self):
456+
"""two previous bugs, paren did't highlight until next render
457+
and paren didn't unhighlight until enter"""
458+
self.assertEqual(self.repl.rl_history.entries, [''])
456459
self.enter('(')
460+
self.assertEqual(self.repl.rl_history.entries, [''])
457461
screen = [u">>> (",
458462
u"... "]
463+
self.assertEqual(self.repl.rl_history.entries, [''])
459464
self.assert_paint_ignoring_formatting(screen)
465+
self.assertEqual(self.repl.rl_history.entries, [''])
460466

461467
with output_to_repl(self.repl):
468+
self.assertEqual(self.repl.rl_history.entries, [''])
462469
self.repl.process_event(')')
470+
self.assertEqual(self.repl.rl_history.entries, [''])
471+
screen = fsarray([cyan(u">>> ")+on_magenta(bold(red('('))),
472+
green(u"... ")+on_magenta(bold(red(')')))])
473+
self.assert_paint(screen, (1, 5))
474+
475+
with output_to_repl(self.repl):
476+
self.repl.process_event(' ')
463477
screen = fsarray([cyan(u">>> ")+yellow('('),
464-
green(u"... ")+yellow(')')])
465-
self.assert_paint(screen, (1, 3))
478+
green(u"... ")+yellow(')')+bold(cyan(" "))])
479+
self.assert_paint(screen, (1, 6))

0 commit comments

Comments
 (0)