summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-04-24 21:13:31 +0200
committermathieui <mathieui@mathieui.net>2014-04-24 21:13:31 +0200
commit5012611bd72bc74cef2a4870b9056df406b5dccb (patch)
tree5e681495ff50b85b421cf293158fc768d33521ec
parent4de2dfc72ba6ea451c9dba8b938a861b4f065a35 (diff)
downloadpoezio-5012611bd72bc74cef2a4870b9056df406b5dccb.tar.gz
poezio-5012611bd72bc74cef2a4870b9056df406b5dccb.tar.bz2
poezio-5012611bd72bc74cef2a4870b9056df406b5dccb.tar.xz
poezio-5012611bd72bc74cef2a4870b9056df406b5dccb.zip
Make keyboard.py a bit nicer to use
-rwxr-xr-xsrc/keyboard.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/keyboard.py b/src/keyboard.py
index 94eba47f..0a1391ea 100755
--- a/src/keyboard.py
+++ b/src/keyboard.py
@@ -179,13 +179,36 @@ class Keyboard(object):
return ret_list
if __name__ == '__main__':
+ import sys
keyboard = Keyboard()
s = curses.initscr()
curses.noecho()
curses.cbreak()
s.keypad(1)
+ curses.start_color()
+ curses.use_default_colors()
+ curses.init_pair(1, 2, -1)
+ s.attron(curses.A_BOLD | curses.color_pair(1))
+ s.addstr('Type Ctrl-c to close\n')
+ s.attroff(curses.A_BOLD | curses.color_pair(1))
+ pressed_chars = []
while True:
- chars = keyboard.get_user_input(s)
- for char in chars if chars else '':
- s.addstr('%s ' % (char))
+
+ try:
+ chars = keyboard.get_user_input(s)
+ for char in chars if chars else '':
+ s.addstr('%s ' % (char))
+ pressed_chars.append(chars)
+
+ except KeyboardInterrupt:
+ break
+ curses.echo()
+ curses.cbreak()
+ curses.curs_set(1)
+ curses.endwin()
+ for char_list in pressed_chars:
+ if char_list:
+ print(' '.join((char for char in char_list)), end=' ')
+ print()
+ sys.exit(0)