colortest.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
  5. """
  6. test/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. import mmgen.color as color_mod
  12. def test_color():
  13. ymsg("Terminal display:") # init_color() not called yet, so no yellow here
  14. for desc,nc in (('pre-init',None),('auto','auto'),('8-color',8),('256-color',256),('disabled',0)):
  15. if nc != None:
  16. init_color(num_colors=nc)
  17. msg('{:9}: {}'.format(
  18. desc,
  19. ' '.join( getattr(color_mod,c)(c) for c in sorted(color_mod._colors) ) ))
  20. init_color()
  21. gmsg("\nParsed terminfo 'colors' values:")
  22. for t,c in (('rxvt',8),('xterm',8),('rxvt-unicode',88),('screen-256color',256),('xterm-256color',256)):
  23. ret = get_terminfo_colors(t)
  24. if ret == None:
  25. ymsg(f'Warning: unable to get info for terminal {t!r}')
  26. continue
  27. msg(f'{t}: {orange(str(ret))}')
  28. assert c == ret, f"'colors' value for terminal {t} ({ret}) does not match expected value of {c}"
  29. ret = get_terminfo_colors()
  30. msg(f'{os.getenv("TERM")} (this terminal): {orange(str(ret))}')
  31. test_color()