##// END OF EJS Templates
Use new prompt machinery to generate Out prompts
Thomas Kluyver -
Show More
@@ -113,7 +113,7 b' class DisplayHook(Configurable):'
113 """
113 """
114 # Use write, not print which adds an extra space.
114 # Use write, not print which adds an extra space.
115 sys.stdout.write(self.shell.separate_out)
115 sys.stdout.write(self.shell.separate_out)
116 outprompt = self.shell.prompt_manager.render('out')
116 outprompt = 'Out[{}]: '.format(self.shell.execution_count)
117 if self.do_full_cache:
117 if self.do_full_cache:
118 sys.stdout.write(outprompt)
118 sys.stdout.write(outprompt)
119
119
@@ -1,4 +1,7 b''
1 from pygments.token import Token
1 from pygments.token import Token
2 import sys
3
4 from IPython.core.displayhook import DisplayHook
2
5
3 class Prompts(object):
6 class Prompts(object):
4 def __init__(self, shell):
7 def __init__(self, shell):
@@ -34,3 +37,14 b' class Prompts(object):'
34 (Token.OutPromptNum, str(self.shell.execution_count)),
37 (Token.OutPromptNum, str(self.shell.execution_count)),
35 (Token.OutPrompt, ']: '),
38 (Token.OutPrompt, ']: '),
36 ]
39 ]
40
41 class RichPromptDisplayHook(DisplayHook):
42 """Subclass of base display hook using coloured prompt"""
43 def write_output_prompt(self):
44 sys.stdout.write(self.shell.separate_out)
45 if self.do_full_cache:
46 tokens = self.shell.prompts.out_prompt_tokens()
47 if self.shell.pt_cli:
48 self.shell.pt_cli.print_tokens(tokens)
49 else:
50 print(*(s for t, s in tokens), sep='')
@@ -29,7 +29,7 b' from pygments.token import Token'
29 from .debugger import TerminalPdb, Pdb
29 from .debugger import TerminalPdb, Pdb
30 from .pt_inputhooks import get_inputhook_func
30 from .pt_inputhooks import get_inputhook_func
31 from .interactiveshell import get_default_editor, TerminalMagics
31 from .interactiveshell import get_default_editor, TerminalMagics
32 from .prompts import Prompts
32 from .prompts import Prompts, RichPromptDisplayHook
33 from .ptutils import IPythonPTCompleter, IPythonPTLexer
33 from .ptutils import IPythonPTCompleter, IPythonPTLexer
34
34
35 _use_simple_prompt = 'IPY_TEST_SIMPLE_PROMPT' in os.environ or not sys.stdin.isatty()
35 _use_simple_prompt = 'IPY_TEST_SIMPLE_PROMPT' in os.environ or not sys.stdin.isatty()
@@ -104,7 +104,10 b' class TerminalInteractiveShell(InteractiveShell):'
104
104
105 def _prompts_default(self):
105 def _prompts_default(self):
106 return Prompts(self)
106 return Prompts(self)
107
107
108 def _displayhook_class_default(self):
109 return RichPromptDisplayHook
110
108 term_title = Bool(True,
111 term_title = Bool(True,
109 help="Automatically set the terminal title"
112 help="Automatically set the terminal title"
110 ).tag(config=True)
113 ).tag(config=True)
@@ -228,6 +231,8 b' class TerminalInteractiveShell(InteractiveShell):'
228 style_overrides = {
231 style_overrides = {
229 Token.Prompt: '#009900',
232 Token.Prompt: '#009900',
230 Token.PromptNum: '#00ff00 bold',
233 Token.PromptNum: '#00ff00 bold',
234 Token.OutPrompt: '#990000',
235 Token.OutPromptNum: '#ff0000 bold',
231 }
236 }
232 if name == 'default':
237 if name == 'default':
233 style_cls = get_style_by_name('default')
238 style_cls = get_style_by_name('default')
General Comments 0
You need to be logged in to leave comments. Login now