本文整理汇总了Python中pygments.style.Style方法的典型用法代码示例。如果您正苦于以下问题:Python style.Style方法的具体用法?Python style.Style怎么用?Python style.Style使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.style
的用法示例。
在下文中一共展示了style.Style方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: json_out
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def json_out(data, pretty=False, mono=False, piped_out=False):
if not mono and not piped_out:
# set colors
class JcStyle(Style):
styles = set_env_colors()
if pretty:
print(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
else:
print(highlight(json.dumps(data), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
else:
if pretty:
print(json.dumps(data, indent=2))
else:
print(json.dumps(data))
示例2: style_factory_output
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_factory_output(name, cli_style):
try:
style = pygments.styles.get_style_by_name(name).styles
except ClassNotFound:
style = pygments.styles.get_style_by_name("native").styles
for token in cli_style:
if token.startswith("Token."):
token_type, style_value = parse_pygments_style(token, style, cli_style)
style.update({token_type: style_value})
elif token in PROMPT_STYLE_TO_TOKEN:
token_type = PROMPT_STYLE_TO_TOKEN[token]
style.update({token_type: cli_style[token]})
else:
# TODO: cli helpers will have to switch to ptk.Style
logger.error("Unhandled style / class name: %s", token)
class OutputStyle(PygmentsStyle):
default_style = ""
styles = style
return OutputStyle
示例3: style_factory_output
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_factory_output(name, cli_style):
try:
style = pygments.styles.get_style_by_name(name).styles
except ClassNotFound:
style = pygments.styles.get_style_by_name('native').styles
for token in cli_style:
if token.startswith('Token.'):
token_type, style_value = parse_pygments_style(
token, style, cli_style)
style.update({token_type: style_value})
elif token in PROMPT_STYLE_TO_TOKEN:
token_type = PROMPT_STYLE_TO_TOKEN[token]
style.update({token_type: cli_style[token]})
else:
# TODO: cli helpers will have to switch to ptk.Style
logger.error('Unhandled style / class name: %s', token)
class OutputStyle(PygmentsStyle):
default_style = ""
styles = style
return OutputStyle
示例4: test_get_style_defs_contains_style_specific_line_numbers_styles
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_get_style_defs_contains_style_specific_line_numbers_styles():
class TestStyle(Style):
line_number_color = '#ff0000'
line_number_background_color = '#0000ff'
line_number_special_color = '#00ff00'
line_number_special_background_color = '#ffffff'
style_defs = HtmlFormatter(style=TestStyle).get_style_defs().splitlines()
assert style_defs[1] == (
'td.linenos pre '
'{ color: #ff0000; background-color: #0000ff; padding: 0 5px 0 5px; }'
)
assert style_defs[2] == (
'span.linenos '
'{ color: #ff0000; background-color: #0000ff; padding: 0 5px 0 5px; }'
)
assert style_defs[3] == (
'td.linenos pre.special '
'{ color: #00ff00; background-color: #ffffff; padding: 0 5px 0 5px; }'
)
assert style_defs[4] == (
'span.linenos.special '
'{ color: #00ff00; background-color: #ffffff; padding: 0 5px 0 5px; }'
)
示例5: style_from_pygments_cls
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_from_pygments_cls(pygments_style_cls: Type["PygmentsStyle"]) -> Style:
"""
Shortcut to create a :class:`.Style` instance from a Pygments style class
and a style dictionary.
Example::
from prompt_toolkit.styles.from_pygments import style_from_pygments_cls
from pygments.styles import get_style_by_name
style = style_from_pygments_cls(get_style_by_name('monokai'))
:param pygments_style_cls: Pygments style class to start from.
"""
# Import inline.
from pygments.style import Style as PygmentsStyle
assert issubclass(pygments_style_cls, PygmentsStyle)
return style_from_pygments_dict(pygments_style_cls.styles)
示例6: set_default_style
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def set_default_style(style):
"""Sets default global style to be used by ``prettyprinter.cpprint``.
:param style: the style to set, either subclass of
``pygments.styles.Style`` or one of ``'dark'``, ``'light'``
"""
global default_style
if style == 'dark':
style = default_dark_style
elif style == 'light':
style = default_light_style
if not issubclass(style, Style):
raise TypeError(
"style must be a subclass of pygments.styles.Style or "
"one of 'dark', 'light'. Got {}".format(repr(style))
)
default_style = style
示例7: test_override_missing_value_with_style
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_override_missing_value_with_style():
"""Test that *override_missing_value()* styles output."""
class NullStyle(Style):
styles = {
Token.Output.Null: '#0f0'
}
headers = ['h1', 'h2']
data = [[None, '2'], ['abc', None]]
expected_headers = ['h1', 'h2']
expected_data = [
['\x1b[38;5;10m<null>\x1b[39m', '2'],
['abc', '\x1b[38;5;10m<null>\x1b[39m']
]
results = override_missing_value(data, headers,
style=NullStyle, missing_value="<null>")
assert (expected_data, expected_headers) == (list(results[0]), results[1])
示例8: test_style_output
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_style_output():
"""Test that *style_output()* styles output."""
class CliStyle(Style):
default_style = ""
styles = {
Token.Output.Header: 'bold ansibrightred',
Token.Output.OddRow: 'bg:#eee #111',
Token.Output.EvenRow: '#0f0'
}
headers = ['h1', 'h2']
data = [['观音', '2'], ['Ποσειδῶν', 'b']]
expected_headers = ['\x1b[91;01mh1\x1b[39;00m', '\x1b[91;01mh2\x1b[39;00m']
expected_data = [['\x1b[38;5;233;48;5;7m观音\x1b[39;49m',
'\x1b[38;5;233;48;5;7m2\x1b[39;49m'],
['\x1b[38;5;10mΠοσειδῶν\x1b[39m', '\x1b[38;5;10mb\x1b[39m']]
results = style_output(data, headers, style=CliStyle)
assert (expected_data, expected_headers) == (list(results[0]), results[1])
示例9: test_style_output_custom_tokens
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_style_output_custom_tokens():
"""Test that *style_output()* styles output with custom token names."""
class CliStyle(Style):
default_style = ""
styles = {
Token.Results.Headers: 'bold ansibrightred',
Token.Results.OddRows: 'bg:#eee #111',
Token.Results.EvenRows: '#0f0'
}
headers = ['h1', 'h2']
data = [['1', '2'], ['a', 'b']]
expected_headers = ['\x1b[91;01mh1\x1b[39;00m', '\x1b[91;01mh2\x1b[39;00m']
expected_data = [['\x1b[38;5;233;48;5;7m1\x1b[39;49m',
'\x1b[38;5;233;48;5;7m2\x1b[39;49m'],
['\x1b[38;5;10ma\x1b[39m', '\x1b[38;5;10mb\x1b[39m']]
output = style_output(
data, headers, style=CliStyle,
header_token='Token.Results.Headers',
odd_row_token='Token.Results.OddRows',
even_row_token='Token.Results.EvenRows')
assert (expected_data, expected_headers) == (list(output[0]), output[1])
示例10: style_factory_output
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_factory_output(name, cli_style):
try:
style = pygments.styles.get_style_by_name(name).styles
except ClassNotFound:
style = pygments.styles.get_style_by_name('native').styles
for token in cli_style:
if token.startswith('Token.'):
token_type, style_value = parse_pygments_style(
token, style, cli_style)
style.update({token_type: style_value})
elif token in PROMPT_STYLE_TO_TOKEN:
token_type = PROMPT_STYLE_TO_TOKEN[token]
style.update({token_type: cli_style[token]})
else:
# TODO: cli helpers will have to switch to ptk.Style
logger.error('Unhandled style / class name: %s', token)
class OutputStyle(PygmentsStyle): # pylint: disable=too-few-public-methods
default_style = ""
styles = style
return OutputStyle
示例11: __init__
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def __init__(
self,
code: str,
lexer_name: str,
*,
theme: Union[str, Type[PygmentsStyle]] = DEFAULT_THEME,
dedent: bool = False,
line_numbers: bool = False,
start_line: int = 1,
line_range: Tuple[int, int] = None,
highlight_lines: Set[int] = None,
code_width: Optional[int] = None,
tab_size: int = 4,
word_wrap: bool = False
) -> None:
self.code = code
self.lexer_name = lexer_name
self.dedent = dedent
self.line_numbers = line_numbers
self.start_line = start_line
self.line_range = line_range
self.highlight_lines = highlight_lines or set()
self.code_width = code_width
self.tab_size = tab_size
self.word_wrap = word_wrap
self._style_cache: Dict[Any, Style] = {}
if not isinstance(theme, str) and issubclass(theme, PygmentsStyle):
self._pygments_style_class = theme
else:
try:
self._pygments_style_class = get_style_by_name(theme)
except ClassNotFound:
self._pygments_style_class = get_style_by_name("default")
self._background_color = self._pygments_style_class.background_color
示例12: style_from_dict
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_from_dict(d):
styles = default_style_extensions.copy()
styles.update(DefaultStyle.styles)
styles.update(d)
PromptStyle = type('PromptStyle', (Style,), {'styles': styles})
return PromptStyle
示例13: test_style_factory
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_style_factory():
"""Test that a Pygments Style class is created."""
header = "bold underline #ansired"
cli_style = {"Token.Output.Header": header}
style = style_factory("default", cli_style)
assert isinstance(style(), Style)
assert Token.Output.Header in style.styles
assert header == style.styles[Token.Output.Header]
示例14: test_style_factory_unknown_name
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_style_factory_unknown_name():
"""Test that an unrecognized name will not throw an error."""
style = style_factory("foobar", {})
assert isinstance(style(), Style)
示例15: override_missing_value
# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def override_missing_value(data, headers, style=None,
missing_value_token="Token.Output.Null",
missing_value='', **_):
"""Override missing values in the *data* with *missing_value*.
A missing value is any value that is :data:`None`.
:param iterable data: An :term:`iterable` (e.g. list) of rows.
:param iterable headers: The column headers.
:param style: Style for missing_value.
:param missing_value_token: The Pygments token used for missing data.
:param missing_value: The default value to use for missing data.
:return: The processed data and headers.
:rtype: tuple
"""
def fields():
for row in data:
processed = []
for field in row:
if field is None and style and HAS_PYGMENTS:
styled = utils.style_field(missing_value_token, missing_value, style)
processed.append(styled)
elif field is None:
processed.append(missing_value)
else:
processed.append(field)
yield processed
return (fields(), headers)