From 63329f5420d6bee78dc1fe8eb30b9d854623cab5 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 15 Apr 2012 23:42:57 +0200 Subject: [PATCH] Added the ability to escape colour codes with \, So using \{g in a text will now result in '{g' being printed instead of the text switching to bright green. This can be useful for documentation. --- src/commands/default/building.py | 2 +- src/utils/ansi.py | 96 +++++++++++++++++--------------- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/src/commands/default/building.py b/src/commands/default/building.py index 9d8bacb10b..dc251cf00a 100644 --- a/src/commands/default/building.py +++ b/src/commands/default/building.py @@ -1161,7 +1161,7 @@ class CmdSetAttribute(ObjManipCommand): the functionality of certain custom objects). This is indicated by you starting your value with one of {c'{n, {c"{n, {c({n, {c[{n or {c{ {n. Note that you should leave a space after starting a dictionary ('{ ') - so as to not confuse the dictionary start with a colour code. + so as to not confuse the dictionary start with a colour code like \{g. Remember that if you use Python primitives like this, you must write proper Python syntax too - notably you must include quotes around your strings or you will get an error. diff --git a/src/utils/ansi.py b/src/utils/ansi.py index f2ed33ea64..dffb5dbe00 100644 --- a/src/utils/ansi.py +++ b/src/utils/ansi.py @@ -60,6 +60,9 @@ class ANSIParser(object): """ A class that parses ansi markup to ANSI command sequences + + We also allow to escape colour codes + by prepending with a \. """ def __init__(self): @@ -68,29 +71,29 @@ class ANSIParser(object): # MUX-style mappings %cr %cn etc self.mux_ansi_map = [ - (r'%r', ANSI_RETURN), - (r'%t', ANSI_TAB), - (r'%b', ANSI_SPACE), - (r'%cf', ANSI_BLINK), - (r'%ci', ANSI_INVERSE), - (r'%ch', ANSI_HILITE), - (r'%cn', ANSI_NORMAL), - (r'%cx', ANSI_BLACK), - (r'%cX', ANSI_BACK_BLACK), - (r'%cr', ANSI_RED), - (r'%cR', ANSI_BACK_RED), - (r'%cg', ANSI_GREEN), - (r'%cG', ANSI_BACK_GREEN), - (r'%cy', ANSI_YELLOW), - (r'%cY', ANSI_BACK_YELLOW), - (r'%cb', ANSI_BLUE), - (r'%cB', ANSI_BACK_BLUE), - (r'%cm', ANSI_MAGENTA), - (r'%cM', ANSI_BACK_MAGENTA), - (r'%cc', ANSI_CYAN), - (r'%cC', ANSI_BACK_CYAN), - (r'%cw', ANSI_WHITE), - (r'%cW', ANSI_BACK_WHITE), + (r'(?