Move selected menu item into the User object
[mudpy.git] / mudpy / misc.py
index 62f531e..dc37b6e 100644 (file)
@@ -488,6 +488,7 @@ class User:
         self.address = ""
         self.authenticated = False
         self.avatar = None
+        self.choice = ""
         self.columns = 79
         self.connection = None
         self.error = ""
@@ -1638,12 +1639,12 @@ def get_default_branch(state):
     return universe.groups["menu"][state].get("branch")
 
 
-def get_choice_branch(user, choice):
+def get_choice_branch(user):
     """Returns the new state matching the given choice."""
     branches = get_menu_branches(user.state)
-    if choice in branches.keys():
-        return branches[choice]
-    elif choice in user.menu_choices.keys():
+    if user.choice in branches.keys():
+        return branches[user.choice]
+    elif user.choice in user.menu_choices.keys():
         return get_default_branch(user.state)
     else:
         return ""
@@ -1665,12 +1666,12 @@ def get_default_action(state):
     return universe.groups["menu"][state].get("action")
 
 
-def get_choice_action(user, choice):
+def get_choice_action(user):
     """Run any indicated script for the given choice."""
     actions = get_menu_actions(user.state)
-    if choice in actions.keys():
-        return actions[choice]
-    elif choice in user.menu_choices.keys():
+    if user.choice in actions.keys():
+        return actions[user.choice]
+    elif user.choice in user.menu_choices.keys():
         return get_default_action(user.state)
     else:
         return ""
@@ -1702,16 +1703,16 @@ def generic_menu_handler(user):
 
     # get a lower-case representation of the next line of input
     if user.input_queue:
-        choice = user.input_queue.pop(0)
-        if choice:
-            choice = choice.lower()
+        user.choice = user.input_queue.pop(0)
+        if user.choice:
+            user.choice = user.choice.lower()
     else:
-        choice = ""
-    if not choice:
-        choice = get_default_menu_choice(user.state)
-    if choice in user.menu_choices:
-        exec(get_choice_action(user, choice))
-        new_state = get_choice_branch(user, choice)
+        user.choice = ""
+    if not user.choice:
+        user.choice = get_default_menu_choice(user.state)
+    if user.choice in user.menu_choices:
+        exec(get_choice_action(user))
+        new_state = get_choice_branch(user)
         if new_state:
             user.state = new_state
     else: