mmgen.color: minor cleanups, define color names statically

This commit is contained in:
The MMGen Project 2023-10-18 12:11:49 +00:00
commit 8190e8eb0c
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 34 additions and 7 deletions

View file

@ -28,18 +28,20 @@ _colors = {
'blue': ( 75, (34,1) ),
'magenta': ( 205, (35,1) ),
'cyan': ( 122, (36,1) ),
'pink': ( 218, (35,1) ),
'orange': ( 216, (31,1) ),
'gray': ( 246, (30,1) ),
'orange': ( 216, (31,1) ),
'purple': ( 141, (35,1) ),
'pink': ( 218, (35,1) ),
'melon': ( 222, (33,1) ),
'brown': ( 173, (33,0) ),
'grndim': ( 108, (32,0) ),
'redbg': ( (232,210), (30,101) ),
'grnbg': ( (232,121), (30,102) ),
'blubg': ( (232,75), (30,104) ),
'yelbg': ( (232,229), (30,103) ),
'blubg': ( (232,75), (30,104) ),
}
def nocolor(s):
@ -77,7 +79,8 @@ def get_terminfo_colors(term=None):
def init_color(num_colors='auto'):
assert num_colors in ('auto',8,16,256,0)
import mmgen.color as self
import sys
self = sys.modules[__name__]
if num_colors == 'auto':
import os
@ -104,5 +107,30 @@ def init_color(num_colors='auto'):
set_vt100()
for _c in _colors:
exec(f'{_c} = lambda s: s')
# Each color name must be bound to an independent stub function with its own
# address in memory. The names themselves must never be redefined, since other
# modules could import them before init_color() is run. Instead, the code
# objects of their associated functions are manipulated by init_color() to
# enable/disable color.
black = lambda s: s
red = lambda s: s
green = lambda s: s
yellow = lambda s: s
blue = lambda s: s
magenta = lambda s: s
cyan = lambda s: s
gray = lambda s: s
orange = lambda s: s
purple = lambda s: s
pink = lambda s: s
melon = lambda s: s
brown = lambda s: s
grndim = lambda s: s
redbg = lambda s: s
grnbg = lambda s: s
yelbg = lambda s: s
blubg = lambda s: s

View file

@ -24,7 +24,6 @@ ignore = [
]
ignored-modules = [ # ignored for no-member, otherwise checked
"mmgen.proto.secp256k1.secp256k1",
"mmgen.color",
"mmgen.term",
"msvcrt",
"gmpy2",