##// END OF EJS Templates
working in tab completion
Omar Andres Zapata Mesa -
Show More
@@ -67,13 +67,12 b' class Frontend(object):'
67 self.request_socket = self.km.xreq_channel.socket
67 self.request_socket = self.km.xreq_channel.socket
68 self.sub_socket = self.km.sub_channel.socket
68 self.sub_socket = self.km.sub_channel.socket
69 self.reply_socket = self.km.rep_channel.socket
69 self.reply_socket = self.km.rep_channel.socket
70
70 self.msg_header = self.km.session.msg_header()
71
71
72 self.completer = completer.ClientCompleter(self,self.session,self.request_socket)
72 self.completer = completer.ClientCompleter(self,self.session,self.request_socket)
73 rlcompleter.readline.parse_and_bind("tab: complete")
73 rlcompleter.readline.parse_and_bind('tab: complete')
74 rlcompleter.readline.parse_and_bind('set show-all-if-ambiguous on')
74 rlcompleter.readline.parse_and_bind('set show-all-if-ambiguous on')
75 rlcompleter.Completer = self.completer.complete
75 rlcompleter.readline.set_completer(self.completer.complete)
76
77 history_path = os.path.expanduser('~/.ipython/history')
76 history_path = os.path.expanduser('~/.ipython/history')
78 if os.path.isfile(history_path):
77 if os.path.isfile(history_path):
79 rlcompleter.readline.read_history_file(history_path)
78 rlcompleter.readline.read_history_file(history_path)
@@ -82,26 +81,31 b' class Frontend(object):'
82
81
83 self.messages = {}
82 self.messages = {}
84
83
85 self.prompt_count = self.km.xreq_channel.execute('', silent=True)
84 self.prompt_count = 0 #self.km.xreq_channel.execute('', silent=True)
86 self.backgrounded = 0
85 self.backgrounded = 0
87 self._splitter = InputSplitter()
86 self._splitter = InputSplitter()
88
87 self.code = ""
88
89 def interact(self):
89 def interact(self):
90 """ let you get input from console using inputsplitter, then
90 """ let you get input from console using inputsplitter, then
91 while you enter code it can indent and set index id to any input
91 while you enter code it can indent and set index id to any input
92
92
93 """
93 """
94
94 try:
95 try:
95 self._splitter.push(raw_input('In[%i]:'%self.prompt_count))
96 self._splitter.push(raw_input('In[%i]:'%self.prompt_count+self.code))
96 while self._splitter.push_accepts_more():
97 while self._splitter.push_accepts_more():
97 code = raw_input('.....:'+' '*self._splitter.indent_spaces)
98 self.code = raw_input('.....:'+' '*self._splitter.indent_spaces)
98 self._splitter.push(' '*self._splitter.indent_spaces+code)
99 self._splitter.push(' '*self._splitter.indent_spaces+self.code)
100 self._execute(self._splitter.source,False)
101 self._splitter.reset()
99 except KeyboardInterrupt:
102 except KeyboardInterrupt:
100 print('\nKeyboardInterrupt\n')
103 print('\nKeyboardInterrupt\n')
101 pass
104 pass
102 else:
105 #else:
103 self._execute(self._splitter.source,False)
106 #self._execute(self._splitter.source,False)
104 self._splitter.reset()
107 #self._splitter.reset()
108
105
109
106 def start(self):
110 def start(self):
107 """ init a bucle that call interact method to get code.
111 """ init a bucle that call interact method to get code.
@@ -128,28 +132,24 b' class Frontend(object):'
128 See parent class :meth:`execute` docstring for full details.
132 See parent class :meth:`execute` docstring for full details.
129 """
133 """
130 msg_id = self.km.xreq_channel.execute(source, hidden)
134 msg_id = self.km.xreq_channel.execute(source, hidden)
131 self.handle_xrep_channel()
135 #timer to debug
132
136 time.sleep(0.5)
133 # while self.km.rep_channel.was_called() :
134 # msg_rep = self.km.rep_channel.get_msg()
135 # print "rep hadler not implemented yet"
136
137
138
139 # self.km.xreq_channel.execute('', silent=True)
140 def handle_xrep_channel(self):
141 msg_header = self.km.session.msg_header()
142 if self.km.xreq_channel.was_called():
137 if self.km.xreq_channel.was_called():
143 msg_xreq = self.km.xreq_channel.get_msg()
138 self.msg_xreq = self.km.xreq_channel.get_msg()
144 if msg_header["session"] == msg_xreq["parent_header"]["session"] :
139 print self.msg_xreq
145 if msg_xreq["content"]["status"] == 'ok' :
140 if self.msg_header["session"] == self.msg_xreq["parent_header"]["session"] :
146 self.handle_sub_channel()
141 if self.msg_xreq["content"]["status"] == 'ok' :
147
142 if self.msg_xreq["msg_type"] == "complete_reply" :
143 print self.msg_xreq["content"]["matches"]
144
145 if self.msg_xreq["msg_type"] == "execute_reply" :
146 self.prompt_count = self.msg_xreq["content"]["execution_count"]
147
148 self.handle_sub_channel()
148 else:
149 else:
149 print >> sys.stderr, "Error executing: ", source
150 print >> sys.stderr, "Error executing: ", source
150 print >> sys.stderr, "Status in the kernel: ", msg_xreq["content"]["status"]
151 print >> sys.stderr, "Status in the kernel: ", self.msg_xreq["content"]["status"]
151 self.prompt_count = msg_xreq["content"]["execution_count"]
152 #print msg_xreq
152 print msg_xreq
153 else:
153 else:
154 print >> sys.stderr, "Kernel is busy!"
154 print >> sys.stderr, "Kernel is busy!"
155
155
@@ -168,7 +168,7 b' class Frontend(object):'
168 """
168 """
169 while self.km.sub_channel.was_called():
169 while self.km.sub_channel.was_called():
170 sub_msg = self.km.sub_channel.get_msg()
170 sub_msg = self.km.sub_channel.get_msg()
171 if msg_header["username"] == sub_msg['parent_header']['username'] and self.km.session.session == sub_msg['parent_header']['session']:
171 if self.msg_header["username"] == sub_msg['parent_header']['username'] and self.km.session.session == sub_msg['parent_header']['session']:
172 if sub_msg['msg_type'] == 'status' :
172 if sub_msg['msg_type'] == 'status' :
173 if sub_msg["content"]["execution_state"] == "busy" :
173 if sub_msg["content"]["execution_state"] == "busy" :
174 pass
174 pass
@@ -177,12 +177,13 b' class Frontend(object):'
177 if sub_msg["content"]["name"] == "stdout":
177 if sub_msg["content"]["name"] == "stdout":
178 print >> sys.stdout,sub_msg["content"]["data"]
178 print >> sys.stdout,sub_msg["content"]["data"]
179 sys.stdout.flush()
179 sys.stdout.flush()
180 if sub_msg["content"]["name"] == "stderr" :
180 if sub_msg["content"]["name"] == "stderr" :
181 print >> sys.stderr,sub_msg["content"]["data"]
181 print >> sys.stderr,sub_msg["content"]["data"]
182 sys.stderr.flush()
182 sys.stderr.flush()
183
183
184 if sub_msg['msg_type'] == 'pyout' :
184 if sub_msg['msg_type'] == 'pyout' :
185 print >> sys.stdout,"Out[%i]:"%sub_msg["content"]["execution_count"], sub_msg["content"]["data"]
185 print >> sys.stdout,"Out[%i]:"%sub_msg["content"]["execution_count"], sub_msg["content"]["data"]
186 #print >> sys.stdout,"Out[%i]:"%self.msg_xreq["content"]["execution_count"], sub_msg["content"]["data"]
186 sys.stdout.flush()
187 sys.stdout.flush()
187
188
188
189
General Comments 0
You need to be logged in to leave comments. Login now