curses_tests.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. #
  3. # $Id: ncurses.py 36559 2004-07-18 05:56:09Z tim_one $
  4. #
  5. # Interactive test suite for the curses module.
  6. # This script displays various things and the user should verify whether
  7. # they display correctly.
  8. #
  9. import curses
  10. from curses import textpad
  11. def test_textpad(stdscr, insert_mode=False):
  12. ncols, nlines = 8, 3
  13. uly, ulx = 3, 2
  14. if insert_mode:
  15. mode = 'insert mode'
  16. else:
  17. mode = 'overwrite mode'
  18. stdscr.addstr(uly-3, ulx, "Use Ctrl-G to end editing (%s)." % mode)
  19. stdscr.addstr(uly-2, ulx, "Be sure to try typing in the lower-right corner.")
  20. win = curses.newwin(nlines, ncols, uly, ulx)
  21. textpad.rectangle(stdscr, uly-1, ulx-1, uly + nlines, ulx + ncols)
  22. stdscr.refresh()
  23. box = textpad.Textbox(win, insert_mode)
  24. contents = box.edit()
  25. stdscr.addstr(uly+ncols+2, 0, "Text entered in the box\n")
  26. stdscr.addstr(repr(contents))
  27. stdscr.addstr('\n')
  28. stdscr.addstr('Press any key')
  29. stdscr.getch()
  30. for i in range(3):
  31. stdscr.move(uly+ncols+2 + i, 0)
  32. stdscr.clrtoeol()
  33. def main(stdscr):
  34. stdscr.clear()
  35. test_textpad(stdscr, False)
  36. test_textpad(stdscr, True)
  37. if __name__ == '__main__':
  38. curses.wrapper(main)