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 +# +# 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, ''), + ] +