From 0560f4ba8edfd11b70293b104bd16d069a36c24b Mon Sep 17 00:00:00 2001 From: nvbn Date: Tue, 1 Dec 2015 20:15:27 +0800 Subject: [PATCH] #414: Install and use `win_unicode_console` only on windows --- setup.py | 5 +++-- thefuck/main.py | 15 +++++++++++---- thefuck/ui.py | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 807b4911..aa4f3729 100755 --- a/setup.py +++ b/setup.py @@ -22,8 +22,9 @@ elif (3, 0) < version < (3, 3): VERSION = '3.2' -install_requires = ['psutil', 'colorama', 'six', 'decorator', 'win_unicode_console'] -extras_require = {':python_version<"3.4"': ['pathlib']} +install_requires = ['psutil', 'colorama', 'six', 'decorator'] +extras_require = {':python_version<"3.4"': ['pathlib'], + ":sys_platform=='win32'": ['win_unicode_console']} setup(name='thefuck', version=VERSION, diff --git a/thefuck/main.py b/thefuck/main.py index ecca3512..5f52f53c 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -2,8 +2,6 @@ from argparse import ArgumentParser 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 import colorama from . import logs, types, shells from .conf import settings @@ -13,9 +11,18 @@ from .utils import get_installation_info from .ui import select_command +def init_colorama(): + if sys.platform == 'win32': + # https://github.com/tartley/colorama/issues/32 + import win_unicode_console + + win_unicode_console.enable() + colorama.init() + + def fix_command(): """Fixes previous command. Used when `thefuck` called without arguments.""" - colorama.init() + init_colorama() settings.init() with logs.debug_time('Total'): logs.debug(u'Run with settings: {}'.format(pformat(settings))) @@ -53,7 +60,7 @@ def how_to_configure_alias(): It'll be only visible when user type fuck and when alias isn't configured. """ - colorama.init() + init_colorama() settings.init() logs.how_to_configure_alias(shells.how_to_configure()) diff --git a/thefuck/ui.py b/thefuck/ui.py index 8a3ec7a9..bea45e96 100644 --- a/thefuck/ui.py +++ b/thefuck/ui.py @@ -7,6 +7,7 @@ from . import logs try: import msvcrt + def getch(): ch = msvcrt.getch() if ch in (b'\x00', b'\xe0'): # arrow or function key prefix?