2015-08-07 13:39:02 +00:00
|
|
|
from pygments.token import string_to_tokentype
|
2015-02-05 02:41:02 +00:00
|
|
|
from pygments.util import ClassNotFound
|
2015-09-24 04:07:20 +00:00
|
|
|
from prompt_toolkit.styles import PygmentsStyle
|
2015-02-04 07:31:35 +00:00
|
|
|
import pygments.styles
|
2014-11-21 07:15:50 +00:00
|
|
|
|
2015-02-04 07:31:35 +00:00
|
|
|
|
2015-08-07 04:14:49 +00:00
|
|
|
def style_factory(name, cli_style):
|
2015-02-05 02:41:02 +00:00
|
|
|
try:
|
|
|
|
style = pygments.styles.get_style_by_name(name)
|
|
|
|
except ClassNotFound:
|
|
|
|
style = pygments.styles.get_style_by_name('native')
|
|
|
|
|
2018-01-11 20:40:45 +00:00
|
|
|
custom_styles = dict([(string_to_tokentype(x), y)
|
|
|
|
for x, y in cli_style.items()])
|
|
|
|
|
2015-09-24 04:07:20 +00:00
|
|
|
return PygmentsStyle.from_defaults(style_dict=custom_styles,
|
|
|
|
pygments_style_cls=style)
|