Simon de Vlieger avatar Simon de Vlieger committed 250f811

Initial work on urwid shortcuts working, todo: cleanup

Comments (0)

Files changed (4)

 from bpython.config import Struct
 
 # This for keys
-from bpython.keys import key_dispatch
+from bpython.keys import cli_key_dispatch as key_dispatch
 
 # This for i18n
 from bpython import translations

bpython/config.py

 import sys
 from ConfigParser import ConfigParser
 from itertools import chain
-from bpython.keys import key_dispatch
+from bpython.keys import cli_key_dispatch as key_dispatch
 
 
 class Struct(object):
     def __setitem__(self, key, value):
         self.map[key] = value
 
-key_dispatch = KeyMap()
+cli_key_dispatch = KeyMap()
+urwid_key_dispatch = KeyMap()
 
 # fill dispatch with letters
 for c in string.ascii_lowercase:
-    key_dispatch['C-%s' % c] = (chr(string.ascii_lowercase.index(c) + 1),
+    cli_key_dispatch['C-%s' % c] = (chr(string.ascii_lowercase.index(c) + 1),
                                 '^%s' % c.upper())
 
+for c in string.ascii_lowercase:
+    urwid_key_dispatch['C-%s' % c] = 'ctrl %s' % c 
+
 # fill dispatch with cool characters
-key_dispatch['C-['] = (chr(27), '^[')
-key_dispatch['C-\\'] = (chr(28), '^\\')
-key_dispatch['C-]'] = (chr(29), '^]')
-key_dispatch['C-^'] = (chr(30), '^^')
-key_dispatch['C-_'] = (chr(31), '^_')
+cli_key_dispatch['C-['] = (chr(27), '^[')
+cli_key_dispatch['C-\\'] = (chr(28), '^\\')
+cli_key_dispatch['C-]'] = (chr(29), '^]')
+cli_key_dispatch['C-^'] = (chr(30), '^^')
+cli_key_dispatch['C-_'] = (chr(31), '^_')
 
 # fill dispatch with function keys
 for x in xrange(1, 13):
-    key_dispatch['F%s' % str(x)] = ('KEY_F(%s)' % str(x),)
+    cli_key_dispatch['F%s' % str(x)] = ('KEY_F(%s)' % str(x),)
+
+for x in xrange(1, 13):
+    urwid_key_dispatch['F%s' % str(x)] = 'F%s' % str(x)
 from bpython.importcompletion import find_coroutine
 from bpython.translations import _
 
+from bpython.keys import urwid_key_dispatch as key_dispatch
+
 import urwid
 
 py3 = sys.version_info[0] == 3
     'd': 'default',
     }
 
+# Add our keys to the urwid command_map
+
 
 try:
     from twisted.internet import protocol
 
     signals = ['edit-pos-changed']
 
-    def __init__(self, tab_length, *args, **kwargs):
+    def __init__(self, config, *args, **kwargs):
         self._bpy_text = ''
         self._bpy_attr = []
         self._bpy_selectable = True
         self._bpy_may_move_cursor = False
-        self.tab_length = tab_length
+        self.config = config
+        self.tab_length = config.tab_length 
         urwid.Edit.__init__(self, *args, **kwargs)
 
     def set_edit_pos(self, pos):
                 if not (cpos or len(line) % self.tab_length or line.strip()):
                     self.set_edit_text(line[:-self.tab_length])
                     return None
+            elif key == 'pastebin':
+                # do pastebin
+                pass
             # TODO: Add in specific keypress fetching code here
             return urwid.Edit.keypress(self, size, key)
         finally:
         self.edit = None
         self._completion_update_suppressed = False
 
+        load_urwid_command_map(config)
+
     # Subclasses of Repl need to implement echo, current_line, cw
     def echo(self, s):
         s = s.rstrip('\n')
         self.rl_history.reset()
         # XXX what is s_hist?
         if not more:
-            self.edit = BPythonEdit(self.config.tab_length,
+            self.edit = BPythonEdit(self.config,
                                     caption=('prompt', '>>> '))
             self.stdout_hist += '>>> '
         else:
-            self.edit = BPythonEdit(self.config.tab_length,
+            self.edit = BPythonEdit(self.config,
                                     caption=('prompt_more', '... '))
             self.stdout_hist += '... '
 
         sys.stdout.write(myrepl.getstdout())
     sys.stdout.flush()
 
-
+def load_urwid_command_map(config):
+    urwid.command_map[key_dispatch[config.up_one_line_key]] = 'cursor up'
+    urwid.command_map[key_dispatch[config.down_one_line_key]] = 'cursor down'
+"""
+            'clear_line': 'C-u',
+            'clear_screen': 'C-l',
+            'clear_word': 'C-w',
+            'cut_to_buffer': 'C-k',
+            'delete': 'C-d',
+            'down_one_line': 'C-n',
+            'exit': '',
+            'last_output': 'F9',
+            'pastebin': 'F8',
+            'save': 'C-s',
+            'show_source': 'F2',
+            'suspend': 'C-z',
+            'undo': 'C-r',
+            'up_one_line': 'C-p',
+            'yank_from_buffer': 'C-y'},
+"""
 if __name__ == '__main__':
     main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.