ttytest.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import sys
  2. import select
  3. import tty
  4. import termios
  5. import os
  6. import readline
  7. addrs = ['a@a.com', 'digger@pansen.com']
  8. def mytool():
  9. print 'MT'
  10. def completer(text, state):
  11. options = [x for x in addrs if x.startswith(text)]
  12. try:
  13. return options[state]
  14. except IndexError:
  15. return None
  16. #readline.set_completer(completer)
  17. readline.parse_and_bind('tab:complete')
  18. while True:
  19. a = raw_input('$ ')
  20. print a
  21. """
  22. #print "#> ",
  23. os.system("stty cbreak -echo")
  24. cmdstring = ''
  25. while True:
  26. #print '---'
  27. a = sys.stdin.read(1)
  28. #sys.stdout.write(a)
  29. sys.stdout.write('\r')
  30. if a == '\n':
  31. #print 'ENTER'
  32. a = ''
  33. cmdstring = ''
  34. print 's'
  35. sys.stdout.write('\r')
  36. elif a == '\010':
  37. print 'ENTER'
  38. a = ''
  39. sys.stdout.write('\r')
  40. else:
  41. cmdstring = cmdstring + a
  42. sys.stdout.write('$ ' + cmdstring)
  43. sys.stdout.flush()
  44. os.system("stty -cbreak echo")
  45. """
  46. """
  47. fd = sys.stdin.fileno()
  48. old = termios.tcgetattr(fd)
  49. tty.setcbreak(fd)
  50. ch = sys.stdin.read(1)
  51. print "Read", ch
  52. termios.tcsetattr(fd, termios.TCSADRAIN, old)
  53. """