Guest User

Untitled

a guest
Oct 18th, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # just a dirty unbuffered getch()
  4. import sys, tty, termios
  5. def raw_getch():
  6.     setbak = termios.tcgetattr(sys.stdin.fileno())
  7.     try:
  8.         tty.setraw(sys.stdin.fileno())
  9.         ch = sys.stdin.read(1)
  10.     finally:
  11.         termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, setbak)
  12.     return ch
  13.  
  14. # binary keyboard, use u and d keys to select the line
  15. def bin_select(chars):
  16.     while len(chars) > 1:
  17.         upper = chars[0:len(chars)/2]
  18.         lower = chars[len(chars)/2:len(chars)]
  19.         print ''.join(upper)
  20.         print ''.join(lower)
  21.  
  22.         inp = raw_getch()
  23.         if inp == 'u':
  24.             chars = upper
  25.         elif inp == 'd':
  26.             chars = lower
  27.  
  28.     return chars[0]
  29.  
  30. if __name__ == '__main__':
  31.     chars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
  32.              'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1',
  33.              '2', '3', '4', '5', '6', '7', '8', '9', '.', ',', '-', '_']
  34.     print bin_select(chars)
Advertisement
Add Comment
Please, Sign In to add comment