Added {-type coding for backgrounds. First removal of mentions of the %c syntax from @color command (%c style syntax is still working though)

This commit is contained in:
Griatch 2014-01-26 18:46:28 +01:00
parent d69f4dc674
commit 5c41adf7d0
2 changed files with 46 additions and 23 deletions

View file

@ -542,12 +542,14 @@ class CmdColorTest(MuxPlayerCommand):
Usage: Usage:
@color ansi|xterm256 @color ansi|xterm256
Print a color map along with in-mud color codes, while testing what is Prints a color map along with in-mud color codes to use to produce
supported in your client. Choices are 16-color ansi (supported in most them. It also tests what is supported in your client. Choices are
muds) or the 256-color xterm256 standard. No checking is done to determine 16-color ansi (supported in most muds) or the 256-color xterm256
your client supports color - if not you will see rubbish appear. standard. No checking is done to determine your client supports
color - if not you will see rubbish appear.
""" """
key = "@color" key = "@color"
aliases = "color"
locks = "cmd:all()" locks = "cmd:all()"
help_category = "General" help_category = "General"
@ -576,17 +578,21 @@ class CmdColorTest(MuxPlayerCommand):
ap = ansi.ANSI_PARSER ap = ansi.ANSI_PARSER
# ansi colors # ansi colors
# show all ansi color-related codes # show all ansi color-related codes
col1 = ["%s%s{n" % (code, code.replace("{", "{{")) for code, _ in ap.ext_ansi_map[:-1]] col1 = ["%s%s{n" % (code, code.replace("{", "{{")) for code, _ in ap.ext_ansi_map[6:14]]
hi = "%ch" col2 = ["%s%s{n" % (code, code.replace("{", "{{")) for code, _ in ap.ext_ansi_map[14:22]]
col2 = ["%s%s{n" % (code, code.replace("%", "%%")) for code, _ in ap.mux_ansi_map[3:-2]] col3 = ["%s%s{n" % (code.replace("\\",""), code.replace("{", "{{").replace("\\", "")) for code, _ in ap.ext_ansi_map[-8:]]
col3 = ["%s%s{n" % (hi + code, (hi + code).replace("%", "%%")) for code, _ in ap.mux_ansi_map[3:-2]] col2.extend(["" for i in range(len(col1)-len(col2))])
table = utils.format_table([col1, col2, col3], extra_space=1) #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:" string = "ANSI colors:"
for row in table: for row in table:
string += "\n" + "".join(row) string += "\n " + " ".join(row)
#print string #print string
self.msg(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"): elif self.args.startswith("x"):
# show xterm256 table # show xterm256 table
@ -605,7 +611,7 @@ class CmdColorTest(MuxPlayerCommand):
for row in table: for row in table:
string += "\n" + "".join(row) string += "\n" + "".join(row)
self.msg(string) self.msg(string)
self.msg("(e.g. %%123 and %%[123 also work)") #self.msg("(e.g. %%123 and %%[123 also work)")
else: else:
# malformed input # malformed input
self.msg("Usage: @color ansi|xterm256") self.msg("Usage: @color ansi|xterm256")

View file

@ -201,6 +201,8 @@ class ANSIParser(object):
mux_ansi_map = [ mux_ansi_map = [
# commented out by default; they (especially blink) are # commented out by default; they (especially blink) are
# potentially annoying # potentially annoying
(r'%cn', ANSI_NORMAL),
(r'%ch', ANSI_HILITE),
(r'%r', ANSI_RETURN), (r'%r', ANSI_RETURN),
(r'%t', ANSI_TAB), (r'%t', ANSI_TAB),
(r'%b', ANSI_SPACE), (r'%b', ANSI_SPACE),
@ -221,33 +223,48 @@ class ANSIParser(object):
(r'%cw', ANSI_WHITE), (r'%cw', ANSI_WHITE),
(r'%cW', ANSI_BACK_WHITE), (r'%cW', ANSI_BACK_WHITE),
(r'%cx', ANSI_BLACK), (r'%cx', ANSI_BLACK),
(r'%cX', ANSI_BACK_BLACK), (r'%cX', ANSI_BACK_BLACK)
(r'%ch', ANSI_HILITE),
(r'%cn', ANSI_NORMAL),
] ]
# Expanded mapping {r {n etc # Expanded mapping {r {n etc
hilite = ANSI_HILITE hilite = ANSI_HILITE
normal = ANSI_NORMAL normal = ANSI_NORMAL
ext_ansi_map = [ 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', hilite + ANSI_RED),
(r'{R', normal + ANSI_RED),
(r'{g', hilite + ANSI_GREEN), (r'{g', hilite + ANSI_GREEN),
(r'{G', normal + ANSI_GREEN),
(r'{y', hilite + ANSI_YELLOW), (r'{y', hilite + ANSI_YELLOW),
(r'{Y', normal + ANSI_YELLOW),
(r'{b', hilite + ANSI_BLUE), (r'{b', hilite + ANSI_BLUE),
(r'{B', normal + ANSI_BLUE),
(r'{m', hilite + ANSI_MAGENTA), (r'{m', hilite + ANSI_MAGENTA),
(r'{M', normal + ANSI_MAGENTA),
(r'{c', hilite + ANSI_CYAN), (r'{c', hilite + ANSI_CYAN),
(r'{C', normal + ANSI_CYAN),
(r'{w', hilite + ANSI_WHITE), # pure white (r'{w', hilite + ANSI_WHITE), # pure white
(r'{W', normal + ANSI_WHITE), # light grey
(r'{x', hilite + ANSI_BLACK), # dark 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'{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, # xterm256 {123, %c134,