From 6c39ad1e586157c74846d604573a5013c631ef46 2015-11-08 05:52:58 From: Matthias Bussonnier Date: 2015-11-08 05:52:58 Subject: [PATCH] Consolidate color scheme localisations. --- diff --git a/IPython/core/prompts.py b/IPython/core/prompts.py index 18c04de..eec8ed6 100644 --- a/IPython/core/prompts.py +++ b/IPython/core/prompts.py @@ -33,6 +33,8 @@ from IPython.core import release from IPython.utils import coloransi, py3compat from traitlets import (Unicode, Instance, Dict, Bool, Int) +from IPython.utils.PyColorize import LightBGColors, LinuxColors, NoColor + #----------------------------------------------------------------------------- # Color schemes for prompts #----------------------------------------------------------------------------- @@ -42,42 +44,6 @@ Colors = coloransi.TermColors # just a shorthand color_lists = dict(normal=Colors(), inp=InputColors(), nocolor=coloransi.NoColors()) -PColNoColors = coloransi.ColorScheme( - 'NoColor', - in_prompt = InputColors.NoColor, # Input prompt - in_number = InputColors.NoColor, # Input prompt number - in_prompt2 = InputColors.NoColor, # Continuation prompt - in_normal = InputColors.NoColor, # color off (usu. Colors.Normal) - - out_prompt = Colors.NoColor, # Output prompt - out_number = Colors.NoColor, # Output prompt number - - normal = Colors.NoColor # color off (usu. Colors.Normal) - ) - -# make some schemes as instances so we can copy them for modification easily: -PColLinux = coloransi.ColorScheme( - 'Linux', - in_prompt = InputColors.Green, - in_number = InputColors.LightGreen, - in_prompt2 = InputColors.Green, - in_normal = InputColors.Normal, # color off (usu. Colors.Normal) - - out_prompt = Colors.Red, - out_number = Colors.LightRed, - - normal = Colors.Normal - ) - -# Slightly modified Linux for light backgrounds -PColLightBG = PColLinux.copy('LightBG') - -PColLightBG.colors.update( - in_prompt = InputColors.Blue, - in_number = InputColors.LightBlue, - in_prompt2 = InputColors.Blue -) - #----------------------------------------------------------------------------- # Utilities #----------------------------------------------------------------------------- @@ -104,7 +70,7 @@ class LazyEvaluate(object): return format(self(), format_spec) def multiple_replace(dict, text): - """ Replace in 'text' all occurences of any key in the given + """ Replace in 'text' all occurrences of any key in the given dictionary by its corresponding value. Returns the new string.""" # Function by Xavier Defrang, originally found at: @@ -334,8 +300,8 @@ class PromptManager(Configurable): super(PromptManager, self).__init__(shell=shell, **kwargs) # Prepare colour scheme table - self.color_scheme_table = coloransi.ColorSchemeTable([PColNoColors, - PColLinux, PColLightBG], self.color_scheme) + self.color_scheme_table = coloransi.ColorSchemeTable([NoColor, + LinuxColors, LightBGColors], self.color_scheme) self._formatter = UserNSFormatter(shell) # Prepare templates & numbers of invisible characters @@ -381,7 +347,7 @@ class PromptManager(Configurable): else: colors = color_lists['inp'] colors.number, colors.prompt, colors.normal = \ - scheme.in_number, scheme.in_prompt, scheme.in_normal + scheme.in_number, scheme.in_prompt, scheme.normal if name=='in2': colors.prompt = scheme.in_prompt2 else: diff --git a/IPython/utils/PyColorize.py b/IPython/utils/PyColorize.py index aec5231..639831a 100644 --- a/IPython/utils/PyColorize.py +++ b/IPython/utils/PyColorize.py @@ -84,7 +84,14 @@ NoColor = ColorScheme( _KEYWORD : Colors.NoColor, _TEXT : Colors.NoColor, - 'normal' : Colors.NoColor # color off (usu. Colors.Normal) + 'in_prompt' : InputTermColors.NoColor, # Input prompt + 'in_number' : InputTermColors.NoColor, # Input prompt number + 'in_prompt2' : InputTermColors.NoColor, # Continuation prompt + + 'out_prompt' : InputTermColors.NoColor, # Output prompt + 'out_number' : InputTermColors.NoColor, # Output prompt number + + 'normal' : InputTermColors.NoColor # color off (usu. Colors.Normal) } ) LinuxColors = ColorScheme( @@ -99,7 +106,14 @@ LinuxColors = ColorScheme( _KEYWORD : Colors.LightGreen, _TEXT : Colors.Yellow, - 'normal' : Colors.Normal # color off (usu. Colors.Normal) + 'in_prompt' : InputTermColors.Green, + 'in_number' : InputTermColors.LightGreen, + 'in_prompt2' : InputTermColors.Green, + + 'out_prompt' : InputTermColors.Red, + 'out_number' : InputTermColors.LightRed, + + 'normal' : InputTermColors.Normal # color off (usu. Colors.Normal) } ) LightBGColors = ColorScheme( @@ -114,7 +128,14 @@ LightBGColors = ColorScheme( _KEYWORD : Colors.Green, _TEXT : Colors.Blue, - 'normal' : Colors.Normal # color off (usu. Colors.Normal) + 'in_prompt' : InputTermColors.Blue, + 'in_number' : InputTermColors.LightBlue, + 'in_prompt2' : InputTermColors.Blue, + + 'out_prompt' : InputTermColors.Red, + 'out_number' : InputTermColors.LightRed, + + 'normal' : InputTermColors.Normal # color off (usu. Colors.Normal) } ) # Build table of color schemes (needed by the parser) diff --git a/IPython/utils/coloransi.py b/IPython/utils/coloransi.py index b879f7c..bc8e837 100644 --- a/IPython/utils/coloransi.py +++ b/IPython/utils/coloransi.py @@ -132,7 +132,7 @@ class ColorSchemeTable(dict): active_scheme_name -> obvious active_colors -> actual color table of the active scheme""" - def __init__(self,scheme_list=None,default_scheme=''): + def __init__(self, scheme_list=None, default_scheme=''): """Create a table of color schemes. The table can be created empty and manually filled or it can be