<s> """<STR_LIT>""" <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> import os <EOL> from IPython . utils . ipstruct import Struct <EOL> def make_color_table ( in_class ) : <EOL> """<STR_LIT>""" <EOL> color_templates = ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ) <EOL> for name , value in color_templates : <EOL> setattr ( in_class , name , in_class . _base % value ) <EOL> class TermColors : <EOL> """<STR_LIT>""" <EOL> NoColor = '<STR_LIT>' <EOL> Normal = '<STR_LIT>' <EOL> _base = '<STR_LIT>' <EOL> make_color_table ( TermColors ) <EOL> class InputTermColors : <EOL> """<STR_LIT>""" <EOL> NoColor = '<STR_LIT>' <EOL> if os . name == '<STR_LIT>' and os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT>' : <EOL> Normal = '<STR_LIT>' <EOL> _base = '<STR_LIT>' <EOL> else : <EOL> Normal = '<STR_LIT>' <EOL> _base = '<STR_LIT>' <EOL> make_color_table ( InputTermColors ) <EOL> class ColorScheme : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , __scheme_name_ , colordict = None , ** colormap ) : <EOL> self . name = __scheme_name_ <EOL> if colordict is None : <EOL> self . colors = Struct ( ** colormap ) <EOL> else : <EOL> self . colors = Struct ( colordict ) <EOL> def copy ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> name = self . name <EOL> return ColorScheme ( name , self . colors . dict ( ) ) <EOL> class ColorSchemeTable ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , scheme_list = None , default_scheme = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> self . active_scheme_name = '<STR_LIT>' <EOL> self . active_colors = None <EOL> if scheme_list : <EOL> if default_scheme == '<STR_LIT>' : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> for scheme in scheme_list : <EOL> self . add_scheme ( scheme ) <EOL> self . set_active_scheme ( default_scheme ) <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return ColorSchemeTable ( list ( self . values ( ) ) , self . active_scheme_name ) <EOL> def add_scheme ( self , new_scheme ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( new_scheme , ColorScheme ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self [ new_scheme . name ] = new_scheme <EOL> def set_active_scheme ( self , scheme , case_sensitive = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> scheme_names = list ( self . keys ( ) ) <EOL> if case_sensitive : <EOL> valid_schemes = scheme_names <EOL> scheme_test = scheme <EOL> else : <EOL> valid_schemes = [ s . lower ( ) for s in scheme_names ] <EOL> scheme_test = scheme . lower ( ) <EOL> try : <EOL> scheme_idx = valid_schemes . index ( scheme_test ) <EOL> except ValueError : <EOL> raise ValueError ( '<STR_LIT>' + scheme + '<STR_LIT>' + str ( scheme_names ) . replace ( "<STR_LIT>" , '<STR_LIT>' ) ) <EOL> else : <EOL> active = scheme_names [ scheme_idx ] <EOL> self . active_scheme_name = active <EOL> self . active_colors = self [ active ] . colors <EOL> self [ '<STR_LIT>' ] = self [ active ] </s>
