colortest.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  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 (
  19. ('pre-init', None),
  20. ('auto', 'auto'),
  21. ('8-color', 8),
  22. ('256-color', 256),
  23. ('disabled', 0)):
  24. if nc is not None:
  25. init_color(num_colors=nc)
  26. msg('{:9}: {}'.format(
  27. desc,
  28. ' '.join(getattr(color_mod, c)(c) for c in sorted(color_mod._colors))))
  29. init_color()
  30. gmsg("\nParsed terminfo 'colors' values:")
  31. from mmgen.color import orange
  32. for t, c in (
  33. ('rxvt', 8),
  34. ('xterm', 8),
  35. ('rxvt-unicode', 88),
  36. ('screen-256color', 256),
  37. ('xterm-256color', 256)):
  38. ret = get_terminfo_colors(t)
  39. if ret is None:
  40. ymsg(f'Warning: unable to get info for terminal {t!r}')
  41. continue
  42. msg(f'{t}: {orange(str(ret))}')
  43. assert c == ret, f"'colors' value for terminal {t} ({ret}) does not match expected value of {c}"
  44. ret = get_terminfo_colors()
  45. msg(f'{os.getenv("TERM")} (this terminal): {orange(str(ret))}')
  46. if __name__ == '__main__':
  47. test_color()