##// END OF EJS Templates
Nicer prompt formatting in zmqterminal, and use print_function.
Thomas Kluyver -
Show More
@@ -15,6 +15,7 b' For more details, see the ipython-zmq design'
15 15 #-----------------------------------------------------------------------------
16 16 # Imports
17 17 #-----------------------------------------------------------------------------
18 from __future__ import print_function
18 19
19 20 import __builtin__
20 21 import sys
@@ -79,9 +80,10 b' class Frontend(object):'
79 80 """
80 81
81 82 try:
82 self._splitter.push(raw_input('In[%i]:'%self.prompt_count+self.code))
83 print()
84 self._splitter.push(raw_input(' In[%i]: '%self.prompt_count+self.code))
83 85 while self._splitter.push_accepts_more():
84 self.code = raw_input('.....:'+' '*self._splitter.indent_spaces)
86 self.code = raw_input(' .....: '+' '*self._splitter.indent_spaces)
85 87 self._splitter.push(' '*self._splitter.indent_spaces+self.code)
86 88 self._execute(self._splitter.source,False)
87 89 self._splitter.reset()
@@ -128,17 +130,12 b' class Frontend(object):'
128 130 if msg_xreq["parent_header"]["msg_id"] == msg_id:
129 131 if msg_xreq["content"]["status"] == 'ok' :
130 132 self.handle_sub_channel()
131 self.prompt_count = msg_xreq["content"]["execution_count"] + 1
132 133
133 else:
134 etb = msg_xreq["content"]["traceback"]
135 print >> sys.stderr, etb[0]
136 try: # These bits aren't there for a SyntaxError
137 print >> sys.stderr, etb[1]
138 print >> sys.stderr, etb[2]
139 except IndexError:
140 pass
141 self.prompt_count = msg_xreq["content"]["execution_count"] + 1
134 elif msg_xreq["content"]["status"] == 'error':
135 for frame in msg_xreq["content"]["traceback"]:
136 print(frame, file=sys.stderr)
137
138 self.prompt_count = msg_xreq["content"]["execution_count"] + 1
142 139
143 140
144 141 def handle_sub_channel(self):
@@ -160,14 +157,16 b' class Frontend(object):'
160 157
161 158 elif sub_msg['msg_type'] == 'stream' :
162 159 if sub_msg["content"]["name"] == "stdout":
163 print >> sys.stdout, sub_msg["content"]["data"]
160 print(sub_msg["content"]["data"], file=sys.stdout, end="")
164 161 sys.stdout.flush()
165 162 elif sub_msg["content"]["name"] == "stderr" :
166 print >> sys.stderr, sub_msg["content"]["data"]
163 print(sub_msg["content"]["data"], file=sys.stderr, end="")
167 164 sys.stderr.flush()
168 165
169 166 elif sub_msg['msg_type'] == 'pyout' :
170 print >> sys.stdout,"Out[%i]:"%sub_msg["content"]["execution_count"], sub_msg["content"]["data"]["text/plain"]
167 print("Out[%i]:"%sub_msg["content"]["execution_count"],
168 sub_msg["content"]["data"]["text/plain"],
169 file=sys.stdout)
171 170 sys.stdout.flush()
172 171
173 172 def handle_rep_channel(self, timeout=0.1):
General Comments 0
You need to be logged in to leave comments. Login now