colortest.py 1.3 KB

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