Resolved an outstanding bug in _format_display.

This commit is contained in:
Griatch 2015-10-18 11:52:16 +02:00
parent 36337f9853
commit 940eb02064

View file

@ -199,7 +199,7 @@ class CmdEvMenuNode(Command):
caller.msg(err) caller.msg(err)
raise EvMenuError(err) raise EvMenuError(err)
menu.handle(self.raw_string) menu.parse_input(self.raw_string)
class EvMenuCmdSet(CmdSet): class EvMenuCmdSet(CmdSet):
@ -388,6 +388,7 @@ class EvMenu(object):
nodetext = self._nodetext_formatter(nodetext, len(optionlist)) nodetext = self._nodetext_formatter(nodetext, len(optionlist))
else: else:
nodetext = dedent(nodetext).strip() nodetext = dedent(nodetext).strip()
nodetext_width_max = max(m_len(line) for line in nodetext.split("\n")) nodetext_width_max = max(m_len(line) for line in nodetext.split("\n"))
# #
@ -397,7 +398,7 @@ class EvMenu(object):
if self._options_formatter: if self._options_formatter:
# use custom formatter # use custom formatter
optionstext = self._options_formatter(optionlist) optionstext = self._options_formatter(optionlist)
else: elif optionlist:
# column separation distance # column separation distance
colsep = 4 colsep = 4
@ -438,14 +439,16 @@ class EvMenu(object):
table = [table[icol*nrows:(icol*nrows) + nrows] for icol in xrange(0, ncols)] table = [table[icol*nrows:(icol*nrows) + nrows] for icol in xrange(0, ncols)]
# adjust the width of each column # adjust the width of each column
options_total_width = 0
for icol in xrange(len(table)): for icol in xrange(len(table)):
col_width = max(max(m_len(p) for p in part.split("\n")) for part in table[icol]) + colsep col_width = max(max(m_len(p) for p in part.split("\n")) for part in table[icol]) + colsep
table[icol] = [pad(part, width=col_width + colsep, align="l") for part in table[icol]] table[icol] = [pad(part, width=col_width + colsep, align="l") for part in table[icol]]
options_total_width += col_width
# format the table into columns # format the table into columns
optionstext = unicode(EvTable(table=table, border="none")) optionstext = unicode(EvTable(table=table, border="none"))
else:
optionstext = ""
options_width_max = max(m_len(line) for line in optionstext.split("\n"))
# #
# format the entire node # format the entire node
@ -455,7 +458,7 @@ class EvMenu(object):
return self._node_formatter(nodetext, optionstext) return self._node_formatter(nodetext, optionstext)
else: else:
# build the page # build the page
total_width = max(options_total_width, nodetext_width_max) total_width = max(options_width_max, nodetext_width_max)
separator1 = "_" * total_width + "\n\n" if nodetext_width_max else "" separator1 = "_" * total_width + "\n\n" if nodetext_width_max else ""
separator2 = "\n" + "_" * total_width + "\n\n" if total_width else "" separator2 = "\n" + "_" * total_width + "\n\n" if total_width else ""
return separator1 + nodetext + separator2 + optionstext return separator1 + nodetext + separator2 + optionstext
@ -512,15 +515,22 @@ class EvMenu(object):
self.goto(goto, raw_string) self.goto(goto, raw_string)
def handle(self, raw_string): def parse_input(self, raw_string):
# flags and data """
Processes the user' node inputs.
Args:
raw_string (str): The incoming raw_string from the menu
command.
"""
caller = self._caller caller = self._caller
cmd = raw_string.strip().lower() cmd = raw_string.strip().lower()
allow_quit = self.allow_quit allow_quit = self.allow_quit
if cmd in self.options: if cmd in self.options:
# this will overload the other commands # this will take precedence over the default commands
# if it has the same name! # below
goto, callback = self.options[cmd] goto, callback = self.options[cmd]
self._callback_goto(callback, goto, raw_string) self._callback_goto(callback, goto, raw_string)
elif cmd in ("look", "l"): elif cmd in ("look", "l"):