mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-15 23:30:44 +01:00
#711: Handle ctrl+n and ctrl+p
This commit is contained in:
parent
50d14be43a
commit
72f0df2f90
@ -12,6 +12,12 @@ class _GenConst(object):
|
|||||||
KEY_UP = _GenConst('↑')
|
KEY_UP = _GenConst('↑')
|
||||||
KEY_DOWN = _GenConst('↓')
|
KEY_DOWN = _GenConst('↓')
|
||||||
KEY_CTRL_C = _GenConst('Ctrl+C')
|
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_SELECT = _GenConst('select')
|
||||||
ACTION_ABORT = _GenConst('abort')
|
ACTION_ABORT = _GenConst('abort')
|
||||||
|
@ -22,8 +22,8 @@ def getch():
|
|||||||
def get_key():
|
def get_key():
|
||||||
ch = getch()
|
ch = getch()
|
||||||
|
|
||||||
if ch == '\x03':
|
if ch in const.KEY_MAPPING:
|
||||||
return const.KEY_CTRL_C
|
return const.KEY_MAPPING[ch]
|
||||||
elif ch == '\x1b':
|
elif ch == '\x1b':
|
||||||
next_ch = getch()
|
next_ch = getch()
|
||||||
if next_ch == '[':
|
if next_ch == '[':
|
||||||
|
@ -16,8 +16,8 @@ def get_key():
|
|||||||
if ch in (b'\x00', b'\xe0'): # arrow or function key prefix?
|
if ch in (b'\x00', b'\xe0'): # arrow or function key prefix?
|
||||||
ch = msvcrt.getch() # second call returns the actual key code
|
ch = msvcrt.getch() # second call returns the actual key code
|
||||||
|
|
||||||
if ch == b'\x03':
|
if ch in const.KEY_MAPPING:
|
||||||
return const.KEY_CTRL_C
|
return const.KEY_MAPPING[ch]
|
||||||
if ch == b'H':
|
if ch == b'H':
|
||||||
return const.KEY_UP
|
return const.KEY_UP
|
||||||
if ch == b'P':
|
if ch == b'P':
|
||||||
|
@ -14,9 +14,9 @@ def read_actions():
|
|||||||
key = get_key()
|
key = get_key()
|
||||||
|
|
||||||
# Handle arrows, j/k (qwerty), and n/e (colemak)
|
# 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
|
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
|
yield const.ACTION_NEXT
|
||||||
elif key in (const.KEY_CTRL_C, 'q'):
|
elif key in (const.KEY_CTRL_C, 'q'):
|
||||||
yield const.ACTION_ABORT
|
yield const.ACTION_ABORT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user