mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-07 05:31:18 +00:00
Fix Win32 get_key (#819)
PR #711 moved the arrow and cancel key codes to `const.py`. However, the move also changed the codes from byte arrays to strings, which broke the use of `msvcrt.getch()` for Windows. The fix is to use `msvcrt.getwch()` so the key is a Unicode character, matching the Unix implementation.
This commit is contained in:
parent
86efc6a252
commit
a6bb41e802
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import msvcrt
|
import msvcrt
|
||||||
import win_unicode_console
|
import win_unicode_console
|
||||||
from .. import const
|
from .. import const
|
||||||
@ -12,20 +11,18 @@ def init_output():
|
|||||||
|
|
||||||
|
|
||||||
def get_key():
|
def get_key():
|
||||||
ch = msvcrt.getch()
|
ch = msvcrt.getwch()
|
||||||
if ch in (b'\x00', b'\xe0'): # arrow or function key prefix?
|
if ch in ('\x00', '\xe0'): # arrow or function key prefix?
|
||||||
ch = msvcrt.getch() # second call returns the actual key code
|
ch = msvcrt.getwch() # second call returns the actual key code
|
||||||
|
|
||||||
if ch in const.KEY_MAPPING:
|
if ch in const.KEY_MAPPING:
|
||||||
return const.KEY_MAPPING[ch]
|
return const.KEY_MAPPING[ch]
|
||||||
if ch == b'H':
|
if ch == 'H':
|
||||||
return const.KEY_UP
|
return const.KEY_UP
|
||||||
if ch == b'P':
|
if ch == 'P':
|
||||||
return const.KEY_DOWN
|
return const.KEY_DOWN
|
||||||
|
|
||||||
encoding = (sys.stdout.encoding
|
return ch
|
||||||
or os.environ.get('PYTHONIOENCODING', 'utf-8'))
|
|
||||||
return ch.decode(encoding)
|
|
||||||
|
|
||||||
|
|
||||||
def open_command(arg):
|
def open_command(arg):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user