X Tutup
Skip to content

Commit 6596693

Browse files
committed
Rollback to 265 to fix bobs merge mishap
1 parent 4534fe0 commit 6596693

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

bpython/cli.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def next_token_inside_string(s, inside_string):
248248

249249
class Interpreter(code.InteractiveInterpreter):
250250

251-
def __init__(self, encoding):
251+
def __init__(self, locals=None, encoding=sys.getdefaultencoding()):
252252
"""The syntaxerror callback can be set at any time and will be called
253253
on a caught syntax error. The purpose for this in bpython is so that
254254
the repl can be instantiated after the interpreter (which it
@@ -260,7 +260,7 @@ def __init__(self, encoding):
260260
self.encoding = encoding
261261
self.syntaxerror_callback = None
262262
# Unfortunately code.InteractiveInterpreter is a classic class, so no super()
263-
code.InteractiveInterpreter.__init__(self)
263+
code.InteractiveInterpreter.__init__(self, locals)
264264

265265
def runsource(self, source):
266266
source = '# coding: %s\n%s' % (self.encoding,
@@ -1080,6 +1080,8 @@ def undo(self, n=1):
10801080

10811081
self.history = self.history[:-n]
10821082
self.reevaluate()
1083+
# This will unhighlight highlighted parens
1084+
self.print_line(self.s)
10831085

10841086
def enter_hist(self):
10851087
"""Set flags for entering into the history by pressing up/down"""
@@ -1231,6 +1233,8 @@ def repl(self):
12311233
if inp:
12321234
self.rl_hist.append(inp + '\n')
12331235
more = self.push(inp) or self.paste_mode
1236+
if not more:
1237+
self.s = ''
12341238

12351239
def size(self):
12361240
"""Set instance attributes for x and y top left corner coordinates
@@ -1474,17 +1478,19 @@ def p_key(self):
14741478
elif self.c == 'KEY_DC': # Del
14751479
self.delete()
14761480
self.complete()
1481+
# Redraw (as there might have been highlighted parens)
1482+
self.print_line(self.s)
14771483
return ''
14781484

1479-
elif self.c in key_dispatch['C-r']: # C-r
1485+
elif self.c in key_dispatch[OPTS.undo_key]: # C-r
14801486
self.undo()
14811487
return ''
14821488

1483-
elif self.c in ('KEY_UP', ) + key_dispatch['C-p']: # Cursor Up/C-p
1489+
elif self.c in ('KEY_UP', ) + key_dispatch[OPTS.up_one_line_key]: # Cursor Up/C-p
14841490
self.back()
14851491
return ''
14861492

1487-
elif self.c in ('KEY_DOWN', ) + key_dispatch['C-n']: # Cursor Down/C-n
1493+
elif self.c in ('KEY_DOWN', ) + key_dispatch[OPTS.down_one_line_key]: # Cursor Down/C-n
14881494
self.fwd()
14891495
return ''
14901496

@@ -1508,30 +1514,30 @@ def p_key(self):
15081514
# Redraw (as there might have been highlighted parens)
15091515
self.print_line(self.s)
15101516

1511-
elif self.c in key_dispatch['C-k']: # cut to buffer
1517+
elif self.c in key_dispatch[OPTS.cut_to_buffer_key]: # cut to buffer
15121518
self.cut_to_buffer()
15131519
return ''
15141520

1515-
elif self.c in key_dispatch['C-y']: # yank from buffer
1521+
elif self.c in key_dispatch[OPTS.yank_from_buffer_key]: # yank from buffer
15161522
self.yank_from_buffer()
15171523
return ''
15181524

1519-
elif self.c in key_dispatch['C-w']:
1525+
elif self.c in key_dispatch[OPTS.clear_word_key]:
15201526
self.bs_word()
15211527
self.complete()
15221528
return ''
15231529

1524-
elif self.c in key_dispatch['C-u']:
1530+
elif self.c in key_dispatch[OPTS.clear_line_key]:
15251531
self.clrtobol()
15261532
return ''
15271533

1528-
elif self.c in key_dispatch['C-l']:
1534+
elif self.c in key_dispatch[OPTS.clear_screen_key]:
15291535
self.s_hist = [self.s_hist[-1]]
15301536
self.highlighted_paren = None
15311537
self.redraw()
15321538
return ''
15331539

1534-
elif self.c in key_dispatch['C-d']:
1540+
elif self.c in key_dispatch[OPTS.exit_key]:
15351541
if not self.s:
15361542
self.do_exit = True
15371543
return None
@@ -1703,7 +1709,7 @@ def reprint_line(lineno, s, to_replace=[]):
17031709
# Marker found
17041710
tokens[i] = (Parenthesis, value)
17051711
break
1706-
elif opening and under_cursor:
1712+
elif opening and under_cursor and not newline:
17071713
if self.cpos:
17081714
tokens[i] = (Parenthesis.UnderCursor, value)
17091715
else:
@@ -2120,7 +2126,8 @@ def main_curses(scr, args, interactive=True):
21202126

21212127
curses.raw(True)
21222128

2123-
interpreter = Interpreter(getpreferredencoding())
2129+
interpreter = Interpreter(dict(__name__='__main__', __doc__=None),
2130+
getpreferredencoding())
21242131

21252132
repl = Repl(main_win, interpreter, statusbar, idle)
21262133
interpreter.syntaxerror_callback = repl.clear_current_line

0 commit comments

Comments
 (0)
X Tutup