dirtywords

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

commit
cf434528d41c42d276125461d074b6c3a8d525e1
parent
84d086f423c2aac2b7e46737412b5ca631db72fb
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-10-09 07:28
add Screen.getkey()

Diffstat

M dirtywords/base.py 25 +++++++++++++++++++++++++

1 files changed, 25 insertions, 0 deletions


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

@@ -18,6 +18,9 @@ implementation is chosen.
   18    18 
   19    19 
   20    20 from time import time
   -1    21 import string
   -1    22 
   -1    23 from constants import KEYS
   21    24 
   22    25 
   23    26 class AttrString(unicode):
@@ -205,6 +208,28 @@ class Screen(Core):
  205   208                     }
  206   209                 self._pressed_keys[ch] = (now, 2)
  207   210 
   -1   211     def getkey(self, blocking=True):
   -1   212         """Wrapper around :py:meth:`getch` that returns unicode if possible."""
   -1   213         ch = self.getch(blocking=blocking)
   -1   214 
   -1   215         if ch is not None:
   -1   216             if ch in KEYS.values():
   -1   217                 return ch
   -1   218 
   -1   219             elif 127 < ch < 256:  # interpret as utf8
   -1   220                 nbytes = bin(ch)[3:].find('0')
   -1   221                 l = [ch]
   -1   222                 for i in range(nbytes):
   -1   223                     l.append(self.getch())
   -1   224                 s = ''.join([chr(c) for c in l])
   -1   225                 return s.decode('utf8')
   -1   226 
   -1   227             elif ch < 256 and chr(ch) in string.printable:
   -1   228                 return unicode(chr(ch))
   -1   229 
   -1   230         if blocking:
   -1   231             return self.getkey(blocking=blocking)
   -1   232 
  208   233     def delch(self, y, x):
  209   234         """Delete character at position."""
  210   235         self.putstr(y, x, ' ')