Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getch on windows #414

Merged
merged 2 commits into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

VERSION = '3.2'

install_requires = ['psutil', 'colorama', 'six', 'decorator']
install_requires = ['psutil', 'colorama', 'six', 'decorator', 'win_unicode_console']
extras_require = {':python_version<"3.4"': ['pathlib']}

setup(name='thefuck',
Expand Down
2 changes: 2 additions & 0 deletions thefuck/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from warnings import warn
from pprint import pformat
import sys
import win_unicode_console
win_unicode_console.enable() #https://github.com/tartley/colorama/issues/32
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the issue related here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you need to init win_unicode_console before importing colorama

import colorama
from . import logs, types, shells
from .conf import settings
Expand Down
14 changes: 13 additions & 1 deletion thefuck/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
from . import logs

try:
from msvcrt import getch
import msvcrt
def getch():
ch = msvcrt.getch()
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':
raise KeyboardInterrupt
if ch == b'H':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msvcrt.getch returns H for and P for ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It returns two chars one \xe0 and one of those.

return 'k'
if ch == b'P':
return 'j'
return ch.decode(sys.stdout.encoding)
except ImportError:
def getch():
import tty
Expand Down