def run(self, context, KEY, ACTION):
keymap = self.tui.keymap
key = KEY
if len(ACTION) == 1 and ACTION[0][0] == '<' and ACTION[0][-1] == '>':
# ACTION is another key (e.g. 'j' -> 'down')
action = keymap.mkkey(ACTION[0])
else:
action = ' '.join(shlex.quote(x) for x in ACTION)
if context is None:
from ...tui.keymap import DEFAULT_CONTEXT
context = DEFAULT_CONTEXT
elif context not in _get_KEYMAP_CONTEXTS():
log.error('Invalid context: {!r}'.format(context))
return False
try:
keymap.bind(key, action, context=context)
except ValueError as e:
log.error(e)
return False
else:
return True
评论列表
文章目录