From 5c41adf7d0ef6571b1d99ac6ba5706b729c2a6ac Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 26 Jan 2014 18:46:28 +0100 Subject: [PATCH] Added {-type coding for backgrounds. First removal of mentions of the %c syntax from @color command (%c style syntax is still working though) --- src/commands/default/player.py | 30 +++++++++++++++----------- src/utils/ansi.py | 39 ++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/commands/default/player.py b/src/commands/default/player.py index 67e9ea3951..cd16501580 100644 --- a/src/commands/default/player.py +++ b/src/commands/default/player.py @@ -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") diff --git a/src/utils/ansi.py b/src/utils/ansi.py index ee55fbb377..5862285ee4 100644 --- a/src/utils/ansi.py +++ b/src/utils/ansi.py @@ -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,