Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit261cf20

Browse files
committed
Initial work on urwid shortcuts working, todo: cleanup
1 parentbb2190c commit261cf20

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

‎bpython/cli.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
frombpython.configimportStruct
5555

5656
# This for keys
57-
frombpython.keysimportkey_dispatch
57+
frombpython.keysimportcli_key_dispatchaskey_dispatch
5858

5959
# This for i18n
6060
frombpythonimporttranslations

‎bpython/config.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
importsys
44
fromConfigParserimportConfigParser
55
fromitertoolsimportchain
6-
frombpython.keysimportkey_dispatch
6+
frombpython.keysimportcli_key_dispatchaskey_dispatch
77

88

99
classStruct(object):

‎bpython/keys.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,27 @@ def __delitem__(self, key):
4747
def__setitem__(self,key,value):
4848
self.map[key]=value
4949

50-
key_dispatch=KeyMap()
50+
cli_key_dispatch=KeyMap()
51+
urwid_key_dispatch=KeyMap()
5152

5253
# fill dispatch with letters
5354
forcinstring.ascii_lowercase:
54-
key_dispatch['C-%s'%c]= (chr(string.ascii_lowercase.index(c)+1),
55+
cli_key_dispatch['C-%s'%c]= (chr(string.ascii_lowercase.index(c)+1),
5556
'^%s'%c.upper())
5657

58+
forcinstring.ascii_lowercase:
59+
urwid_key_dispatch['C-%s'%c]='ctrl %s'%c
60+
5761
# fill dispatch with cool characters
58-
key_dispatch['C-[']= (chr(27),'^[')
59-
key_dispatch['C-\\']= (chr(28),'^\\')
60-
key_dispatch['C-]']= (chr(29),'^]')
61-
key_dispatch['C-^']= (chr(30),'^^')
62-
key_dispatch['C-_']= (chr(31),'^_')
62+
cli_key_dispatch['C-[']= (chr(27),'^[')
63+
cli_key_dispatch['C-\\']= (chr(28),'^\\')
64+
cli_key_dispatch['C-]']= (chr(29),'^]')
65+
cli_key_dispatch['C-^']= (chr(30),'^^')
66+
cli_key_dispatch['C-_']= (chr(31),'^_')
6367

6468
# fill dispatch with function keys
6569
forxinxrange(1,13):
66-
key_dispatch['F%s'%str(x)]= ('KEY_F(%s)'%str(x),)
70+
cli_key_dispatch['F%s'%str(x)]= ('KEY_F(%s)'%str(x),)
71+
72+
forxinxrange(1,13):
73+
urwid_key_dispatch['F%s'%str(x)]='F%s'%str(x)

‎bpython/urwid.py‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
frombpython.importcompletionimportfind_coroutine
5050
frombpython.translationsimport_
5151

52+
frombpython.keysimporturwid_key_dispatchaskey_dispatch
53+
5254
importurwid
5355

5456
py3=sys.version_info[0]==3
@@ -77,6 +79,8 @@
7779
'd':'default',
7880
}
7981

82+
# Add our keys to the urwid command_map
83+
8084

8185
try:
8286
fromtwisted.internetimportprotocol
@@ -215,12 +219,13 @@ class BPythonEdit(urwid.Edit):
215219

216220
signals= ['edit-pos-changed']
217221

218-
def__init__(self,tab_length,*args,**kwargs):
222+
def__init__(self,config,*args,**kwargs):
219223
self._bpy_text=''
220224
self._bpy_attr= []
221225
self._bpy_selectable=True
222226
self._bpy_may_move_cursor=False
223-
self.tab_length=tab_length
227+
self.config=config
228+
self.tab_length=config.tab_length
224229
urwid.Edit.__init__(self,*args,**kwargs)
225230

226231
defset_edit_pos(self,pos):
@@ -294,6 +299,9 @@ def keypress(self, size, key):
294299
ifnot (cposorlen(line)%self.tab_lengthorline.strip()):
295300
self.set_edit_text(line[:-self.tab_length])
296301
returnNone
302+
elifkey=='pastebin':
303+
# do pastebin
304+
pass
297305
# TODO: Add in specific keypress fetching code here
298306
returnurwid.Edit.keypress(self,size,key)
299307
finally:
@@ -451,6 +459,8 @@ def __init__(self, event_loop, palette, interpreter, config):
451459
self.edit=None
452460
self._completion_update_suppressed=False
453461

462+
load_urwid_command_map(config)
463+
454464
# Subclasses of Repl need to implement echo, current_line, cw
455465
defecho(self,s):
456466
s=s.rstrip('\n')
@@ -722,11 +732,11 @@ def prompt(self, more):
722732
self.rl_history.reset()
723733
# XXX what is s_hist?
724734
ifnotmore:
725-
self.edit=BPythonEdit(self.config.tab_length,
735+
self.edit=BPythonEdit(self.config,
726736
caption=('prompt','>>> '))
727737
self.stdout_hist+='>>> '
728738
else:
729-
self.edit=BPythonEdit(self.config.tab_length,
739+
self.edit=BPythonEdit(self.config,
730740
caption=('prompt_more','... '))
731741
self.stdout_hist+='... '
732742

@@ -1036,6 +1046,25 @@ def run_find_coroutine():
10361046
sys.stdout.write(myrepl.getstdout())
10371047
sys.stdout.flush()
10381048

1039-
1049+
defload_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+
"""
10401069
if__name__=='__main__':
10411070
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp