If I want to have a colored representation of an objects in a QtConsole or the IPython Notebook, I just have to add the _repr_html_
method to the objects class.
In [1]: class Test(object):
def __init__(self, x):
self.x = x
def _repr_html_(self):
return '''<span style="color: green">
Test{<span style="color: red">%s</span>}
</span>''' % self.x
In [2]: Test(33)
Test{33}
This will give me a nice colored representation where Test{
will be green, 33
red and }
green again.
Is there a way to do this in the terminal version of the IPython Shell in a cross platform way?
Ideally it would work the same way as the the templates for the prompt customization:
In [1]: class Test(object):
def __init__(self, x):
self.x = x
def _repr_shell_(self):
return '{color.Green}Test{{color.Red}%s{color.Green}}' % self.x
If not, can I somehow import and use the IPython's internal cross-platform coloring system in my own console application? I looked into the IPython codebase, but I haven't found any direct way to use it :(