Make an empty evmenu desc option just show the key

This commit is contained in:
Griatch 2017-10-28 14:31:09 +02:00
parent 931e42082c
commit b6b112b70a

View file

@ -733,15 +733,14 @@ class EvMenu(object):
for inum, dic in enumerate(options): for inum, dic in enumerate(options):
# fix up the option dicts # fix up the option dicts
keys = make_iter(dic.get("key")) keys = make_iter(dic.get("key"))
desc = dic.get("desc", dic.get("text", None))
if "_default" in keys: if "_default" in keys:
keys = [key for key in keys if key != "_default"] keys = [key for key in keys if key != "_default"]
desc = dic.get("desc", dic.get("text", _ERR_NO_OPTION_DESC).strip())
goto, goto_kwargs, execute, exec_kwargs = _extract_goto_exec(dic) goto, goto_kwargs, execute, exec_kwargs = _extract_goto_exec(dic)
self.default = (goto, goto_kwargs, execute, exec_kwargs) self.default = (goto, goto_kwargs, execute, exec_kwargs)
else: else:
# use the key (only) if set, otherwise use the running number # use the key (only) if set, otherwise use the running number
keys = list(make_iter(dic.get("key", str(inum + 1).strip()))) keys = list(make_iter(dic.get("key", str(inum + 1).strip())))
desc = dic.get("desc", dic.get("text", _ERR_NO_OPTION_DESC).strip())
goto, goto_kwargs, execute, exec_kwargs = _extract_goto_exec(dic) goto, goto_kwargs, execute, exec_kwargs = _extract_goto_exec(dic)
if keys: if keys:
display_options.append((keys[0], desc)) display_options.append((keys[0], desc))
@ -887,16 +886,17 @@ class EvMenu(object):
for key, desc in optionlist: for key, desc in optionlist:
if not (key or desc): if not (key or desc):
continue continue
desc_string = ": %s" % desc if desc else ""
table_width_max = max(table_width_max, table_width_max = max(table_width_max,
max(m_len(p) for p in key.split("\n")) + max(m_len(p) for p in key.split("\n")) +
max(m_len(p) for p in desc.split("\n")) + colsep) max(m_len(p) for p in desc_string.split("\n")) + colsep)
raw_key = strip_ansi(key) raw_key = strip_ansi(key)
if raw_key != key: if raw_key != key:
# already decorations in key definition # already decorations in key definition
table.append(" |lc%s|lt%s|le: %s" % (raw_key, key, desc)) table.append(" |lc%s|lt%s|le%s" % (raw_key, key, desc_string))
else: else:
# add a default white color to key # add a default white color to key
table.append(" |lc%s|lt|w%s|n|le: %s" % (raw_key, raw_key, desc)) table.append(" |lc%s|lt|w%s|n|le%s" % (raw_key, raw_key, desc_string))
ncols = (_MAX_TEXT_WIDTH // table_width_max) + 1 # number of ncols ncols = (_MAX_TEXT_WIDTH // table_width_max) + 1 # number of ncols
@ -1151,7 +1151,6 @@ def test_set_node(caller):
""") """)
options = {"key": ("back (default)", "_default"), options = {"key": ("back (default)", "_default"),
"desc": "back to main",
"goto": "test_start_node"} "goto": "test_start_node"}
return text, options return text, options