mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 01:36:32 +01:00
Merge branch 'master' of https://github.com/evennia/evennia
This commit is contained in:
commit
a54f0b5b9e
3 changed files with 65 additions and 29 deletions
|
|
@ -542,12 +542,14 @@ class CmdColorTest(MuxPlayerCommand):
|
|||
Usage:
|
||||
@color ansi|xterm256
|
||||
|
||||
Print a color map along with in-mud color codes, while testing what is
|
||||
supported in your client. Choices are 16-color ansi (supported in most
|
||||
muds) or the 256-color xterm256 standard. No checking is done to determine
|
||||
your client supports color - if not you will see rubbish appear.
|
||||
Prints a color map along with in-mud color codes to use to produce
|
||||
them. It also tests what is supported in your client. Choices are
|
||||
16-color ansi (supported in most muds) or the 256-color xterm256
|
||||
standard. No checking is done to determine your client supports
|
||||
color - if not you will see rubbish appear.
|
||||
"""
|
||||
key = "@color"
|
||||
aliases = "color"
|
||||
locks = "cmd:all()"
|
||||
help_category = "General"
|
||||
|
||||
|
|
@ -576,17 +578,21 @@ class CmdColorTest(MuxPlayerCommand):
|
|||
ap = ansi.ANSI_PARSER
|
||||
# ansi colors
|
||||
# show all ansi color-related codes
|
||||
col1 = ["%s%s{n" % (code, code.replace("{", "{{")) for code, _ in ap.ext_ansi_map[:-1]]
|
||||
hi = "%ch"
|
||||
col2 = ["%s%s{n" % (code, code.replace("%", "%%")) for code, _ in ap.mux_ansi_map[3:-2]]
|
||||
col3 = ["%s%s{n" % (hi + code, (hi + code).replace("%", "%%")) for code, _ in ap.mux_ansi_map[3:-2]]
|
||||
table = utils.format_table([col1, col2, col3], extra_space=1)
|
||||
col1 = ["%s%s{n" % (code, code.replace("{", "{{")) for code, _ in ap.ext_ansi_map[6:14]]
|
||||
col2 = ["%s%s{n" % (code, code.replace("{", "{{")) for code, _ in ap.ext_ansi_map[14:22]]
|
||||
col3 = ["%s%s{n" % (code.replace("\\",""), code.replace("{", "{{").replace("\\", "")) for code, _ in ap.ext_ansi_map[-8:]]
|
||||
col2.extend(["" for i in range(len(col1)-len(col2))])
|
||||
#hi = "%ch"
|
||||
#col2 = ["%s%s{n" % (code, code.replace("%", "%%")) for code, _ in ap.mux_ansi_map[6:]]
|
||||
#col3 = ["%s%s{n" % (hi + code, (hi + code).replace("%", "%%")) for code, _ in ap.mux_ansi_map[3:-2]]
|
||||
table = utils.format_table([col1, col2, col3])
|
||||
string = "ANSI colors:"
|
||||
for row in table:
|
||||
string += "\n" + "".join(row)
|
||||
string += "\n " + " ".join(row)
|
||||
#print string
|
||||
self.msg(string)
|
||||
self.msg("({{X and %%cx are black-on-black\n %%r - return, %%t - tab, %%b - space)")
|
||||
self.msg("{{X : black. {{\ : return, {{- : tab, {{_ : space, {{* : invert")
|
||||
self.msg("To combine background and foreground, add background marker last, e.g. {{r{{[b.")
|
||||
|
||||
elif self.args.startswith("x"):
|
||||
# show xterm256 table
|
||||
|
|
@ -605,7 +611,7 @@ class CmdColorTest(MuxPlayerCommand):
|
|||
for row in table:
|
||||
string += "\n" + "".join(row)
|
||||
self.msg(string)
|
||||
self.msg("(e.g. %%123 and %%[123 also work)")
|
||||
#self.msg("(e.g. %%123 and %%[123 also work)")
|
||||
else:
|
||||
# malformed input
|
||||
self.msg("Usage: @color ansi|xterm256")
|
||||
|
|
|
|||
|
|
@ -170,10 +170,18 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
through the telnet connection.
|
||||
|
||||
valid telnet kwargs:
|
||||
oob=<string> - supply an Out-of-Band instruction.
|
||||
xterm256=True/False - enforce xterm256 setting. If not
|
||||
given, ttype result is used. If
|
||||
client does not suport xterm256, the
|
||||
ansi fallback will be used
|
||||
ansi=True/False - enforce ansi setting. If not given,
|
||||
ttype result is used.
|
||||
nomarkup=True - strip all ansi markup (this is the same as
|
||||
xterm256=False, ansi=False)
|
||||
raw=True - pass string through without any ansi
|
||||
processing (i.e. include Evennia ansi markers but do
|
||||
not convert them into ansi tokens)
|
||||
nomarkup=True - strip all ansi markup
|
||||
processing (i.e. include Evennia ansi markers but do
|
||||
not convert them into ansi tokens)
|
||||
|
||||
The telnet ttype negotiation flags, if any, are used if no kwargs
|
||||
are given.
|
||||
|
|
@ -192,10 +200,15 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
#print "msdp_string:", msdp_string
|
||||
self.msdp.data_out(msdp_string)
|
||||
|
||||
# parse **kwargs, falling back to ttype if nothing is given explicitly
|
||||
ttype = self.protocol_flags.get('TTYPE', {})
|
||||
xterm256 = kwargs.get("xterm256", ttype and ttype.get('256 COLORS', False))
|
||||
useansi = kwargs.get("ansi", ttype and ttype.get('ANSI', False))
|
||||
raw = kwargs.get("raw", False)
|
||||
nomarkup = not (ttype or ttype.get('256 COLORS') or ttype.get('ANSI') or not ttype.get("init_done"))
|
||||
nomarkup = kwargs.get("nomarkup", nomarkup)
|
||||
nomarkup = kwargs.get("nomarkup", not (xterm256 or useansi) or not ttype.get("init_done"))
|
||||
|
||||
#print "telnet kwargs=%s, message=%s" % (kwargs, text)
|
||||
#print "xterm256=%s, useansi=%s, raw=%s, nomarkup=%s, init_done=%s" % (xterm256, useansi, raw, nomarkup, ttype.get("init_done"))
|
||||
if raw:
|
||||
# no processing whatsoever
|
||||
self.sendLine(text)
|
||||
|
|
@ -203,4 +216,4 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
# we need to make sure to kill the color at the end in order
|
||||
# to match the webclient output.
|
||||
# print "telnet data out:", self.protocol_flags, id(self.protocol_flags), id(self)
|
||||
self.sendLine(ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=ttype.get('256 COLORS')))
|
||||
self.sendLine(ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256))
|
||||
|
|
|
|||
|
|
@ -201,6 +201,8 @@ class ANSIParser(object):
|
|||
mux_ansi_map = [
|
||||
# commented out by default; they (especially blink) are
|
||||
# potentially annoying
|
||||
(r'%cn', ANSI_NORMAL),
|
||||
(r'%ch', ANSI_HILITE),
|
||||
(r'%r', ANSI_RETURN),
|
||||
(r'%t', ANSI_TAB),
|
||||
(r'%b', ANSI_SPACE),
|
||||
|
|
@ -221,33 +223,48 @@ class ANSIParser(object):
|
|||
(r'%cw', ANSI_WHITE),
|
||||
(r'%cW', ANSI_BACK_WHITE),
|
||||
(r'%cx', ANSI_BLACK),
|
||||
(r'%cX', ANSI_BACK_BLACK),
|
||||
(r'%ch', ANSI_HILITE),
|
||||
(r'%cn', ANSI_NORMAL),
|
||||
(r'%cX', ANSI_BACK_BLACK)
|
||||
]
|
||||
|
||||
# Expanded mapping {r {n etc
|
||||
|
||||
hilite = ANSI_HILITE
|
||||
normal = ANSI_NORMAL
|
||||
|
||||
ext_ansi_map = [
|
||||
(r'{n', normal), # reset
|
||||
(r'{/', ANSI_RETURN), # line break
|
||||
(r'{-', ANSI_TAB), # tab
|
||||
(r'{_', ANSI_SPACE), # space
|
||||
(r'{\*', ANSI_INVERSE), # invert
|
||||
(r'{\^', ANSI_BLINK), # blinking text (very annoying and not supported by all clients)
|
||||
|
||||
(r'{r', hilite + ANSI_RED),
|
||||
(r'{R', normal + ANSI_RED),
|
||||
(r'{g', hilite + ANSI_GREEN),
|
||||
(r'{G', normal + ANSI_GREEN),
|
||||
(r'{y', hilite + ANSI_YELLOW),
|
||||
(r'{Y', normal + ANSI_YELLOW),
|
||||
(r'{b', hilite + ANSI_BLUE),
|
||||
(r'{B', normal + ANSI_BLUE),
|
||||
(r'{m', hilite + ANSI_MAGENTA),
|
||||
(r'{M', normal + ANSI_MAGENTA),
|
||||
(r'{c', hilite + ANSI_CYAN),
|
||||
(r'{C', normal + ANSI_CYAN),
|
||||
(r'{w', hilite + ANSI_WHITE), # pure white
|
||||
(r'{W', normal + ANSI_WHITE), # light grey
|
||||
(r'{x', hilite + ANSI_BLACK), # dark grey
|
||||
|
||||
(r'{R', normal + ANSI_RED),
|
||||
(r'{G', normal + ANSI_GREEN),
|
||||
(r'{Y', normal + ANSI_YELLOW),
|
||||
(r'{B', normal + ANSI_BLUE),
|
||||
(r'{M', normal + ANSI_MAGENTA),
|
||||
(r'{C', normal + ANSI_CYAN),
|
||||
(r'{W', normal + ANSI_WHITE), # light grey
|
||||
(r'{X', normal + ANSI_BLACK), # pure black
|
||||
(r'{n', normal) # reset
|
||||
|
||||
(r'{\[r', ANSI_BACK_RED),
|
||||
(r'{\[g', ANSI_BACK_GREEN),
|
||||
(r'{\[y', ANSI_BACK_YELLOW),
|
||||
(r'{\[b', ANSI_BACK_BLUE),
|
||||
(r'{\[m', ANSI_BACK_MAGENTA),
|
||||
(r'{\[c', ANSI_BACK_CYAN),
|
||||
(r'{\[w', ANSI_BACK_WHITE), # light grey background
|
||||
(r'{\[x', ANSI_BACK_BLACK) # pure black background
|
||||
]
|
||||
|
||||
# xterm256 {123, %c134,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue