diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-10-10 13:45:42 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-10-10 14:38:49 +0200 |
| commit | a247f3f5815f42e8f1b616e311d38f41587cef64 (patch) | |
| tree | 8889ea5bd8e40bc9b292e34eaef2670447633340 | |
| parent | aa5b9e710e04a67e689af0bcc61c27f9f052c035 (diff) | |
menuconfig: Improve/fix promptless choice handling
The code assumed that all parent (interface) menus always have a prompt,
which is false for items in promptless choices. This lead to a crash
e.g. when viewing the symbol information for a symbol within a
promptless choice.
Promptless choices with children can show up "legitimately" when people
define choices in multiple locations to add symbols, though this is
broken in the C tools.
Use standard_sc_expr_str(node.item) instead of the non-existing prompt
for promptless choices. That way they show up as
<choice (name if any>)>, which is consistent with how they're shown
elsewhere.
This commit also changes how choices names are displayed in
show-name/show-all mode, to the standard_sc_expr_str() format.
| -rwxr-xr-x | menuconfig.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/menuconfig.py b/menuconfig.py index 14edb83..d5cac8f 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -1190,7 +1190,11 @@ def _draw_main(): menu = _cur_menu while menu is not _kconf.top_node: - menu_prompts.append(menu.prompt[0]) + # Promptless choices can be entered in show-all mode. Use + # standard_sc_expr_str() for them, so they show up as + # <choice (name if any)>. + menu_prompts.append(menu.prompt[0] if menu.prompt else + standard_sc_expr_str(menu.item)) menu = _parent_menu(menu) menu_prompts.append("(top menu)") menu_prompts.reverse() @@ -2489,7 +2493,11 @@ def _menu_path_info(node): node = _parent_menu(node) while node is not _kconf.top_node: - path = " -> " + node.prompt[0] + path + # Promptless choices might appear among the parents. Use + # standard_sc_expr_str() for them, so that they show up as + # <choice (name if any)>. + path = " -> " + (node.prompt[0] if node.prompt else + standard_sc_expr_str(node.item)) + path node = _parent_menu(node) return "(top menu)" + path @@ -2645,13 +2653,13 @@ def _node_str(node): # This approach gives nice alignment for empty string symbols ("() Foo") s = "{:{}}".format(_value_str(node), 3 + indent) - # 'not node.prompt' can only be True in show-all mode - if not node.prompt or \ - (_show_name and - (isinstance(node.item, Symbol) or - (isinstance(node.item, Choice) and node.item.name))): - - s += " <{}>".format(node.item.name) + if _should_show_name(node): + if isinstance(node.item, Symbol): + s += " <{}>".format(node.item.name) + else: + # For choices, use standard_sc_expr_str(). That way they show up as + # <choice (name if any)>. + s += " " + standard_sc_expr_str(node.item) if node.prompt: s += " " @@ -2687,6 +2695,15 @@ def _node_str(node): return s +def _should_show_name(node): + # Returns True if 'node' is a symbol or choice whose name should shown (if + # any, as names are optional for choices) + + # The 'not node.prompt' case only hits in show-all mode, for promptless + # symbols and choices + return not node.prompt or \ + (_show_name and isinstance(node.item, (Symbol, Choice))) + def _value_str(node): # Returns the value part ("[*]", "<M>", "(foo)" etc.) of a menu node |
