colortest.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. ('xterm', 8),
  34. ('rxvt', 8),
  35. ('rxvt-88color', 88),
  36. ('rxvt-256color', 256),
  37. ('screen-256color', 256),
  38. ('xterm-256color', 256)):
  39. ret = get_terminfo_colors(t)
  40. if ret is None:
  41. ymsg(f'Warning: unable to get info for terminal {t!r}')
  42. continue
  43. msg(f'{t}: {orange(str(ret))}')
  44. assert c == ret, f"'colors' value for terminal {t} ({ret}) does not match expected value of {c}"
  45. ret = get_terminfo_colors()
  46. msg(f'{os.getenv("TERM")} (this terminal): {orange(str(ret))}')
  47. if __name__ == '__main__':
  48. test_color()