From 4e25d1c713b0c37feb6a8781a92b62a52ee5eb04 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 8 Sep 2018 01:30:56 +0200 Subject: menuconfig: Print warnings instead of having StyleError Mostly motivated by curses.COLORS, which depends on the terminal. It's probably friendlier to run even if the style gets a bit messed up, but it's also nice to point out problems. Missing style templates and missing styles to the left of '=' are pointed out now too, with the help of some flag hackery. Prefix the warnings with 'menuconfig warning:' to make it easier to distinguish them from warnings from Kconfiglib. --- menuconfig.py | 78 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 24 deletions(-) (limited to 'menuconfig.py') diff --git a/menuconfig.py b/menuconfig.py index 5a3d371..14958ee 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -83,9 +83,11 @@ The color definition is a comma separated list of attributes: - fg:COLOR Set the foreground/background colors. COLOR can be one of * or * the basic 16 colors (black, red, green, yellow, blue, - bg:COLOR magenta,cyan, white and brighter versions, for example, - brightred). On terminals that support 256 color mode, you - can also directly put in a color number, e.g. fg:123 + brightred). On terminals that support more than 8 colors, + you can also directly put in a color number, e.g. fg:123 (hexadecimal and octal constants are accepted as well). + Colors outside the range -1..curses.COLORS-1 (which is + terminal-dependent) are ignored (with a warning). If the background or foreground color of an element is not specified, it defaults to -1, representing the default @@ -105,8 +107,9 @@ For example, take the aquatic theme and give it a red selection bar: MENUCONFIG_STYLE="aquatic selection=fg:white,bg:red" -If there's an error in the style definition, a StyleError exception will be -thrown briefly describing the error. +If there's an error in the style definition or if a missing style is assigned +to, the assignment will be ignored, along with a warning being printed on +stderr. The 'default' theme is always implicitly parsed first (or the 'monochrome' theme if the terminal lacks colors), so the following two settings have the @@ -162,6 +165,7 @@ import locale import os import platform import re +import sys import textwrap from kconfiglib import Symbol, Choice, MENU, COMMENT, MenuNode, \ @@ -297,22 +301,37 @@ _STYLE_STD_COLORS = { _style = {} -class StyleError(Exception): - pass +def _parse_style(style_str, parsing_default): + # Parses a string with '=