From: Jeremy Stanley Date: Sun, 5 May 2019 21:07:26 +0000 (+0000) Subject: Allow including time in the active state prompt X-Git-Tag: 0.0.1~21 X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=commitdiff_plain;h=56f918a8f40771b5fd7db125d301b8e50e9a7a32 Allow including time in the active state prompt Occurrences of $(time) in the user's prompt string will be replaced by the current World clock increment when displayed. Also test this works as intended. --- diff --git a/mudpy/misc.py b/mudpy/misc.py index dce3ea6..50a9456 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -672,8 +672,18 @@ class User: 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 "%s " % prompt + return prompt def adjust_echoing(self): """Adjust echoing to match state menu requirements.""" diff --git a/mudpy/tests/selftest.py b/mudpy/tests/selftest.py index d98755a..b73c13e 100644 --- a/mudpy/tests/selftest.py +++ b/mudpy/tests/selftest.py @@ -167,7 +167,8 @@ test_preferences = ( (0, "> ", "preferences"), (0, r"prompt \x1b\[32m.*> ", "preferences prompt $(foo)"), (0, r"\$\(foo\) ", "preferences prompt"), - (0, r"\$\(foo\).*\$\(foo\) ", "preferences prompt >"), + (0, r"\$\(foo\).*\$\(foo\) ", "preferences prompt $(time)>"), + (0, "[0-9]> ", "preferences prompt >"), (2, "> ", "preferences loglevel 0"), (2, "> ", "preferences"), (2, r"loglevel \x1b\[32m0\x1b\[0m.*> ", "preferences loglevel zero"), diff --git a/share/command.yaml b/share/command.yaml index 6d009b2..cf3abec 100644 --- a/share/command.yaml +++ b/share/command.yaml @@ -62,7 +62,7 @@ command.preferences.help: If invoked with no parameters, all your current parameter is supplied, the first must be the name of a preference and the remainder is the value to which you wish to change it. Examples:$(eol)$(eol) preferences$(eol) preferences - prompt$(eol) preferences prompt $ + prompt$(eol) preferences prompt $_(time)> command.quit.action: mudpy.command.quit(actor) command.quit.description: Leave the World.