X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fcommand.py;h=2b20b1a6d4b818e7be8f8efc149f09d99e1c8c13;hp=ebd9036983b8178a0f3d9a7ef71840b811446c46;hb=a93dc77b0d77e622834f524e2060d516b47bbc58;hpb=b64bdabe02e5d30113df5052050cfb9b62683a74 diff --git a/mudpy/command.py b/mudpy/command.py index ebd9036..2b20b1a 100644 --- a/mudpy/command.py +++ b/mudpy/command.py @@ -11,7 +11,7 @@ import unicodedata import mudpy -def chat(actor): +def chat(actor, parameters): """Toggle chat mode.""" mode = actor.get("mode") if not mode: @@ -148,10 +148,7 @@ def help(actor, parameters): if parameters and actor.owner: # is the command word one for which we have data? - if parameters in actor.universe.groups["command"]: - command = actor.universe.groups["command"][parameters] - else: - command = None + command = mudpy.misc.find_command(parameters) # only for allowed commands if actor.can_run(command): @@ -164,7 +161,8 @@ def help(actor, parameters): output = "$(red)" else: output = "$(grn)" - output += parameters + "$(nrm) - " + description + "$(eol)$(eol)" + output = "%s%s$(nrm) - %s$(eol)$(eol)" % ( + output, command.subkey, description) # add the help text if provided help_text = command.get("help") @@ -197,23 +195,53 @@ def help(actor, parameters): # no specific command word was indicated else: - # give a sorted list of commands with descriptions if provided - output = "These are the commands available to you:$(eol)$(eol)" - sorted_commands = list(actor.universe.groups["command"].keys()) - sorted_commands.sort() - for item in sorted_commands: - command = actor.universe.groups["command"][item] + # preamble text + output = ("These are the commands available to you [brackets indicate " + "optional portion]:$(eol)$(eol)") + + # list command names in alphabetical order + for command_name, command in sorted( + actor.universe.groups["command"].items()): + + # skip over disallowed commands if actor.can_run(command): - description = command.get("description") - if not description: - description = "(no short description provided)" + + # start incrementing substrings + for position in range(1, len(command_name) + 1): + + # we've found our shortest possible abbreviation + candidate = mudpy.misc.find_command( + command_name[:position]) + try: + if candidate.subkey == command_name: + break + except AttributeError: + pass + + # use square brackets to indicate optional part of command name + if position < len(command_name): + abbrev = "%s[%s]" % ( + command_name[:position], command_name[position:]) + else: + abbrev = command_name + + # supply a useful default if the short description is missing + description = command.get( + "description", "(no short description provided)") + + # administrative command names are in red, others in green if command.get("administrative"): - output += " $(red)" + color = "red" else: - output += " $(grn)" - output += item + "$(nrm) - " + description + "$(eol)" - output += ('$(eol)Enter "help COMMAND" for help on a command ' - 'named "COMMAND".') + color = "grn" + + # format the entry for this command + output = "%s $(%s)%s$(nrm) - %s$(eol)" % ( + output, color, abbrev, description) + + # add a footer with instructions on getting additional information + output = ('%s $(eol)Enter "help COMMAND" for help on a command named ' + '"COMMAND".' % output) # send the accumulated output to the user actor.send(output) @@ -237,6 +265,10 @@ def move(actor, parameters): def preferences(actor, parameters): """List, view and change actor preferences.""" + + # Escape replacement macros in preferences + parameters = mudpy.misc.escape_macros(parameters) + message = "" arguments = parameters.split() allowed_prefs = set() @@ -269,14 +301,14 @@ def preferences(actor, parameters): actor.send(message) -def quit(actor): +def quit(actor, parameters): """Leave the world and go back to the main menu.""" if actor.owner: actor.owner.state = "main_utility" actor.owner.deactivate_avatar() -def reload(actor): +def reload(actor, parameters): """Reload all code modules, configs and data.""" if actor.owner: @@ -421,9 +453,8 @@ def show(actor, parameters): elif arguments[0] == "version": message = repr(actor.universe.versions) elif arguments[0] == "time": - message = actor.universe.groups["internal"]["counters"].get( - "elapsed" - ) + " increments elapsed since the world was created." + message = "%s increments elapsed since the world was created." % ( + str(actor.universe.groups["internal"]["counters"].get("elapsed"))) elif arguments[0] == "groups": message = "These are the element groups:$(eol)" groups = list(actor.universe.groups.keys())