def prompt(self):
""""Generate and return an input prompt."""
- return self.account.get("prompt", ">") + " "
+
+ # Start with the user's preference, if one was provided
+ prompt = self.account.get("prompt")
+
+ # If the user has not set a prompt, then immediately return the default
+ # provided for the current state
+ if not prompt:
+ return get_menu_prompt(self.state)
+
+ # Allow including the World clock state
+ if "$_(time)" in prompt:
+ prompt = prompt.replace(
+ "$_(time)",
+ str(universe.groups["internal"]["counters"].get("elapsed")))
+
+ # Append a single space for clear separation from user input
+ if prompt[-1] != " ":
+ prompt = "%s " % prompt
+
+ # Return the cooked prompt
+ return prompt
def adjust_echoing(self):
"""Adjust echoing to match state menu requirements."""
return user
+def find_command(command_name):
+ """Try to find a command by name or abbreviation."""
+
+ # lowercase the command
+ command_name = command_name.lower()
+
+ command = None
+ if command_name in universe.groups["command"]:
+ # the command matches a command word for which we have data
+ command = universe.groups["command"][command_name]
+ else:
+ for candidate in sorted(universe.groups["command"]):
+ if candidate.startswith(command_name) and not universe.groups[
+ "command"][candidate].get("administrative"):
+ # the command matches the start of a command word and is not
+ # restricted to administrators
+ command = universe.groups["command"][candidate]
+ break
+ return command
+
+
def get_menu(state, error=None, choices=None):
"""Show the correct menu text to a user."""
else:
command_name, parameters = first_word(input_data)
- # lowercase the command
- command_name = command_name.lower()
-
- # the command matches a command word for which we have data
- if command_name in universe.groups["command"]:
- command = universe.groups["command"][command_name]
- else:
- command = None
+ # expand to an actual command
+ command = find_command(command_name)
# if it's allowed, do it
if actor.can_run(command):