Commits

anatoly techtonik committed 6ada9fd

Fix special keys on Windows. Bump version to 1.3

Comments (0)

Files changed (3)

 Status
 ------
 
+1.3 (stable)
+ - fix ENTER LEFT UP RIGHT DOWN ESC keys on Windows
 1.2 (stable)
  - add names for ENTER LEFT UP RIGHT DOWN ESC keys
  - manual tests for getch() (fixes bug #4)
 License: Public Domain (use MIT if Public Domain doesn't work for you)
 """
 
-__version__ = '1.2'
+__version__ = '1.3'
 
 import os,sys
 
 STD_OUTPUT_HANDLE = -11
 STD_ERROR_HANDLE  = -12
 
-if os.name == 'nt':
+WINDOWS = os.name == 'nt' 
+
+if WINDOWS:
     # get console handle
     from ctypes import windll, Structure, byref
     try:
     *nix part uses termios ioctl TIOCGWINSZ call.
     """
     width = None
-    if os.name == 'nt':
+    if WINDOWS:
         return _windows_get_window_size()[0]
     elif os.name == 'posix':
         return _posix_get_window_size()[0]
     *nix part uses termios ioctl TIOCGWINSZ call.
     """
     height = None
-    if os.name == 'nt':
+    if WINDOWS:
         return _windows_get_window_size()[1]
     elif os.name == 'posix':
         return _posix_get_window_size()[1]
 
 # --- getch() constants and input logic ---
 
-ENTER = '\n'
-ESC = '\x1B'
-LEFT = ['\x1b', '[', 'D']
-RIGHT = ['\x1b', '[', 'C']
-UP = ['\x1b', '[', 'A']
-DOWN = ['\x1b', '[', 'B']
+if WINDOWS:
+    ENTER = '\x0d'
+    LEFT =  ['\xe0', 'K']
+    UP =    ['\xe0', 'H']
+    RIGHT = ['\xe0', 'M']
+    DOWN =  ['\xe0', 'P']
+else:
+    ENTER = '\n'
+    LEFT =  ['\x1b', '[', 'D']
+    UP =    ['\x1b', '[', 'A']
+    RIGHT = ['\x1b', '[', 'C']
+    DOWN =  ['\x1b', '[', 'B']
+ESC = '\x1b'
 
 def dumpkey(key):
     """
     try:
         import msvcrt
         ch = msvcrt.getch()
-        # [ ] TODO - test this on Windows
+        # [ ] deal with buffered output - return when a key is
+        #     recognized or scan code exceeds max len
         while msvcrt.kbhit():
             morech.append(msvcrt.getch())
     except ImportError:
                 linelist = ['']
             lines2print = min(len(linelist), linesleft)
             for i in range(lines2print):
-                if os.name == 'nt' and len(line) == width:
+                if WINDOWS and len(line) == width:
                     # avoid extra blank line by skipping linefeed print
                     echo(linelist[i])
                 else:
 
 from distutils.core import setup
 
+def get_version(relpath):
+    """read version info from file without importing it"""
+    from os.path import dirname, join
+    for line in open(join(dirname(__file__), relpath)):
+        if '__version__' in line:
+            if '"' in line:
+                # __version__ = "0.9"
+                return line.split('"')[1]
+            elif "'" in line:
+                return line.split("'")[1]
+
 setup(
     name='pager',
-    version='1.2',
+    version=get_version('pager.py'),
     description='Terminal/console pager module for Python',
     long_description=open('README.rst').read(),
     py_modules=['pager'],
         'License :: Public Domain',
         'Operating System :: OS Independent',
         'Programming Language :: Python :: 2',
-        'Programming Language :: Python :: 3',
+        #'Programming Language :: Python :: 3',
     ],
 )