2019-10-23 10:44:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
#
|
2024-10-18 10:32:06 +00:00
|
|
|
# MMGen Wallet, a terminal-based cryptocurrency wallet
|
2026-02-11 13:02:12 +00:00
|
|
|
# Copyright (C)2013-2026 The MMGen Project <mmgen@tuta.io>
|
2019-10-23 10:44:17 +00:00
|
|
|
|
|
|
|
|
"""
|
2022-11-14 09:54:07 +00:00
|
|
|
test/colortest.py: test color handling for the MMGen suite
|
2019-10-23 10:44:17 +00:00
|
|
|
"""
|
|
|
|
|
|
2023-10-03 14:27:57 +00:00
|
|
|
import os
|
|
|
|
|
|
2023-10-13 09:51:14 +00:00
|
|
|
try:
|
|
|
|
|
from include import test_init
|
|
|
|
|
except ImportError:
|
|
|
|
|
from test.include import test_init
|
2023-10-03 14:27:57 +00:00
|
|
|
|
2019-10-23 10:44:17 +00:00
|
|
|
from mmgen.color import *
|
2024-10-18 10:32:12 +00:00
|
|
|
from mmgen.util import msg, ymsg, gmsg
|
2022-02-03 20:40:40 +00:00
|
|
|
import mmgen.color as color_mod
|
2019-10-23 10:44:17 +00:00
|
|
|
|
|
|
|
|
def test_color():
|
|
|
|
|
|
2022-01-27 11:08:05 +00:00
|
|
|
ymsg("Terminal display:") # init_color() not called yet, so no yellow here
|
|
|
|
|
|
2024-10-18 10:32:12 +00:00
|
|
|
for desc, nc in (
|
|
|
|
|
('pre-init', None),
|
|
|
|
|
('auto', 'auto'),
|
|
|
|
|
('8-color', 8),
|
|
|
|
|
('256-color', 256),
|
|
|
|
|
('disabled', 0)):
|
2023-10-11 12:58:52 +00:00
|
|
|
if nc is not None:
|
2022-01-27 11:08:05 +00:00
|
|
|
init_color(num_colors=nc)
|
|
|
|
|
msg('{:9}: {}'.format(
|
|
|
|
|
desc,
|
2024-10-18 10:32:12 +00:00
|
|
|
' '.join(getattr(color_mod, c)(c) for c in sorted(color_mod._colors))))
|
2022-01-27 11:08:05 +00:00
|
|
|
|
2021-07-26 18:26:21 +00:00
|
|
|
init_color()
|
2022-01-27 11:08:05 +00:00
|
|
|
gmsg("\nParsed terminfo 'colors' values:")
|
2019-10-23 10:44:17 +00:00
|
|
|
|
2023-10-13 09:51:13 +00:00
|
|
|
from mmgen.color import orange
|
2024-10-18 10:32:12 +00:00
|
|
|
for t, c in (
|
|
|
|
|
('xterm', 8),
|
2024-12-30 11:31:39 +00:00
|
|
|
('rxvt', 8),
|
|
|
|
|
('rxvt-88color', 88),
|
|
|
|
|
('rxvt-256color', 256),
|
2024-10-18 10:32:12 +00:00
|
|
|
('screen-256color', 256),
|
|
|
|
|
('xterm-256color', 256)):
|
2019-10-23 10:44:17 +00:00
|
|
|
ret = get_terminfo_colors(t)
|
2023-10-11 12:58:52 +00:00
|
|
|
if ret is None:
|
2021-09-29 21:17:57 +00:00
|
|
|
ymsg(f'Warning: unable to get info for terminal {t!r}')
|
2019-11-15 10:46:16 +00:00
|
|
|
continue
|
2022-01-27 11:08:05 +00:00
|
|
|
msg(f'{t}: {orange(str(ret))}')
|
2021-09-29 21:17:57 +00:00
|
|
|
assert c == ret, f"'colors' value for terminal {t} ({ret}) does not match expected value of {c}"
|
2019-10-23 10:44:17 +00:00
|
|
|
|
|
|
|
|
ret = get_terminfo_colors()
|
2022-01-27 11:08:05 +00:00
|
|
|
msg(f'{os.getenv("TERM")} (this terminal): {orange(str(ret))}')
|
2019-10-23 10:44:17 +00:00
|
|
|
|
2023-10-13 09:51:14 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
test_color()
|