From 4182704ceddd5a445f33e47fd6d5e51e02f7ea2d Mon Sep 17 00:00:00 2001 From: Omar Andres Zapata Mesa Date: Sun, 3 Apr 2011 20:30:36 -0500 Subject: [PATCH] -mworking in tab-completion --- IPython/frontend/terminal/completer.py | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 IPython/frontend/terminal/completer.py diff --git a/IPython/frontend/terminal/completer.py b/IPython/frontend/terminal/completer.py new file mode 100644 index 00000000000..a19e2f39840 --- /dev/null +++ b/IPython/frontend/terminal/completer.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +import readline +import time +import sys +stdout = sys.stdout +class ClientCompleter2p(object): + """Client-side completion machinery. + + How it works: self.complete will be called multiple times, with + state=0,1,2,... When state=0 it should compute ALL the completion matches, + and then return them for each value of state.""" + + def __init__(self, km): + self.km = km + self.matches = [] + + def complete_request(self,text): + line = readline.get_line_buffer() + msg = self.km.session.send(self.km.xreq_channel.socket, + 'complete_request', + dict(text=text, line=line)) + msg_matches = None + for i in range(5): + if self.km.xreq_channel.was_called(): + msg_xreq = self.km.xreq_channel.get_msg() + if msg["header"]['session'] == msg_xreq["parent_header"]['session'] : + if msg_xreq["content"]["status"] == 'ok' : + if msg_xreq["msg_type"] == "complete_reply" : + msg_matches = msg_xreq["content"]["matches"] + time.sleep(0.1) + return msg_matches + + def complete(self, text, state): + if state == 0 : + self.matches = self.complete_request(text) + # send completion request to kernel + # Give the kernel up to 0.5s to respond + if self.matches is None: + self.matches = [] + print('WARNING: Kernel timeout on tab completion.') + return self.matches + + + \ No newline at end of file