Fix ANSI->HTML conversion in webclient; Resolve #1792

This commit is contained in:
Griatch 2019-09-08 18:26:23 +02:00
parent 05b859c0b7
commit ea07a81696
3 changed files with 37 additions and 11 deletions

View file

@ -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))

View file

@ -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'''<span class="%s">%s%s%s</span>''' % (
self.bg_colormap.get(bgcode, self.fg_colormap.get(bgcode, "err")),
prespace and "&nbsp;" * len(prespace) or "",
postspace and "&nbsp;" * len(postspace) or "",
text)
else:
ret = r'''<span class="%s"><span class="%s">%s%s%s</span></span>''' % (
self.bg_colormap.get(bgcode, self.fg_colormap.get(bgcode, "err")),
self.fg_colormap.get(fgcode, self.bg_colormap.get(fgcode, "err")),
prespace and "&nbsp;" * len(prespace) or "",
postspace and "&nbsp;" * len(postspace) or "",
text)
return ret
def _sub_fg(self, colormatch):
code, text = colormatch.groups()
return r'''<span class="%s">%s</span>''' % (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)

View file

@ -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) {