Created
January 14, 2017 02:41
-
-
Save stakemori/68f42ba2f9ac6f6d581e9525c1c41e07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/sage/repl/interpreter.py b/src/sage/repl/interpreter.py | |
index 6c6dfd7..e7cc68c 100644 | |
--- a/src/sage/repl/interpreter.py | |
+++ b/src/sage/repl/interpreter.py | |
@@ -102,12 +102,17 @@ Check that Cython source code appears in tracebacks:: | |
#***************************************************************************** | |
+from __future__ import print_function | |
import os | |
import re | |
+import sys | |
+ | |
+from IPython.core.displayhook import DisplayHook | |
+ | |
from sage.repl.preparse import preparse | |
from sage.repl.prompts import SagePrompts, InterfacePrompts | |
-from traitlets import Bool, Type | |
+from traitlets import Bool, Type, default | |
from sage.env import SAGE_LOCAL | |
from sage.repl.configuration import sage_ipython_config, SAGE_EXTENSION | |
@@ -234,6 +239,21 @@ class SageNotebookInteractiveShell(SageShellOverride, InteractiveShell): | |
backend.get_display_manager().switch_backend(backend, shell=self) | |
+class SageRichPromptDisplayHook(DisplayHook): | |
+ """Subclass of base display hook using coloured prompt""" | |
+ | |
+ prompt_end_newline = True | |
+ | |
+ def write_output_prompt(self): | |
+ sys.stdout.write(self.shell.separate_out) | |
+ if self.do_full_cache: | |
+ tokens = self.shell.prompts.out_prompt_tokens() | |
+ if self.shell.pt_cli: | |
+ self.shell.pt_cli.print_tokens(tokens) | |
+ else: | |
+ print(*(s for t, s in tokens), sep='') | |
+ | |
+ | |
class SageTerminalInteractiveShell(SageShellOverride, TerminalInteractiveShell): | |
""" | |
IPython Shell for the Sage IPython Commandline Interface | |
@@ -261,6 +281,10 @@ class SageTerminalInteractiveShell(SageShellOverride, TerminalInteractiveShell): | |
backend = BackendIPythonCommandline() | |
backend.get_display_manager().switch_backend(backend, shell=self) | |
+ @default('displayhook_class') | |
+ def _displayhook_class_default(self): | |
+ return SageRichPromptDisplayHook | |
+ | |
class SageTestShell(SageShellOverride, TerminalInteractiveShell): | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment