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