Show More
@@ -21,11 +21,12 b' from prompt_toolkit.key_binding.manager import KeyBindingManager' | |||
|
21 | 21 | from prompt_toolkit.key_binding.vi_state import InputMode |
|
22 | 22 | from prompt_toolkit.key_binding.bindings.vi import ViStateFilter |
|
23 | 23 | from prompt_toolkit.keys import Keys |
|
24 | from prompt_toolkit.layout.lexers import Lexer | |
|
24 | 25 | from prompt_toolkit.layout.lexers import PygmentsLexer |
|
25 | 26 | from prompt_toolkit.styles import PygmentsStyle |
|
26 | 27 | |
|
27 | 28 | from pygments.styles import get_style_by_name |
|
28 | from pygments.lexers import Python3Lexer, PythonLexer | |
|
29 | from pygments.lexers import Python3Lexer, BashLexer, PythonLexer | |
|
29 | 30 | from pygments.token import Token |
|
30 | 31 | |
|
31 | 32 | from .pt_inputhooks import get_inputhook_func |
@@ -50,6 +51,22 b' class IPythonPTCompleter(Completer):' | |||
|
50 | 51 | for m in matches: |
|
51 | 52 | yield Completion(m, start_position=start_pos) |
|
52 | 53 | |
|
54 | ||
|
55 | class IPythonPTLexer(Lexer): | |
|
56 | """ | |
|
57 | Wrapper around PythonLexer and BashLexer. | |
|
58 | """ | |
|
59 | def __init__(self): | |
|
60 | self.python_lexer = PygmentsLexer(Python3Lexer if PY3 else PythonLexer) | |
|
61 | self.shell_lexer = PygmentsLexer(BashLexer) | |
|
62 | ||
|
63 | def lex_document(self, cli, document): | |
|
64 | if document.text.startswith('!'): | |
|
65 | return self.shell_lexer.lex_document(cli, document) | |
|
66 | else: | |
|
67 | return self.python_lexer.lex_document(cli, document) | |
|
68 | ||
|
69 | ||
|
53 | 70 | class TerminalInteractiveShell(InteractiveShell): |
|
54 | 71 | colors_force = True |
|
55 | 72 | |
@@ -192,7 +209,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
192 | 209 | style_dict=style_overrides) |
|
193 | 210 | |
|
194 | 211 | app = create_prompt_application(multiline=True, |
|
195 |
lexer= |
|
|
212 | lexer=IPythonPTLexer(), | |
|
196 | 213 | get_prompt_tokens=self.get_prompt_tokens, |
|
197 | 214 | get_continuation_tokens=self.get_continuation_tokens, |
|
198 | 215 | key_bindings_registry=kbmanager.registry, |
General Comments 0
You need to be logged in to leave comments.
Login now