Show More
@@ -1,5 +1,6 b'' | |||
|
1 | 1 | from IPython.core.interactiveshell import InteractiveShell |
|
2 | 2 | |
|
3 | from prompt_toolkit.completion import Completer, Completion | |
|
3 | 4 | from prompt_toolkit.history import InMemoryHistory |
|
4 | 5 | from prompt_toolkit.shortcuts import create_prompt_application |
|
5 | 6 | from prompt_toolkit.interface import CommandLineInterface |
@@ -11,6 +12,21 b' from pygments.lexers import Python3Lexer' | |||
|
11 | 12 | from pygments.token import Token |
|
12 | 13 | |
|
13 | 14 | |
|
15 | class IPythonPTCompleter(Completer): | |
|
16 | """Adaptor to provide IPython completions to prompt_toolkit""" | |
|
17 | def __init__(self, ipy_completer): | |
|
18 | self.ipy_completer = ipy_completer | |
|
19 | ||
|
20 | def get_completions(self, document, complete_event): | |
|
21 | used, matches = self.ipy_completer.complete( | |
|
22 | line_buffer=document.current_line, | |
|
23 | cursor_pos=document.cursor_position_col | |
|
24 | ) | |
|
25 | start_pos = -len(used) | |
|
26 | for m in matches: | |
|
27 | yield Completion(m, start_position=start_pos) | |
|
28 | ||
|
29 | ||
|
14 | 30 | class PTInteractiveShell(InteractiveShell): |
|
15 | 31 | pt_cli = None |
|
16 | 32 | |
@@ -57,6 +73,7 b' class PTInteractiveShell(InteractiveShell):' | |||
|
57 | 73 | get_prompt_tokens=self.get_prompt_tokens, |
|
58 | 74 | key_bindings_registry=kbmanager.registry, |
|
59 | 75 | history=history, |
|
76 | completer=IPythonPTCompleter(self.Completer), | |
|
60 | 77 | ) |
|
61 | 78 | |
|
62 | 79 | self.pt_cli = CommandLineInterface(app) |
@@ -83,4 +100,4 b' class PTInteractiveShell(InteractiveShell):' | |||
|
83 | 100 | |
|
84 | 101 | |
|
85 | 102 | if __name__ == '__main__': |
|
86 | PTInteractiveShell().interact() | |
|
103 | PTInteractiveShell.instance().interact() |
General Comments 0
You need to be logged in to leave comments.
Login now