dirtywords

portable text interface framework  https://pypi.python.org/pypi/dirtywords
git clone https://git.ce9e.org/dirtywords.git

commit
b67025338a4806b8a28c3a8c7c884e08bcf04f1a
parent
219c8643116f0e528e66b2a149f734f98905ff62
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-10-09 07:27
map curses keys to our own

Diffstat

M dirtywords/curses_core.py 31 +++++++++++++++++++++++++++++--

1 files changed, 29 insertions, 2 deletions


diff --git a/dirtywords/curses_core.py b/dirtywords/curses_core.py

@@ -4,6 +4,9 @@ except ImportError:
    4     4     import curses
    5     5 
    6     6 import base
   -1     7 import locale
   -1     8 
   -1     9 from constants import KEYS
    7    10 
    8    11 
    9    12 class Screen(base.Screen):
@@ -25,6 +28,31 @@ class Screen(base.Screen):
   25    28         self.curses_window = curses.newwin(height, width, 0, 0)
   26    29         self.curses_window.keypad(1)
   27    30 
   -1    31     def _convert_ch(self, ch):
   -1    32         mapping = {
   -1    33             'Pause': curses.KEY_BREAK,
   -1    34             'Down': curses.KEY_DOWN,
   -1    35             'Up': curses.KEY_UP,
   -1    36             'Left': curses.KEY_LEFT,
   -1    37             'Right': curses.KEY_RIGHT,
   -1    38             'Home': curses.KEY_HOME,
   -1    39             'Backspace': curses.KEY_BACKSPACE,
   -1    40             'Delete': curses.KEY_DC,
   -1    41             'Insert': curses.KEY_IC,
   -1    42             'PageDown': curses.KEY_NPAGE,
   -1    43             'PageUp': curses.KEY_PPAGE,
   -1    44             'Return': 10,
   -1    45             'Print': curses.KEY_PRINT,
   -1    46             'End': curses.KEY_END,
   -1    47         }
   -1    48 
   -1    49         for key, curses_ch in mapping.iteritems():
   -1    50             if ch == curses_ch:
   -1    51                 return KEYS[key]
   -1    52 
   -1    53         if 0 <= ch < 256:
   -1    54             return ch
   -1    55 
   28    56     def getch(self, blocking=True):
   29    57         if blocking:
   30    58             self.curses_window.timeout(-1)
@@ -32,8 +60,7 @@ class Screen(base.Screen):
   32    60             self.curses_window.timeout(100)
   33    61 
   34    62         ch = self.curses_window.getch()
   35    -1         if ch != -1:
   36    -1             return ch
   -1    63         return self._convert_ch(ch)
   37    64 
   38    65     def _get_color(self, color):
   39    66         r, g, b = color