36 FUNCTION_NAME =
"blue",
53 """Return a string that should display as coloured on a conformant terminal"""
55 color = Color.categories[category]
57 raise RuntimeError(
"Unknown category: %s" % category)
60 x = color.lower().split(
";")
61 self.color, bold = x.pop(0),
False
64 if props
in (
"bold",):
68 self.
_code =
"%s" % (30 + Color.colors[self.color])
70 raise RuntimeError(
"Unknown colour: %s" % self.color)
77 """Should I colour strings? With an argument, set the value"""
82 if isinstance(val, dict):
85 if Color.categories.has_key(k):
86 if Color.colors.has_key(val[k]):
87 Color.categories[k] = val[k]
89 print >> sys.stderr,
"Unknown colour %s for category %s" % (val[k], k)
94 print >> sys.stderr,
"Unknown colourizing category: %s" %
" ".join(unknown)
96 return Color._colorize
104 prefix = base + self.
_code +
"m"
107 return prefix + self.
rawText + suffix
111 text =
Color(text, category)
127 def format(config, name=None, writeSourceLine=True, prefix="", verbose=False):
128 """Format the history record for config.name"""
131 for i, name
in enumerate(config.history.keys()):
134 print format(config, name)
137 for value, tb, label
in config.history[name]:
140 if frame.functionName
in (
"__new__",
"__set__",
"__setattr__",
"execfile",
"wrapper")
or \
141 os.path.split(frame.fileName)[1]
in (
"argparse.py",
"argumentParser.py"):
147 line.append([
"%s" % (
"%s:%d" % (frame.fileName, frame.lineNumber)),
"FILE",])
149 line.append([frame.text,
"TEXT",])
151 line.append([frame.functionName,
"FUNCTION_NAME",])
155 outputs.append([value, output])
161 for value, output
in outputs:
162 sourceLengths.append(max([len(x[0][0])
for x
in output]))
163 sourceLength = max(sourceLengths)
165 valueLength = len(prefix) + max([len(str(value))
for value, output
in outputs])
170 fullname =
"%s.%s" %(config._name, name)
if config._name
is not None else name
171 msg.append(
_colorize(re.sub(
r"^root\.",
"", fullname),
"NAME"))
172 for value, output
in outputs:
173 line = prefix +
_colorize(
"%-*s" % (valueLength, value),
"VALUE") +
" "
174 for i, vt
in enumerate(output):
176 vt[0][0] =
"%-*s" % (sourceLength, vt[0][0])
178 output[i] =
" ".join([
_colorize(v, t)
for v, t
in vt])
180 line += (
"\n%*s" % (valueLength + 1,
"")).join(output)
183 return "\n".join(msg)