diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py index 07a8a84d9c6d10ed8580a7ef83d6720b522cfd98..b7bb061d41b69c8aecc2c6b1d750c7a180cc3e04 100644 --- a/pystencils/cpu/cpujit.py +++ b/pystencils/cpu/cpujit.py @@ -176,8 +176,14 @@ def read_config(): ('clear_cache_on_start', False), ]) + default_highlight_style = OrderedDict([ + ('light_theme', 'default'), + ('dark_theme', 'stata-dark'), + ]) + default_config = OrderedDict([('compiler', default_compiler_config), - ('cache', default_cache_config)]) + ('cache', default_cache_config), + ('highlight_style', default_highlight_style)]) config_path, config_exists = get_configuration_file_path() config = default_config.copy() @@ -219,6 +225,10 @@ def get_cache_config(): return _config['cache'] +def get_highlight_style_config(): + return _config['highlight_style'] + + def add_or_change_compiler_flags(flags): if not isinstance(flags, list) and not isinstance(flags, tuple): flags = [flags] diff --git a/pystencils/display_utils.py b/pystencils/display_utils.py index cb09197bf175b43c4896072693ea11253976691f..bb17c4fdc03af576fbcd6aa05cbd136251c78c6e 100644 --- a/pystencils/display_utils.py +++ b/pystencils/display_utils.py @@ -29,8 +29,22 @@ def highlight_cpp(code: str): # noinspection PyUnresolvedReferences from pygments.lexers import CppLexer - css = HtmlFormatter().get_style_defs('.highlight') - css_tag = "<style>{css}</style>".format(css=css) + from pystencils.cpu.cpujit import get_highlight_style_config + config = get_highlight_style_config() + + try: + css = HtmlFormatter(style=config['light_theme']).get_style_defs('.highlight') + except Exception: + css = HtmlFormatter(style='default').get_style_defs('.highlight') + print(f"Could not find light theme: {config['light_theme']}") + + try: + dark_css = HtmlFormatter(style=config['dark_theme']).get_style_defs('.highlight') + except Exception: + dark_css = css + + css_tag = "<style>{css} @media (prefers-color-scheme: dark) {{ {dark_css} }}</style>".format(css=css, + dark_css=dark_css) display(HTML(css_tag)) return HTML(highlight(code, CppLexer(), HtmlFormatter()))