X-Git-Url: https://mudpy.org/gitweb?a=blobdiff_plain;f=lib%2Fmudpy%2Fmisc.py;h=d8c863ab80032e103882c5163fdb545ba21c73cb;hb=c817b9432d6ac5512dc86a266ac033d3078fcdcc;hp=8f6630f8b05e83a28329dd316336d2093b851462;hpb=51b19cb43ecf5f656ff5d46eb9a37a8613607fda;p=mudpy.git diff --git a/lib/mudpy/misc.py b/lib/mudpy/misc.py index 8f6630f..d8c863a 100644 --- a/lib/mudpy/misc.py +++ b/lib/mudpy/misc.py @@ -800,15 +800,15 @@ class User: # and the ansi escape to return to normal text if not just_prompt and prepend_padding: if not self.output_queue \ - or not self.output_queue[-1].endswith("\r\n"): + or not self.output_queue[-1].endswith(b"\r\n"): output = "$(eol)" + output elif not self.output_queue[-1].endswith( - "\r\n\x1b[0m\r\n" + b"\r\n\x1b[0m\r\n" ) and not self.output_queue[-1].endswith( - "\r\n\r\n" + b"\r\n\r\n" ): output = "$(eol)" + output - output += eol + unichr(27) + "[0m" + output += eol + chr(27) + "[0m" # tack on a prompt if active if self.state == "active": @@ -1202,7 +1202,11 @@ def wrap_ansi_text(text, width): escape = False # normalize any potentially composited unicode before we count it - text = unicodedata.normalize("NFKC", text) + # TODO: remove this check after the switch to py3k + try: + text = unicodedata.normalize("NFKC", text) + except TypeError: + text = unicodedata.normalize("NFKC", unicode(text)) # iterate over each character from the begining of the text for each_character in text: @@ -1354,15 +1358,15 @@ def replace_macros(user, text, is_input=False): # a dict of replacement macros macros = { "eol": "\r\n", - "bld": unichr(27) + "[1m", - "nrm": unichr(27) + "[0m", - "blk": unichr(27) + "[30m", - "blu": unichr(27) + "[34m", - "cyn": unichr(27) + "[36m", - "grn": unichr(27) + "[32m", - "mgt": unichr(27) + "[35m", - "red": unichr(27) + "[31m", - "yel": unichr(27) + "[33m", + "bld": chr(27) + "[1m", + "nrm": chr(27) + "[0m", + "blk": chr(27) + "[30m", + "blu": chr(27) + "[34m", + "cyn": chr(27) + "[36m", + "grn": chr(27) + "[32m", + "mgt": chr(27) + "[35m", + "red": chr(27) + "[31m", + "yel": chr(27) + "[33m", } # add dynamic macros where possible @@ -2442,9 +2446,8 @@ def daemonize(universe): if universe.contents["internal:process"].getboolean("daemon"): # if possible, we want to rename the process to the same as the script - # (these will need to be byte type during 2to3 migration) - new_argv = "\0".join(sys.argv) + "\0" - new_short_argv0 = os.path.basename(sys.argv[0]) + "\0" + new_argv = b"\x00".join(x.encode("utf-8") for x in sys.argv) + b"\x00" + short_argv0 = os.path.basename(sys.argv[0]).encode("utf-8") + b"\x00" # attempt the linux way first try: @@ -2463,7 +2466,7 @@ def daemonize(universe): ctypes.memmove(argc.contents, new_argv, len(new_argv)) ctypes.CDLL(ctypes.util.find_library("c")).prctl( 15, - new_short_argv0, + short_argv0, 0, 0, 0