##// END OF EJS Templates
add colored repr_pretty to ExecuteReply
MinRK -
Show More
@@ -33,6 +33,7 b' import zmq'
33 from IPython.config.configurable import MultipleInstanceError
33 from IPython.config.configurable import MultipleInstanceError
34 from IPython.core.application import BaseIPythonApplication
34 from IPython.core.application import BaseIPythonApplication
35
35
36 from IPython.utils.coloransi import TermColors
36 from IPython.utils.jsonutil import rekey
37 from IPython.utils.jsonutil import rekey
37 from IPython.utils.localinterfaces import LOCAL_IPS
38 from IPython.utils.localinterfaces import LOCAL_IPS
38 from IPython.utils.path import get_ipython_dir
39 from IPython.utils.path import get_ipython_dir
@@ -90,13 +91,39 b' class ExecuteReply(object):'
90 return self.metadata[key]
91 return self.metadata[key]
91
92
92 def __repr__(self):
93 def __repr__(self):
93 pyout = self.metadata['pyout'] or {}
94 pyout = self.metadata['pyout'] or {'data':{}}
94 text_out = pyout.get('data', {}).get('text/plain', '')
95 text_out = pyout['data'].get('text/plain', '')
95 if len(text_out) > 32:
96 if len(text_out) > 32:
96 text_out = text_out[:29] + '...'
97 text_out = text_out[:29] + '...'
97
98
98 return "<ExecuteReply[%i]: %s>" % (self.execution_count, text_out)
99 return "<ExecuteReply[%i]: %s>" % (self.execution_count, text_out)
99
100
101 def _repr_pretty_(self, p, cycle):
102 pyout = self.metadata['pyout'] or {'data':{}}
103 text_out = pyout['data'].get('text/plain', '')
104
105 if not text_out:
106 return
107
108 try:
109 ip = get_ipython()
110 except NameError:
111 colors = "NoColor"
112 else:
113 colors = ip.colors
114
115 if colors == "NoColor":
116 out = normal = ""
117 else:
118 out = TermColors.Red
119 normal = TermColors.Normal
120
121 p.text(
122 u'[%2i] ' % self.metadata['engine_id'] +
123 out + u'Out[%2i]: ' % self.execution_count +
124 normal + text_out
125 )
126
100 def _repr_html_(self):
127 def _repr_html_(self):
101 pyout = self.metadata['pyout'] or {'data':{}}
128 pyout = self.metadata['pyout'] or {'data':{}}
102 return pyout['data'].get("text/html")
129 return pyout['data'].get("text/html")
General Comments 0
You need to be logged in to leave comments. Login now