From ea07a8169689ab63b420b3427e7445c86f7e3092 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 8 Sep 2019 18:26:23 +0200 Subject: [PATCH] Fix ANSI->HTML conversion in webclient; Resolve #1792 --- evennia/accounts/accounts.py | 13 ++++---- evennia/utils/text2html.py | 33 ++++++++++++++++--- .../static/webclient/css/webclient.css | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index d1b5749dd9..9929ca6e78 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -48,7 +48,7 @@ _AT_SEARCH_RESULT = variable_from_module(*settings.SEARCH_AT_RESULT.rsplit('.', _MULTISESSION_MODE = settings.MULTISESSION_MODE _MAX_NR_CHARACTERS = settings.MAX_NR_CHARACTERS _CMDSET_ACCOUNT = settings.CMDSET_ACCOUNT -_CONNECT_CHANNEL = None +_MUDINFO_CHANNEL = None # Create throttles for too many account-creations and login attempts CREATION_THROTTLE = Throttle(limit=2, timeout=10 * 60) @@ -1145,17 +1145,18 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)): message (str): A message to send to the connect channel. """ - global _CONNECT_CHANNEL - if not _CONNECT_CHANNEL: + global _MUDINFO_CHANNEL + if not _MUDINFO_CHANNEL: try: - _CONNECT_CHANNEL = ChannelDB.objects.filter(db_key=settings.DEFAULT_CHANNELS[1]["key"])[0] + _MUDINFO_CHANNEL = ChannelDB.objects.filter( + db_key=settings.CHANNEL_MUDINFO["key"])[0] except Exception: logger.log_trace() now = timezone.now() now = "%02i-%02i-%02i(%02i:%02i)" % (now.year, now.month, now.day, now.hour, now.minute) - if _CONNECT_CHANNEL: - _CONNECT_CHANNEL.tempmsg("[%s, %s]: %s" % (_CONNECT_CHANNEL.key, now, message)) + if _MUDINFO_CHANNEL: + _MUDINFO_CHANNEL.tempmsg("[%s, %s]: %s" % (_MUDINFO_CHANNEL.key, now, message)) else: logger.log_info("[%s]: %s" % (now, message)) diff --git a/evennia/utils/text2html.py b/evennia/utils/text2html.py index 88f2101d3c..fc75780809 100644 --- a/evennia/utils/text2html.py +++ b/evennia/utils/text2html.py @@ -80,12 +80,18 @@ class TextToHTMLparser(object): bg_colormap = dict((code, clr) for clr, code in colorback) # create stop markers - fgstop = "(?:\033\[1m|\033\[22m)*\033\[3[0-8].*?m|\033\[0m|$" - bgstop = "(?:\033\[1m|\033\[22m)*\033\[4[0-8].*?m|\033\[0m|$" + fgstop = "(?:\033\[1m|\033\[22m){0,1}\033\[3[0-8].*?m|\033\[0m|$" + bgstop = "(?:\033\[1m|\033\[22m){0,1}\033\[4[0-8].*?m|\033\[0m|$" + bgfgstop = bgstop[:-2] + r"(\s*)" + fgstop + + fgstart = "((?:\033\[1m|\033\[22m){0,1}\033\[3[0-8].*?m)" + bgstart = "((?:\033\[1m|\033\[22m){0,1}\033\[4[0-8].*?m)" + bgfgstart = bgstart + r"(\s*)" + "((?:\033\[1m|\033\[22m){0,1}\033\[[3-4][0-8].*?m){0,1}" # extract color markers, tagging the start marker and the text marked - re_fgs = re.compile("((?:\033\[1m|\033\[22m)*\033\[3[0-8].*?m)(.*?)(?=" + fgstop + ")") - re_bgs = re.compile("((?:\033\[1m|\033\[22m)*\033\[4[0-8].*?m)(.*?)(?=" + bgstop + ")") + re_fgs = re.compile(fgstart + "(.*?)(?=" + fgstop + ")") + re_bgs = re.compile(bgstart + "(.*?)(?=" + bgstop + ")") + re_bgfg = re.compile(bgfgstart + "(.*?)(?=" + bgfgstop + ")") re_normal = re.compile(normal.replace("[", r"\[")) re_hilite = re.compile("(?:%s)(.*)(?=%s|%s)" % (hilite.replace("[", r"\["), fgstop, bgstop)) @@ -97,6 +103,24 @@ class TextToHTMLparser(object): re_url = re.compile(r'((?:ftp|www|https?)\W+(?:(?!\.(?:\s|$)|&\w+;)[^"\',;$*^\\(){}<>\[\]\s])+)(\.(?:\s|$)|&\w+;|)') re_mxplink = re.compile(r'\|lc(.*?)\|lt(.*?)\|le', re.DOTALL) + def _sub_bgfg(self, colormatch): + # print("colormatch.groups()", colormatch.groups()) + bgcode, prespace, fgcode, text, postspace = colormatch.groups() + if not fgcode: + ret = r'''%s%s%s''' % ( + self.bg_colormap.get(bgcode, self.fg_colormap.get(bgcode, "err")), + prespace and " " * len(prespace) or "", + postspace and " " * len(postspace) or "", + text) + else: + ret = r'''%s%s%s''' % ( + self.bg_colormap.get(bgcode, self.fg_colormap.get(bgcode, "err")), + self.fg_colormap.get(fgcode, self.bg_colormap.get(fgcode, "err")), + prespace and " " * len(prespace) or "", + postspace and " " * len(postspace) or "", + text) + return ret + def _sub_fg(self, colormatch): code, text = colormatch.groups() return r'''%s''' % (self.fg_colormap.get(code, "err"), text) @@ -117,6 +141,7 @@ class TextToHTMLparser(object): text (str): Re-colored text. """ + text = self.re_bgfg.sub(self._sub_bgfg, text) text = self.re_fgs.sub(self._sub_fg, text) text = self.re_bgs.sub(self._sub_bg, text) text = self.re_normal.sub("", text) diff --git a/evennia/web/webclient/static/webclient/css/webclient.css b/evennia/web/webclient/static/webclient/css/webclient.css index 856931501a..fe15af45f1 100644 --- a/evennia/web/webclient/static/webclient/css/webclient.css +++ b/evennia/web/webclient/static/webclient/css/webclient.css @@ -17,7 +17,7 @@ body { color: #ccc; font-size: .9em; font-family: 'DejaVu Sans Mono', Consolas, Inconsolata, 'Lucida Console', monospace; - line-height: 1.6em; + line-height: 1.1em; overflow: hidden; } @media screen and (max-width: 480px) {