From 8190e8eb0ce6b2583f264dd8cff08673e3977286 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 18 Oct 2023 12:11:49 +0000 Subject: [PATCH] mmgen.color: minor cleanups, define color names statically --- mmgen/color.py | 40 ++++++++++++++++++++++++++++++++++------ pyproject.toml | 1 - 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/mmgen/color.py b/mmgen/color.py index b2ead538..19fe85d2 100755 --- a/mmgen/color.py +++ b/mmgen/color.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 74edd1ab..57273cb4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,6 @@ ignore = [ ] ignored-modules = [ # ignored for no-member, otherwise checked "mmgen.proto.secp256k1.secp256k1", - "mmgen.color", "mmgen.term", "msvcrt", "gmpy2",