From 7a98bc7944f1b390e5a82e40c62d0ce7540befdc Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 23 Nov 2019 19:15:17 +0100 Subject: menuconfig: Check that bright named colors are < curses.COLORS The bright colors in the range 8-15 are not ANSI and are not guaranteed to be available. Previously, the code assumed that all named colors are always available on color terminals, and skipped the check against curses.COLORS. This led to this error e.g. with TERM=xterm (as opposed to xterm-256color) and the aquatic theme, which uses 'brightwhite': _curses.error: init_pair() returned ERR Fix it by checking the number returned for named colors against curses.COLORS as well. Came up in https://github.com/espressif/esp-idf/issues/4387. --- menuconfig.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/menuconfig.py b/menuconfig.py index 1f2e9fa..7b1dbce 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -550,9 +550,6 @@ def _style_to_curses(style_def): def parse_color(color_def): color_def = color_def.split(":", 1)[1] - if color_def in _STYLE_STD_COLORS: - return _color_from_num(_STYLE_STD_COLORS[color_def]) - # HTML format, #RRGGBB if re.match("#[A-Fa-f0-9]{6}", color_def): return _color_from_rgb(( @@ -560,19 +557,20 @@ def _style_to_curses(style_def): int(color_def[3:5], 16), int(color_def[5:7], 16))) - try: - color_num = _color_from_num(int(color_def, 0)) - except ValueError: - _warn("Ignoring color ", color_def, "that's neither predefined " - "nor a number") - - return -1 + if color_def in _STYLE_STD_COLORS: + color_num = _color_from_num(_STYLE_STD_COLORS[color_def]) + else: + try: + color_num = _color_from_num(int(color_def, 0)) + except ValueError: + _warn("Ignoring color", color_def, "that's neither " + "predefined nor a number") + return -1 if not -1 <= color_num < curses.COLORS: _warn("Ignoring color {}, which is outside the range " "-1..curses.COLORS-1 (-1..{})" .format(color_def, curses.COLORS - 1)) - return -1 return color_num -- cgit v1.2.3