Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephan Seitz
pystencils
Commits
72bb4fd0
Commit
72bb4fd0
authored
Mar 27, 2020
by
Stephan Seitz
Browse files
Make highlight_style configurable
parent
1dcf5229
Pipeline
#22868
passed with stage
in 6 minutes
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pystencils/cpu/cpujit.py
View file @
72bb4fd0
...
@@ -176,8 +176,14 @@ def read_config():
...
@@ -176,8 +176,14 @@ def read_config():
(
'clear_cache_on_start'
,
False
),
(
'clear_cache_on_start'
,
False
),
])
])
default_highlight_style
=
OrderedDict
([
(
'light_theme'
,
'default'
),
(
'dark_theme'
,
'stata-dark'
),
])
default_config
=
OrderedDict
([(
'compiler'
,
default_compiler_config
),
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_path
,
config_exists
=
get_configuration_file_path
()
config
=
default_config
.
copy
()
config
=
default_config
.
copy
()
...
@@ -219,6 +225,10 @@ def get_cache_config():
...
@@ -219,6 +225,10 @@ def get_cache_config():
return
_config
[
'cache'
]
return
_config
[
'cache'
]
def
get_highlight_style_config
():
return
_config
[
'highlight_style'
]
def
add_or_change_compiler_flags
(
flags
):
def
add_or_change_compiler_flags
(
flags
):
if
not
isinstance
(
flags
,
list
)
and
not
isinstance
(
flags
,
tuple
):
if
not
isinstance
(
flags
,
list
)
and
not
isinstance
(
flags
,
tuple
):
flags
=
[
flags
]
flags
=
[
flags
]
...
...
pystencils/display_utils.py
View file @
72bb4fd0
...
@@ -29,10 +29,18 @@ def highlight_cpp(code: str):
...
@@ -29,10 +29,18 @@ def highlight_cpp(code: str):
# noinspection PyUnresolvedReferences
# noinspection PyUnresolvedReferences
from
pygments.lexers
import
CppLexer
from
pygments.lexers
import
CppLexer
css
=
HtmlFormatter
().
get_style_defs
(
'.highlight'
)
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
:
try
:
dark_css
=
HtmlFormatter
(
style
=
"stata-dark"
).
get_style_defs
(
'.highlight'
)
dark_css
=
HtmlFormatter
(
style
=
config
[
'dark_theme'
]
).
get_style_defs
(
'.highlight'
)
except
ModuleNotFoundError
:
except
Exception
:
dark_css
=
css
dark_css
=
css
css_tag
=
"<style>{css} @media (prefers-color-scheme: dark) {{ {dark_css} }}</style>"
.
format
(
css
=
css
,
css_tag
=
"<style>{css} @media (prefers-color-scheme: dark) {{ {dark_css} }}</style>"
.
format
(
css
=
css
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment