colortest.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2021 The MMGen Project <mmgen@tuta.io>
  5. """
  6. colortest.py: test color handling for the MMGen suite
  7. """
  8. import include.tests_header
  9. from include.common import *
  10. from mmgen.color import *
  11. from mmgen.color import _colors
  12. def test_color():
  13. init_color()
  14. gmsg("Parsed terminfo 'colors' values:")
  15. for t,c in (('rxvt',8),('xterm',8),('rxvt-unicode',88),('screen-256color',256),('xterm-256color',256)):
  16. ret = get_terminfo_colors(t)
  17. if ret == None:
  18. set_vt100()
  19. ymsg(f'Warning: unable to get info for terminal {t!r}')
  20. continue
  21. msg(f'{t}: {ret}')
  22. assert c == ret, f"'colors' value for terminal {t} ({ret}) does not match expected value of {c}"
  23. ret = get_terminfo_colors()
  24. msg(f'This terminal ({os.getenv("TERM")}): {ret}')
  25. set_vt100()
  26. gmsg("Terminal display:")
  27. for desc,n in (('auto','auto'),('8-color',8),('256-color',256),('off',0)):
  28. init_color(num_colors=n)
  29. msg('{:9}: {}'.format(
  30. desc,
  31. ' '.join(globals()[c](c) for c in sorted(_colors)) ))
  32. test_color()