Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from blessed import Terminal
  4.  
  5. menu = [["login to system"], ["create account"], ["disconnect"]]
  6.  
  7.  
  8. def display_screen(selection):
  9. term = Terminal()
  10. print term.clear()
  11.  
  12. for (idx, m) in enumerate(menu):
  13. if idx == selection:
  14. print('{t.bold_red_reverse}{title}'.format(t=term, title=m[0]))
  15. else:
  16. print('{t.normal}{title}'.format(t=term, title=m[0]))
  17.  
  18.  
  19. def run_selection(selection):
  20. print term.green_reverse('Running {}'.format(menu[selection][0]))
  21.  
  22.  
  23. if __name__ == '__main__':
  24. term = Terminal()
  25. with term.fullscreen():
  26. selection = 0
  27. display_screen(selection)
  28. selection_inprogress = True
  29. with term.cbreak():
  30. while selection_inprogress:
  31. key = term.inkey()
  32. if key.is_sequence:
  33. if key.name == 'KEY_TAB':
  34. selection += 1
  35. if key.name == 'KEY_DOWN':
  36. selection += 1
  37. if key.name == 'KEY_UP':
  38. selection -= 1
  39. if key.name == 'KEY_ENTER':
  40. selection_inprogress = False
  41. elif key:
  42. print("got {0}.".format(key))
  43.  
  44. selection = selection % len(menu)
  45.  
  46. display_screen(selection)
  47.  
  48. run_selection(selection)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement