##// END OF EJS Templates
Add __future__ import for prompts module
Thomas Kluyver -
Show More
@@ -1,53 +1,56 b''
1 """Terminal input and output prompts."""
2 from __future__ import print_function
3
1 4 from pygments.token import Token
2 5 import sys
3 6
4 7 from IPython.core.displayhook import DisplayHook
5 8
6 9 class Prompts(object):
7 10 def __init__(self, shell):
8 11 self.shell = shell
9 12
10 13 def in_prompt_tokens(self, cli=None):
11 14 return [
12 15 (Token.Prompt, 'In ['),
13 16 (Token.PromptNum, str(self.shell.execution_count)),
14 17 (Token.Prompt, ']: '),
15 18 ]
16 19
17 20 def _width(self):
18 21 in_tokens = self.in_prompt_tokens()
19 22 return sum(len(s) for (t, s) in in_tokens)
20 23
21 24 def continuation_prompt_tokens(self, cli=None, width=None):
22 25 if width is None:
23 26 width = self._width()
24 27 return [
25 28 (Token.Prompt, (' ' * (width - 5)) + '...: '),
26 29 ]
27 30
28 31 def rewrite_prompt_tokens(self):
29 32 width = self._width()
30 33 return [
31 34 (Token.Prompt, ('-' * (width - 2)) + '> '),
32 35 ]
33 36
34 37 def out_prompt_tokens(self):
35 38 return [
36 39 (Token.OutPrompt, 'Out['),
37 40 (Token.OutPromptNum, str(self.shell.execution_count)),
38 41 (Token.OutPrompt, ']: '),
39 42 ]
40 43
41 44 class RichPromptDisplayHook(DisplayHook):
42 45 """Subclass of base display hook using coloured prompt"""
43 46 def write_output_prompt(self):
44 47 sys.stdout.write(self.shell.separate_out)
45 48 self.prompt_end_newline = False
46 49 if self.do_full_cache:
47 50 tokens = self.shell.prompts.out_prompt_tokens()
48 51 if tokens and tokens[-1][1].endswith('\n'):
49 52 self.prompt_end_newline = True
50 53 if self.shell.pt_cli:
51 54 self.shell.pt_cli.print_tokens(tokens)
52 55 else:
53 56 print(*(s for t, s in tokens), sep='')
General Comments 0
You need to be logged in to leave comments. Login now