##// END OF EJS Templates
use rlineimpl in terminal.console
MinRK -
Show More
@@ -1,58 +1,58 b''
1 1 """Adapt readline completer interface to make ZMQ request.
2 2 """
3 3 # -*- coding: utf-8 -*-
4 import readline
5 4 try:
6 5 from queue import Empty # Py 3
7 6 except ImportError:
8 7 from Queue import Empty # Py 2
9 8
10 9 from IPython.config import Configurable
11 10 from IPython.core.completer import IPCompleter
12 11 from IPython.utils.traitlets import Float
12 import IPython.utils.rlineimpl as readline
13 13
14 14 class ZMQCompleter(IPCompleter):
15 15 """Client-side completion machinery.
16 16
17 17 How it works: self.complete will be called multiple times, with
18 18 state=0,1,2,... When state=0 it should compute ALL the completion matches,
19 19 and then return them for each value of state."""
20 20
21 21 timeout = Float(5.0, config=True, help='timeout before completion abort')
22 22
23 23 def __init__(self, shell, client, config=None):
24 24 super(ZMQCompleter,self).__init__(config=config)
25 25
26 26 self.shell = shell
27 27 self.client = client
28 28 self.matches = []
29 29
30 30 def complete_request(self,text):
31 31 line = readline.get_line_buffer()
32 32 cursor_pos = readline.get_endidx()
33 33
34 34 # send completion request to kernel
35 35 # Give the kernel up to 0.5s to respond
36 36 msg_id = self.client.shell_channel.complete(text=text, line=line,
37 37 cursor_pos=cursor_pos)
38 38
39 39 msg = self.client.shell_channel.get_msg(timeout=self.timeout)
40 40 if msg['parent_header']['msg_id'] == msg_id:
41 41 return msg["content"]["matches"]
42 42 return []
43 43
44 44 def rlcomplete(self, text, state):
45 45 if state == 0:
46 46 try:
47 47 self.matches = self.complete_request(text)
48 48 except Empty:
49 49 #print('WARNING: Kernel timeout on tab completion.')
50 50 pass
51 51
52 52 try:
53 53 return self.matches[state]
54 54 except IndexError:
55 55 return None
56 56
57 57 def complete(self, text, line, cursor_pos=None):
58 58 return self.rlcomplete(text, 0)
General Comments 0
You need to be logged in to leave comments. Login now