colortest.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.test_init
  9. from include.common import *
  10. from mmgen.color import *
  11. from mmgen.util import msg,ymsg,gmsg
  12. import mmgen.color as color_mod
  13. def test_color():
  14. ymsg("Terminal display:") # init_color() not called yet, so no yellow here
  15. for desc,nc in (('pre-init',None),('auto','auto'),('8-color',8),('256-color',256),('disabled',0)):
  16. if nc != None:
  17. init_color(num_colors=nc)
  18. msg('{:9}: {}'.format(
  19. desc,
  20. ' '.join( getattr(color_mod,c)(c) for c in sorted(color_mod._colors) ) ))
  21. init_color()
  22. gmsg("\nParsed terminfo 'colors' values:")
  23. for t,c in (('rxvt',8),('xterm',8),('rxvt-unicode',88),('screen-256color',256),('xterm-256color',256)):
  24. ret = get_terminfo_colors(t)
  25. if ret == None:
  26. ymsg(f'Warning: unable to get info for terminal {t!r}')
  27. continue
  28. msg(f'{t}: {orange(str(ret))}')
  29. assert c == ret, f"'colors' value for terminal {t} ({ret}) does not match expected value of {c}"
  30. ret = get_terminfo_colors()
  31. msg(f'{os.getenv("TERM")} (this terminal): {orange(str(ret))}')
  32. test_color()