colortest.py 1.0 KB

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