dirtywords

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

commit
5125f78e73ec5566852061d1c959e46e4597b6cb
parent
4c186b3ea87fc78727cf166dca45fc72a8049815
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-10-07 18:42
move get_key_events from Core to Screen

Diffstat

M dirtywords/base.py 47 +++++++++++++++++++++++++----------------------

1 files changed, 25 insertions, 22 deletions


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

@@ -69,7 +69,6 @@ class Core(object):
   69    69         self.height = height
   70    70         self.width = width
   71    71         self.data = [[' ' for xx in range(width)] for yy in range(height)]
   72    -1         self._pressed_keys = {}
   73    72 
   74    73     def getch(self, blocking=True):
   75    74         """Get a character from ``stdin``."""
@@ -77,6 +76,31 @@ class Core(object):
   77    76         # more general any non-ascii keys.
   78    77         raise NotImplementedError
   79    78 
   -1    79     def putstr(self, y, x, s):
   -1    80         """Write string to position."""
   -1    81         # TODO: handle newlines
   -1    82         for i, ch in enumerate(s):
   -1    83             try:
   -1    84                 self.data[y][x + i] = ch
   -1    85             except IndexError:
   -1    86                 pass
   -1    87 
   -1    88     def refresh(self):
   -1    89         """Print the current state to the screen."""
   -1    90         raise NotImplementedError
   -1    91 
   -1    92     def cleanup(self):
   -1    93         """Deinitialize screen."""
   -1    94         pass
   -1    95 
   -1    96 
   -1    97 class Screen(Core):
   -1    98     """Additional utility functions for :py:class:`Core`."""
   -1    99 
   -1   100     def __init__(self, height, width):
   -1   101         super(Screen, self).__init__(height, width)
   -1   102         self._pressed_keys = {}
   -1   103 
   80   104     def get_key_events(self):
   81   105         """Get iterator of keyup/-down events.
   82   106 
@@ -152,27 +176,6 @@ class Core(object):
  152   176                     }
  153   177                 self._pressed_keys[ch] = (now, 2)
  154   178 
  155    -1     def putstr(self, y, x, s):
  156    -1         """Write string to position."""
  157    -1         # TODO: handle newlines
  158    -1         for i, ch in enumerate(s):
  159    -1             try:
  160    -1                 self.data[y][x + i] = ch
  161    -1             except IndexError:
  162    -1                 pass
  163    -1 
  164    -1     def refresh(self):
  165    -1         """Print the current state to the screen."""
  166    -1         raise NotImplementedError
  167    -1 
  168    -1     def cleanup(self):
  169    -1         """Deinitialize screen."""
  170    -1         pass
  171    -1 
  172    -1 
  173    -1 class Screen(Core):
  174    -1     """Additional utility functions for :py:class:`Core`."""
  175    -1 
  176   179     def delch(self, y, x):
  177   180         """Delete character at position."""
  178   181         self.putstr(y, x, ' ')