From b18a049886f36a36a5e41f977cae3d12c195e268 Mon Sep 17 00:00:00 2001
From: Pavel Krymets <pavel@krymets.com>
Date: Mon, 30 Nov 2015 12:33:28 -0800
Subject: [PATCH] Fix getch on windows

---
 thefuck/ui.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/thefuck/ui.py b/thefuck/ui.py
index e54e8654..8a3ec7a9 100644
--- a/thefuck/ui.py
+++ b/thefuck/ui.py
@@ -6,7 +6,19 @@ from .exceptions import NoRuleMatched
 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':
+            return 'k'
+        if ch == b'P':
+            return 'j'
+        return ch.decode(sys.stdout.encoding)
 except ImportError:
     def getch():
         import tty