1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
diff --git a/src/sage/repl/interpreter.py b/src/sage/repl/interpreter.py
index ef8724d..6896985 100644
--- a/src/sage/repl/interpreter.py
+++ b/src/sage/repl/interpreter.py
@@ -103,6 +103,7 @@ import os
import re
import sys
from sage.repl.preparse import preparse
+from sage.repl.prompts import SagePrompts, InterfacePrompts
from traitlets.config.loader import Config
from traitlets import Bool, Type
@@ -371,11 +372,6 @@ class SageTestShell(SageShellOverride, TerminalInteractiveShell):
###################################################################
DEFAULT_SAGE_CONFIG = Config(
- PromptManager = Config(
- in_template = 'sage: ',
- in2_template = '....: ',
- justify = False,
- out_template = ''),
TerminalIPythonApp = Config(
display_banner = False,
verbose_crash = True,
@@ -383,6 +379,7 @@ DEFAULT_SAGE_CONFIG = Config(
shell_class = SageTerminalInteractiveShell,
),
InteractiveShell = Config(
+ prompts_class = SagePrompts,
ast_node_interactivity = 'all',
colors = 'LightBG' if sys.stdout.isatty() else 'NoColor',
confirm_exit = False,
@@ -616,13 +613,11 @@ def interface_shell_embed(interface):
cfg = copy.deepcopy(get_ipython().config)
except NameError:
cfg = copy.deepcopy(DEFAULT_SAGE_CONFIG)
- cfg.PromptManager['in_template'] = interface.name() + ': '
- cfg.PromptManager['in2_template'] = len(interface.name())*'.' + ': '
-
ipshell = InteractiveShellEmbed(config=cfg,
banner1='\n --> Switching to %s <--\n\n'%interface,
exit_msg = '\n --> Exiting back to Sage <--\n')
ipshell.interface = interface
+ ipshell.prompts = InterfacePrompts(interface.name())
while ipshell.prefilter_manager.transformers:
ipshell.prefilter_manager.transformers.pop()
diff --git a/src/sage/repl/prompts.py b/src/sage/repl/prompts.py
new file mode 100644
index 0000000..69f8cdd
--- /dev/null
+++ b/src/sage/repl/prompts.py
@@ -0,0 +1,67 @@
+r"""
+Sage Commandline Prompts
+"""
+
+#*****************************************************************************
+# Copyright (C) 2016 Volker Braun <vbraun.name@gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+# http://www.gnu.org/licenses/
+#*****************************************************************************
+
+from pygments.token import Token
+from IPython.terminal.prompts import Prompts
+
+
+class SagePrompts(Prompts):
+
+ def in_prompt_tokens(self, cli=None):
+ return [
+ (Token.Prompt, 'sage: '),
+ ]
+
+ def continuation_prompt_tokens(self, cli=None, width=None):
+ return [
+ (Token.Prompt, '....: '),
+ ]
+
+ def rewrite_prompt_tokens(self):
+ return [
+ (Token.Prompt, '----> '),
+ ]
+
+ def out_prompt_tokens(self):
+ return [
+ (Token.OutPrompt, ''),
+ ]
+
+
+class InterfacePrompts(Prompts):
+
+ def __init__(self, interface_name):
+ self.__name = interface_name
+ self.__width = len(interface_name)
+
+ def in_prompt_tokens(self, cli=None):
+ return [
+ (Token.Prompt, self.__name + ': '),
+ ]
+
+ def continuation_prompt_tokens(self, cli=None, width=None):
+ return [
+ (Token.Prompt, '.' * self.__width + ': '),
+ ]
+
+ def rewrite_prompt_tokens(self):
+ return [
+ (Token.Prompt, '-' * self.__width + '> '),
+ ]
+
+ def out_prompt_tokens(self):
+ return [
+ (Token.OutPrompt, ''),
+ ]
+
|