dirtywords

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

commit
3014a4e2a60fa230037f09349ce4693a54686533
parent
b7a3d7f1636b15303ad6975411b6c1f80d7492a2
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-08-03 11:15
Gardening

Diffstat

M dirtywords/base.py 6 +++---
M dirtywords/curses.py 2 +-
M dirtywords/stupid.py 30 +++++++++++++++---------------
M example.py 2 +-

4 files changed, 20 insertions, 20 deletions


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

@@ -224,10 +224,10 @@ class Screen(Core):
  224   224 
  225   225             elif 127 < ch < 256:  # interpret as utf8
  226   226                 nbytes = bin(ch)[3:].find('0')
  227    -1                 l = [ch]
   -1   227                 chars = [ch]
  228   228                 for i in range(nbytes):
  229    -1                     l.append(self.getch())
  230    -1                 s = ''.join([chr(c) for c in l])
   -1   229                     chars.append(self.getch())
   -1   230                 s = ''.join([chr(c) for c in chars])
  231   231                 return s.decode('utf8')
  232   232 
  233   233             elif ch < 256 and chr(ch) in string.printable:

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

@@ -93,7 +93,7 @@ class Screen(base.Screen):
   93    93 
   94    94             try:
   95    95                 self.curses_window.addstr(y, x + i, ch.encode('utf8'))
   96    -1             except:
   -1    96             except Exception:
   97    97                 pass
   98    98 
   99    99             self.curses_window.attroff(curses.A_BOLD)

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

@@ -73,28 +73,28 @@ class Screen(base.Screen):
   73    73         # Convert ANSI escape sequences to key constants
   74    74         # This is implemented as a wrapper around :py:meth:`_getch` because
   75    75         # it needs to get a variable number of bytes from stdin.
   76    -1         l = [self._getch(blocking=blocking)]
   -1    76         chars = [self._getch(blocking=blocking)]
   77    77 
   78    -1         if l == [27]:
   -1    78         if chars == [27]:
   79    79             # TODO: single ESC is valid, so this should not block
   80    -1             l.append(self._getch())
   81    -1         elif l == [155]:
   82    -1             l = [27, 91]
   83    -1 
   84    -1         if l[0] == 27:
   85    -1             if l[1] == 91:
   86    -1                 l.append(self._getch())
   87    -1                 while l[-1] not in range(64, 127):
   88    -1                     l.append(self._getch())
   89    -1             elif l[1] == 79:
   90    -1                 l.append(self._getch())
   91    -1             elif l[-1] in range(64, 96):
   -1    80             chars.append(self._getch())
   -1    81         elif chars == [155]:
   -1    82             chars = [27, 91]
   -1    83 
   -1    84         if chars[0] == 27:
   -1    85             if chars[1] == 91:
   -1    86                 chars.append(self._getch())
   -1    87                 while chars[-1] not in range(64, 127):
   -1    88                     chars.append(self._getch())
   -1    89             elif chars[1] == 79:
   -1    90                 chars.append(self._getch())
   -1    91             elif chars[-1] in range(64, 96):
   92    92                 pass
   93    93             else:
   94    94                 # invalid?
   95    95                 pass
   96    96 
   97    -1         return self._codes2key(l)
   -1    97         return self._codes2key(chars)
   98    98 
   99    99     def refresh(self):
  100   100         spacing = '\n' * self.height * 2

diff --git a/example.py b/example.py

@@ -56,6 +56,6 @@ if __name__ == '__main__':
   56    56                 elif event['type'] == 'keyup':
   57    57                     player.direction = 'stop'
   58    58             player.move()
   59    -1     except:
   -1    59     except Exception:
   60    60         scr.cleanup()
   61    61         raise