##// END OF EJS Templates
Merge pull request #9371 from jonathanslenders/shell-lexer...
Matthias Bussonnier -
r22200:9fbd7a07 merge
parent child Browse files
Show More
@@ -21,11 +21,12 b' from prompt_toolkit.key_binding.manager import KeyBindingManager'
21 from prompt_toolkit.key_binding.vi_state import InputMode
21 from prompt_toolkit.key_binding.vi_state import InputMode
22 from prompt_toolkit.key_binding.bindings.vi import ViStateFilter
22 from prompt_toolkit.key_binding.bindings.vi import ViStateFilter
23 from prompt_toolkit.keys import Keys
23 from prompt_toolkit.keys import Keys
24 from prompt_toolkit.layout.lexers import Lexer
24 from prompt_toolkit.layout.lexers import PygmentsLexer
25 from prompt_toolkit.layout.lexers import PygmentsLexer
25 from prompt_toolkit.styles import PygmentsStyle
26 from prompt_toolkit.styles import PygmentsStyle
26
27
27 from pygments.styles import get_style_by_name
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 from pygments.token import Token
30 from pygments.token import Token
30
31
31 from .pt_inputhooks import get_inputhook_func
32 from .pt_inputhooks import get_inputhook_func
@@ -50,6 +51,22 b' class IPythonPTCompleter(Completer):'
50 for m in matches:
51 for m in matches:
51 yield Completion(m, start_position=start_pos)
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 class TerminalInteractiveShell(InteractiveShell):
70 class TerminalInteractiveShell(InteractiveShell):
54 colors_force = True
71 colors_force = True
55
72
@@ -192,7 +209,7 b' class TerminalInteractiveShell(InteractiveShell):'
192 style_dict=style_overrides)
209 style_dict=style_overrides)
193
210
194 app = create_prompt_application(multiline=True,
211 app = create_prompt_application(multiline=True,
195 lexer=PygmentsLexer(Python3Lexer if PY3 else PythonLexer),
212 lexer=IPythonPTLexer(),
196 get_prompt_tokens=self.get_prompt_tokens,
213 get_prompt_tokens=self.get_prompt_tokens,
197 get_continuation_tokens=self.get_continuation_tokens,
214 get_continuation_tokens=self.get_continuation_tokens,
198 key_bindings_registry=kbmanager.registry,
215 key_bindings_registry=kbmanager.registry,
General Comments 0
You need to be logged in to leave comments. Login now