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