@@ -132,6 +132,8 @@ class BPythonEdit(urwid.Edit):
132
132
133
133
- move_cursor_to_coords is ignored
134
134
(except for internal calls from keypress or mouse_event).
135
+
136
+ - arrow up/down are ignored.
135
137
"""
136
138
137
139
def __init__ (self , * args , ** kwargs ):
@@ -191,10 +193,13 @@ def move_cursor_to_coords(self, *args):
191
193
return urwid .Edit .move_cursor_to_coords (self , * args )
192
194
return False
193
195
194
- def keypress (self , * args ):
196
+ def keypress (self , size , key ):
195
197
self ._bpy_may_move_cursor = True
196
198
try :
197
- return urwid .Edit .keypress (self , * args )
199
+ # Do not handle up/down arrow, leave them for the repl.
200
+ if urwid .command_map [key ] in ('cursor up' , 'cursor down' ):
201
+ return key
202
+ return urwid .Edit .keypress (self , size , key )
198
203
finally :
199
204
self ._bpy_may_move_cursor = False
200
205
@@ -474,6 +479,8 @@ def keyboard_interrupt(self):
474
479
self .echo ('KeyboardInterrupt' )
475
480
476
481
def prompt (self , more ):
482
+ # XXX is this the right place?
483
+ self .rl_history .reset ()
477
484
# XXX what is s_hist?
478
485
if not more :
479
486
self .edit = BPythonEdit (caption = ('prompt' , '>>> ' ))
@@ -514,6 +521,18 @@ def handle_input(self, event):
514
521
# ctrl+d on an empty line exits
515
522
if self .edit is not None and not self .edit .get_edit_text ():
516
523
raise urwid .ExitMainLoop ()
524
+ elif urwid .command_map [event ] == 'cursor up' :
525
+ # "back" from bpython.cli
526
+ self .cpos = 0
527
+ self .rl_history .enter (self .edit .get_edit_text ())
528
+ self .edit .set_edit_text ('' )
529
+ self .edit .insert_text (self .rl_history .back ())
530
+ elif urwid .command_map [event ] == 'cursor down' :
531
+ # "fwd" from bpython.cli
532
+ self .cpos = 0
533
+ self .rl_history .enter (self .edit .get_edit_text ())
534
+ self .edit .set_edit_text ('' )
535
+ self .edit .insert_text (self .rl_history .forward ())
517
536
#else:
518
537
# self.echo(repr(event))
519
538
0 commit comments