term_ni.py 776 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. import sys, os
  3. os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(sys.argv[0])))))
  4. sys.path[0] = os.curdir
  5. from mmgen.cfg import Config
  6. cfg = Config()
  7. from mmgen.util import msg
  8. from mmgen.term import init_term, get_term
  9. init_term(cfg)
  10. term = get_term()
  11. if sys.argv[1] == 'echo':
  12. from mmgen.ui import line_input
  13. from mmgen.term import get_char_raw
  14. def test_noecho():
  15. term.init(noecho=True)
  16. ret = line_input(cfg, 'noecho> ')
  17. msg(f'==> [{ret.upper()}]')
  18. get_char_raw()
  19. def test_echo():
  20. term.set('echo')
  21. ret = line_input(cfg, 'echo> ')
  22. msg(f'==> [{ret.upper()}]')
  23. test_noecho()
  24. test_echo()
  25. test_noecho()
  26. elif sys.argv[1] == 'cleanup':
  27. term.register_cleanup()
  28. import tty
  29. tty.setcbreak(term.stdin_fd)