Skip to content

Commit 72f0df2

Browse files
committed
#711: Handle ctrl+n and ctrl+p
1 parent 50d14be commit 72f0df2

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

thefuck/const.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def __repr__(self):
1212
KEY_UP = _GenConst('↑')
1313
KEY_DOWN = _GenConst('↓')
1414
KEY_CTRL_C = _GenConst('Ctrl+C')
15+
KEY_CTRL_N = _GenConst('Ctrl+N')
16+
KEY_CTRL_P = _GenConst('Ctrl+P')
17+
18+
KEY_MAPPING = {'\x0e': KEY_CTRL_N,
19+
'\x03': KEY_CTRL_C,
20+
'\x10': KEY_CTRL_P}
1521

1622
ACTION_SELECT = _GenConst('select')
1723
ACTION_ABORT = _GenConst('abort')

thefuck/system/unix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def getch():
2222
def get_key():
2323
ch = getch()
2424

25-
if ch == '\x03':
26-
return const.KEY_CTRL_C
25+
if ch in const.KEY_MAPPING:
26+
return const.KEY_MAPPING[ch]
2727
elif ch == '\x1b':
2828
next_ch = getch()
2929
if next_ch == '[':

thefuck/system/win32.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def get_key():
1616
if ch in (b'\x00', b'\xe0'): # arrow or function key prefix?
1717
ch = msvcrt.getch() # second call returns the actual key code
1818

19-
if ch == b'\x03':
20-
return const.KEY_CTRL_C
19+
if ch in const.KEY_MAPPING:
20+
return const.KEY_MAPPING[ch]
2121
if ch == b'H':
2222
return const.KEY_UP
2323
if ch == b'P':

thefuck/ui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def read_actions():
1414
key = get_key()
1515

1616
# Handle arrows, j/k (qwerty), and n/e (colemak)
17-
if key in (const.KEY_UP, 'k', 'e'):
17+
if key in (const.KEY_UP, const.KEY_CTRL_N, 'k', 'e'):
1818
yield const.ACTION_PREVIOUS
19-
elif key in (const.KEY_DOWN, 'j', 'n'):
19+
elif key in (const.KEY_DOWN, const.KEY_CTRL_P, 'j', 'n'):
2020
yield const.ACTION_NEXT
2121
elif key in (const.KEY_CTRL_C, 'q'):
2222
yield const.ACTION_ABORT

0 commit comments

Comments
 (0)