##// END OF EJS Templates
-mworking in tab-completion
Omar Andres Zapata Mesa -
Show More
@@ -0,0 +1,44 b''
1 # -*- coding: utf-8 -*-
2 import readline
3 import time
4 import sys
5 stdout = sys.stdout
6 class ClientCompleter2p(object):
7 """Client-side completion machinery.
8
9 How it works: self.complete will be called multiple times, with
10 state=0,1,2,... When state=0 it should compute ALL the completion matches,
11 and then return them for each value of state."""
12
13 def __init__(self, km):
14 self.km = km
15 self.matches = []
16
17 def complete_request(self,text):
18 line = readline.get_line_buffer()
19 msg = self.km.session.send(self.km.xreq_channel.socket,
20 'complete_request',
21 dict(text=text, line=line))
22 msg_matches = None
23 for i in range(5):
24 if self.km.xreq_channel.was_called():
25 msg_xreq = self.km.xreq_channel.get_msg()
26 if msg["header"]['session'] == msg_xreq["parent_header"]['session'] :
27 if msg_xreq["content"]["status"] == 'ok' :
28 if msg_xreq["msg_type"] == "complete_reply" :
29 msg_matches = msg_xreq["content"]["matches"]
30 time.sleep(0.1)
31 return msg_matches
32
33 def complete(self, text, state):
34 if state == 0 :
35 self.matches = self.complete_request(text)
36 # send completion request to kernel
37 # Give the kernel up to 0.5s to respond
38 if self.matches is None:
39 self.matches = []
40 print('WARNING: Kernel timeout on tab completion.')
41 return self.matches
42
43
44 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now