1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

#711: Handle ctrl+n and ctrl+p

This commit is contained in:
Vladimir Iakovlev 2017-10-16 19:19:29 +02:00
parent 50d14be43a
commit 72f0df2f90
4 changed files with 12 additions and 6 deletions

View File

@ -12,6 +12,12 @@ class _GenConst(object):
KEY_UP = _GenConst('')
KEY_DOWN = _GenConst('')
KEY_CTRL_C = _GenConst('Ctrl+C')
KEY_CTRL_N = _GenConst('Ctrl+N')
KEY_CTRL_P = _GenConst('Ctrl+P')
KEY_MAPPING = {'\x0e': KEY_CTRL_N,
'\x03': KEY_CTRL_C,
'\x10': KEY_CTRL_P}
ACTION_SELECT = _GenConst('select')
ACTION_ABORT = _GenConst('abort')

View File

@ -22,8 +22,8 @@ def getch():
def get_key():
ch = getch()
if ch == '\x03':
return const.KEY_CTRL_C
if ch in const.KEY_MAPPING:
return const.KEY_MAPPING[ch]
elif ch == '\x1b':
next_ch = getch()
if next_ch == '[':

View File

@ -16,8 +16,8 @@ def get_key():
if ch in (b'\x00', b'\xe0'): # arrow or function key prefix?
ch = msvcrt.getch() # second call returns the actual key code
if ch == b'\x03':
return const.KEY_CTRL_C
if ch in const.KEY_MAPPING:
return const.KEY_MAPPING[ch]
if ch == b'H':
return const.KEY_UP
if ch == b'P':

View File

@ -14,9 +14,9 @@ def read_actions():
key = get_key()
# Handle arrows, j/k (qwerty), and n/e (colemak)
if key in (const.KEY_UP, 'k', 'e'):
if key in (const.KEY_UP, const.KEY_CTRL_N, 'k', 'e'):
yield const.ACTION_PREVIOUS
elif key in (const.KEY_DOWN, 'j', 'n'):
elif key in (const.KEY_DOWN, const.KEY_CTRL_P, 'j', 'n'):
yield const.ACTION_NEXT
elif key in (const.KEY_CTRL_C, 'q'):
yield const.ACTION_ABORT