+ return ""
+
+def get_menu_prompt(state):
+ """Try to get a prompt, if it was defined."""
+ try:
+ return menu_data.get(state, "prompt") + " "
+ except:
+ return ""
+
+def get_menu_choices(user):
+ """Return a dict of choice:meaning."""
+ choices = {}
+ for option in menu_data.options(user.state):
+ if option.startswith("choice_"):
+ choices[option.split("_", 2)[1]] = menu_data.get(user.state, option)
+ elif option.startswith("create_"):
+ choices[option.split("_", 2)[1]] = eval(menu_data.get(user.state, option))
+ return choices
+
+def get_formatted_menu_choices(state, choices):
+ """Returns a formatted string of menu choices."""
+ choice_output = ""
+ choice_keys = choices.keys()
+ choice_keys.sort()
+ for choice in choice_keys:
+ choice_output += " [$(red)" + choice + "$(nrm)] " + choices[choice] + "$(eol)"
+ if choice_output: choice_output += "$(eol)"
+ return choice_output
+
+def get_menu_branches(state):
+ """Return a dict of choice:branch."""
+ branches = {}
+ try:
+ for option in menu_data.options(state):
+ if option.startswith("branch_"):
+ branches[option.split("_", 2)[1]] = menu_data.get(state, option)
+ except:
+ pass
+ return branches
+
+def get_default_branch(state):
+ """Return the default branch."""
+ try:
+ return menu_data.get(state, "branch")
+ except:
+ return ""
+
+def get_choice_branch(user, choice):
+ """Returns the new state matching the given choice."""
+ branches = get_menu_branches(user.state)
+ if not choice: choice = get_default_menu_choice(user.state)
+ if choice in branches.keys(): return branches[choice]
+ elif choice in user.menu_choices.keys(): return get_default_branch(user.state)
+ else: return ""
+
+def get_menu_actions(state):
+ """Return a dict of choice:branch."""
+ actions = {}
+ try:
+ for option in menu_data.options(state):
+ if option.startswith("action_"):
+ actions[option.split("_", 2)[1]] = menu_data.get(state, option)
+ except:
+ pass
+ return actions
+
+def get_default_action(state):
+ """Return the default action."""
+ try:
+ return menu_data.get(state, "action")
+ except:
+ return ""
+
+def get_choice_action(user, choice):
+ """Run any indicated script for the given choice."""
+ actions = get_menu_actions(user.state)
+ if not choice: choice = get_default_menu_choice(user.state)
+ if choice in actions.keys(): return actions[choice]
+ elif choice in user.menu_choices.keys(): return get_default_action(user.state)
+ else: return ""