X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fmisc.py;h=dce3ea6c84c7b0ccdc1782a4d5d7601414ef3b6b;hp=7c013a8f9a3f54c1a2d7e758ccf8a233442f0fed;hb=da204426401f781b90121eac018166bcde5ee211;hpb=6d10b4e795679965dfd7f5e4ff027151ff629b8f diff --git a/mudpy/misc.py b/mudpy/misc.py index 7c013a8..dce3ea6 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -5,6 +5,7 @@ # provided in the LICENSE file distributed with this software. import codecs +import datetime import os import random import re @@ -660,6 +661,20 @@ class User: self.error = False self.adjust_echoing() + def prompt(self): + """"Generate and return an input 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) + + # Return the cooked prompt + return "%s " % prompt + def adjust_echoing(self): """Adjust echoing to match state menu requirements.""" if mudpy.telnet.is_enabled(self, mudpy.telnet.TELOPT_ECHO, @@ -722,7 +737,7 @@ class User: if not just_prompt: output += "$(eol)" if add_prompt: - output += self.account.get("prompt", ">") + " " + output += self.prompt() mode = self.avatar.get("mode") if mode: output += "(" + mode + ") " @@ -986,7 +1001,7 @@ def log(message, level=0): file_name = "" max_log_lines = 0 syslog_name = "" - timestamp = time.asctime()[4:19] + timestamp = datetime.datetime.now().isoformat(' ') # turn the message into a list of nonempty lines lines = [x for x in [(x.rstrip()) for x in message.split("\n")] if x != ""] @@ -1191,7 +1206,7 @@ def weighted_choice(data): # create the expanded list of keys for key in data.keys(): - for count in range(data[key]): + for _count in range(data[key]): expanded.append(key) # return one at random @@ -1242,7 +1257,7 @@ def random_name(): name = "" # create a name of random length from the syllables - for syllable in range(random.randrange(2, 6)): + for _syllable in range(random.randrange(2, 6)): name += weighted_choice(syllables) # strip any leading quotemark, capitalize and return the name