|
49 | 49 | from bpython.importcompletion import find_coroutine |
50 | 50 | from bpython.translations import _ |
51 | 51 |
|
| 52 | +from bpython.keys import urwid_key_dispatch as key_dispatch |
| 53 | + |
52 | 54 | import urwid |
53 | 55 |
|
54 | 56 | py3 = sys.version_info[0] == 3 |
|
77 | 79 | 'd': 'default', |
78 | 80 | } |
79 | 81 |
|
| 82 | +# Add our keys to the urwid command_map |
| 83 | + |
80 | 84 |
|
81 | 85 | try: |
82 | 86 | from twisted.internet import protocol |
@@ -215,12 +219,13 @@ class BPythonEdit(urwid.Edit): |
215 | 219 |
|
216 | 220 | signals = ['edit-pos-changed'] |
217 | 221 |
|
218 | | - def __init__(self, tab_length, *args, **kwargs): |
| 222 | + def __init__(self, config, *args, **kwargs): |
219 | 223 | self._bpy_text = '' |
220 | 224 | self._bpy_attr = [] |
221 | 225 | self._bpy_selectable = True |
222 | 226 | self._bpy_may_move_cursor = False |
223 | | - self.tab_length = tab_length |
| 227 | + self.config = config |
| 228 | + self.tab_length = config.tab_length |
224 | 229 | urwid.Edit.__init__(self, *args, **kwargs) |
225 | 230 |
|
226 | 231 | def set_edit_pos(self, pos): |
@@ -294,6 +299,9 @@ def keypress(self, size, key): |
294 | 299 | if not (cpos or len(line) % self.tab_length or line.strip()): |
295 | 300 | self.set_edit_text(line[:-self.tab_length]) |
296 | 301 | return None |
| 302 | + elif key == 'pastebin': |
| 303 | + # do pastebin |
| 304 | + pass |
297 | 305 | # TODO: Add in specific keypress fetching code here |
298 | 306 | return urwid.Edit.keypress(self, size, key) |
299 | 307 | finally: |
@@ -451,6 +459,8 @@ def __init__(self, event_loop, palette, interpreter, config): |
451 | 459 | self.edit = None |
452 | 460 | self._completion_update_suppressed = False |
453 | 461 |
|
| 462 | + load_urwid_command_map(config) |
| 463 | + |
454 | 464 | # Subclasses of Repl need to implement echo, current_line, cw |
455 | 465 | def echo(self, s): |
456 | 466 | s = s.rstrip('\n') |
@@ -722,11 +732,11 @@ def prompt(self, more): |
722 | 732 | self.rl_history.reset() |
723 | 733 | # XXX what is s_hist? |
724 | 734 | if not more: |
725 | | - self.edit = BPythonEdit(self.config.tab_length, |
| 735 | + self.edit = BPythonEdit(self.config, |
726 | 736 | caption=('prompt', '>>> ')) |
727 | 737 | self.stdout_hist += '>>> ' |
728 | 738 | else: |
729 | | - self.edit = BPythonEdit(self.config.tab_length, |
| 739 | + self.edit = BPythonEdit(self.config, |
730 | 740 | caption=('prompt_more', '... ')) |
731 | 741 | self.stdout_hist += '... ' |
732 | 742 |
|
@@ -1036,6 +1046,25 @@ def run_find_coroutine(): |
1036 | 1046 | sys.stdout.write(myrepl.getstdout()) |
1037 | 1047 | sys.stdout.flush() |
1038 | 1048 |
|
1039 | | - |
| 1049 | +def load_urwid_command_map(config): |
| 1050 | + urwid.command_map[key_dispatch[config.up_one_line_key]] = 'cursor up' |
| 1051 | + urwid.command_map[key_dispatch[config.down_one_line_key]] = 'cursor down' |
| 1052 | +""" |
| 1053 | + 'clear_line': 'C-u', |
| 1054 | + 'clear_screen': 'C-l', |
| 1055 | + 'clear_word': 'C-w', |
| 1056 | + 'cut_to_buffer': 'C-k', |
| 1057 | + 'delete': 'C-d', |
| 1058 | + 'down_one_line': 'C-n', |
| 1059 | + 'exit': '', |
| 1060 | + 'last_output': 'F9', |
| 1061 | + 'pastebin': 'F8', |
| 1062 | + 'save': 'C-s', |
| 1063 | + 'show_source': 'F2', |
| 1064 | + 'suspend': 'C-z', |
| 1065 | + 'undo': 'C-r', |
| 1066 | + 'up_one_line': 'C-p', |
| 1067 | + 'yank_from_buffer': 'C-y'}, |
| 1068 | +""" |
1040 | 1069 | if __name__ == '__main__': |
1041 | 1070 | main() |
0 commit comments