Pygments Hooks (xonsh.pyghooks)

Hooks for pygments syntax highlighting.

class xonsh.pyghooks.CompoundColorMap(styles, *args, **kwargs)[source]

Looks up color tokes by name, potentailly generating the value from the lookup.

class xonsh.pyghooks.XonshConsoleLexer(**options)[source]

Xonsh console lexer for pygments.

aliases = ['xonshcon']
filenames = []
name = 'Xonsh console lexer'
tokens = {'pymode': [('(.+)(\\))', <function bygroups.<locals>.callback>, '#pop'), ('(.+)(\\})', <function bygroups.<locals>.callback>, '#pop')], 'subproc': [('(.+)(\\))', <function bygroups.<locals>.callback>, '#pop'), ('(.+)(\\])', <function bygroups.<locals>.callback>, '#pop')], 'root': [('^(>>>|\\.\\.\\.) ', Token.Generic.Prompt), ('\\n(>>>|\\.\\.\\.)', Token.Generic.Prompt), ('\\n(?![>.][>.][>.] )([^\\n]*)', Token.Generic.Output), ('\\n(?![>.][>.][>.] )(.*?)$', Token.Generic.Output), ('\\?', Token.Keyword), ('\\$\\w+', Token.Name.Variable), ('\\$\\{', Token.Keyword, ('pymode',)), ('[\\!\\$]\\(', Token.Keyword, ('subproc',)), ('[\\!\\$]\\[', Token.Keyword, ('subproc',)), ('@\\$\\(', Token.Keyword, ('subproc',)), ('@\\(', Token.Keyword, ('pymode',)), inherit]}
class xonsh.pyghooks.XonshLexer(**options)[source]

Xonsh console lexer for pygments.

aliases = ['xonsh', 'xsh']
filenames = ['*.xsh', '*xonshrc']
name = 'Xonsh lexer'
tokens = {'pymode': [('(.+)(\\))', <function bygroups.<locals>.callback>, '#pop'), ('(.+)(\\})', <function bygroups.<locals>.callback>, '#pop')], 'subproc': [('(.+)(\\))', <function bygroups.<locals>.callback>, '#pop'), ('(.+)(\\])', <function bygroups.<locals>.callback>, '#pop')], 'root': [('\\?', Token.Keyword), ('\\$\\w+', Token.Name.Variable), ('\\$\\{', Token.Keyword, ('pymode',)), ('[\\!\\$]\\(', Token.Keyword, ('subproc',)), ('[\\!\\$]\\[', Token.Keyword, ('subproc',)), ('@\\$\\(', Token.Keyword, ('subproc',)), ('@\\(', Token.Keyword, ('pymode',)), inherit]}
class xonsh.pyghooks.XonshStyle(style_name='default')[source]

A xonsh pygments style that will dispatch to the correct color map by using a ChainMap. The style_name property may be used to reset the current style.

Parameters:

style_name : str, optional

The style name to initialize with.

enhance_colors_for_cmd_exe()[source]

Enhance colors when using cmd.exe on windows. When using the default style all blue and dark red colors are changed to CYAN and intence red.

style_name
class xonsh.pyghooks.XonshSubprocLexer(**options)[source]

Lexer for xonsh subproc mode.

name = 'Xonsh subprocess lexer'
tokens = {'root': [('(\\$\\{)(.*)(\\})', <function bygroups.<locals>.callback>), ('(@\\()(.+)(\\))', <function bygroups.<locals>.callback>), ('((?:[rg]|@\\w*)?)`([^\\n`\\\\]*(?:\\\\.[^\\n`\\\\]*)*)`', Token.Literal.String.Backtick), inherit]}
xonsh.pyghooks.code_by_name(name, styles)[source]

Converts a token name into a pygments-style color code.

Parameters:

name : str

Color token name.

styles : Mapping

Mapping for looking up non-hex colors

Returns:

code : str

Pygments style color code.

xonsh.pyghooks.color_by_name(name, fg=None, bg=None)[source]

Converts a color name to a color token, foreground name, and background name. Will take into consideration current foreground and background colors, if provided.

Parameters:

name : str

Color name.

fg : str, optional

Foreground color name.

bg : str, optional

Background color name.

Returns:

tok : Token

Pygments Token.Color subclass

fg : str or None

New computed foreground color name.

bg : str or None

New computed background color name.

xonsh.pyghooks.norm_name(name)[source]

Normalizes a color name.

xonsh.pyghooks.partial_color_tokenize(template)[source]

Tokenizes a template string containing colors. Will return a list of tuples mapping the token to the string which has that color. These sub-strings maybe templates themselves.

xonsh.pyghooks.xonsh_style_proxy(styler)[source]

Factory for a proxy class to a xonsh style.