From 78907568be7d3eed934e8dd13005d963ab252835 2016-06-28 20:51:19 From: Matthias Bussonnier Date: 2016-06-28 20:51:19 Subject: [PATCH] Make everyone happy with a neutral colortheme by default. --- diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py index bc3ba77..e97eb7a 100644 --- a/IPython/core/debugger.py +++ b/IPython/core/debugger.py @@ -233,6 +233,10 @@ class Pdb(OldPdb, object): cst['LightBG'].colors.breakpoint_enabled = C.LightRed cst['LightBG'].colors.breakpoint_disabled = C.Red + cst['Neutral'].colors.prompt = C.Blue + cst['Neutral'].colors.breakpoint_enabled = C.LightRed + cst['Neutral'].colors.breakpoint_disabled = C.Red + self.set_colors(color_scheme) # Add a python parser so we can syntax highlight source while @@ -313,7 +317,7 @@ class Pdb(OldPdb, object): except KeyboardInterrupt: pass - def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ', + def print_stack_entry(self,frame_lineno, prompt_prefix='\n-> ', context=None): if context is None: context = self.context diff --git a/IPython/core/excolors.py b/IPython/core/excolors.py index 9d57258..279924b 100644 --- a/IPython/core/excolors.py +++ b/IPython/core/excolors.py @@ -18,7 +18,7 @@ def exception_colors(): """Return a color table with fields for exception reporting. The table is an instance of ColorSchemeTable with schemes added for - 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled + 'Neutral', 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled in. Examples: @@ -127,6 +127,35 @@ def exception_colors(): Normal = C.Normal, )) + ex_colors.add_scheme(ColorScheme( + 'Neutral', + # The color to be used for the top line + topline = C.Red, + + # The colors to be used in the traceback + filename = C.LightGreen, + lineno = C.LightGreen, + name = C.LightPurple, + vName = C.Cyan, + val = C.LightGreen, + em = C.Cyan, + + # Emphasized colors for the last frame of the traceback + normalEm = C.Cyan, + filenameEm = C.Green, + linenoEm = C.Green, + nameEm = C.Purple, + valEm = C.Blue, + + # Colors for printing the exception + excName = C.Red, + #line = C.Brown, # brown often is displayed as yellow + line = C.Red, + caret = C.Normal, + Normal = C.Normal, + )) + + return ex_colors class Deprec(object): diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 3157d7c..481f1e9 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -137,12 +137,10 @@ class SpaceInInput(Exception): pass def get_default_colors(): - if sys.platform=='darwin': - return "LightBG" - elif os.name=='nt': - return 'Linux' - else: - return 'Linux' + "DEPRECATED" + warn('get_default_color is Deprecated, and is `Neutral` on all platforms.', + DeprecationWarning, stacklevel=2) + return 'Neutral' class SeparateUnicode(Unicode): @@ -250,8 +248,8 @@ class InteractiveShell(SingletonConfigurable): get confused with color codes, this capability can be turned off. """ ).tag(config=True) - colors = CaselessStrEnum(('NoColor','LightBG','Linux'), - default_value=get_default_colors(), + colors = CaselessStrEnum(('Neutral', 'NoColor','LightBG','Linux'), + default_value='Neutral', help="Set the color scheme (NoColor, Linux, or LightBG)." ).tag(config=True) colors_force = Bool(False, help= diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py index 1108ffb..692ea32 100644 --- a/IPython/core/magics/basic.py +++ b/IPython/core/magics/basic.py @@ -325,7 +325,7 @@ Currently the magic system has the following functions:""", """ def color_switch_err(name): warn('Error changing %s color schemes.\n%s' % - (name, sys.exc_info()[1])) + (name, sys.exc_info()[1]), stacklevel=2) new_scheme = parameter_s.strip() diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 38ba74e..3e636b3 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -67,6 +67,9 @@ ColorSchemeTable class. Currently the following exist: - LightBG: similar to Linux but swaps dark/light colors to be more readable in light background terminals. + - Neutral: a neutral color scheme that should be readable on both light and + dark background + You can implement other color schemes easily, the syntax is fairly self-explanatory. Please send back new schemes you develop to the author for possible inclusion in future releases. diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 86326a9..a0277e1 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -369,6 +369,7 @@ class TerminalInteractiveShell(InteractiveShell): We need that to add style for prompt ... etc. """ + style_overrides = {} if name == 'legacy': legacy = self.colors.lower() if legacy == 'linux': @@ -376,10 +377,12 @@ class TerminalInteractiveShell(InteractiveShell): style_overrides = _style_overrides_linux elif legacy == 'lightbg': style_overrides = _style_overrides_light_bg - style_cls = get_style_by_name('default') + style_cls = get_style_by_name('pastie') + elif legacy == 'neutral': # The default theme needs to be visible on both a dark background # and a light background, because we can't tell what the terminal # looks like. These tweaks to the default theme help with that. + style_cls = get_style_by_name('default') style_overrides.update({ Token.Number: '#007700', Token.Operator: 'noinherit', @@ -387,6 +390,10 @@ class TerminalInteractiveShell(InteractiveShell): Token.Name.Function: '#2080D0', Token.Name.Class: 'bold #2080D0', Token.Name.Namespace: 'bold #2080D0', + Token.Prompt: '#009900', + Token.PromptNum: '#00ff00 bold', + Token.OutPrompt: '#990000', + Token.OutPromptNum: '#ff0000 bold', }) elif legacy =='nocolor': style_cls=_NoStyle diff --git a/IPython/utils/PyColorize.py b/IPython/utils/PyColorize.py index def4386..1dda22f 100644 --- a/IPython/utils/PyColorize.py +++ b/IPython/utils/PyColorize.py @@ -122,6 +122,32 @@ LinuxColors = ColorScheme( 'normal' : Colors.Normal # color off (usu. Colors.Normal) } ) +NeutralColors = ColorScheme( + 'Neutral',{ + 'header' : Colors.Red, + token.NUMBER : Colors.Cyan, + token.OP : Colors.Blue, + token.STRING : Colors.Blue, + tokenize.COMMENT : Colors.Red, + token.NAME : Colors.Normal, + token.ERRORTOKEN : Colors.Red, + + _KEYWORD : Colors.Green, + _TEXT : Colors.Blue, + + 'in_prompt' : InputTermColors.Blue, + 'in_number' : InputTermColors.LightBlue, + 'in_prompt2' : InputTermColors.Blue, + 'in_normal' : InputTermColors.Normal, # color off (usu. Colors.Normal) + + 'out_prompt' : Colors.Red, + 'out_number' : Colors.LightRed, + + 'normal' : Colors.Normal # color off (usu. Colors.Normal) + } ) + + + LightBGColors = ColorScheme( 'LightBG',{ 'header' : Colors.Red, @@ -132,6 +158,7 @@ LightBGColors = ColorScheme( token.NAME : Colors.Normal, token.ERRORTOKEN : Colors.Red, + _KEYWORD : Colors.Green, _TEXT : Colors.Blue, @@ -147,7 +174,7 @@ LightBGColors = ColorScheme( } ) # Build table of color schemes (needed by the parser) -ANSICodeColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors], +ANSICodeColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors, NeutralColors], _scheme_default) class Parser(Colorable): diff --git a/IPython/utils/colorable.py b/IPython/utils/colorable.py index 77e9dbf..9f7c5ac 100644 --- a/IPython/utils/colorable.py +++ b/IPython/utils/colorable.py @@ -16,7 +16,7 @@ from traitlets.config import Configurable from traitlets import Unicode -available_themes = lambda : [s for s in pygments.styles.get_all_styles()]+['NoColor','LightBG','Linux'] +available_themes = lambda : [s for s in pygments.styles.get_all_styles()]+['NoColor','LightBG','Linux', 'Neutral'] class Colorable(Configurable): """ diff --git a/IPython/utils/tests/test_pycolorize.py b/IPython/utils/tests/test_pycolorize.py index 2a2ff33..6c7f36e 100644 --- a/IPython/utils/tests/test_pycolorize.py +++ b/IPython/utils/tests/test_pycolorize.py @@ -49,7 +49,7 @@ class Bar(Super): def test_loop_colors(): - for scheme in ('Linux', 'NoColor','LightBG'): + for scheme in ('Linux', 'NoColor','LightBG', 'Neutral'): def test_unicode_colorize(): p = Parser()