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(*args, **kwargs)[source]

Xonsh console lexer for pygments.

aliases = ['xonshcon']
filenames = []
name = 'Xonsh console lexer'
tokens = {'root': [('^(>>>|\\.\\.\\.) ', Token.Generic.Prompt), ('\\n(>>>|\\.\\.\\.)', Token.Generic.Prompt), ('\\n(?![>.][>.][>.] )([^\\n]*)', Token.Generic.Output), ('\\n(?![>.][>.][>.] )(.*?)$', Token.Generic.Output), ('\\?', Token.Keyword), ('(?<=\\w)!', Token.Keyword), ('\\$\\w+', Token.Name.Variable), ('\\(', Token.Punctuation, 'py_bracket'), ('\\{', Token.Punctuation, 'py_curly_bracket'), 'mode_switch_brackets', ('\\n', Token.Text), ('^(\\s*)([rRuUbB]{,2})("""(?:.|\\n)*?""")', <function bygroups.<locals>.callback>), ("^(\\s*)([rRuUbB]{,2})('''(?:.|\\n)*?''')", <function bygroups.<locals>.callback>), ('[^\\S\\n]+', Token.Text), ('\\A#!.+$', Token.Comment.Hashbang), ('#.*$', Token.Comment.Single), ('[]{}:(),;[]', Token.Punctuation), ('\\\\\\n', Token.Text), ('\\\\', Token.Text), ('(in|is|and|or|not)\\b', Token.Operator.Word), ('!=|==|<<|>>|[-~+/*%=<>&^|.]', Token.Operator), 'keywords', ('(def)((?:\\s|\\\\\\s)+)', <function bygroups.<locals>.callback>, 'funcname'), ('(class)((?:\\s|\\\\\\s)+)', <function bygroups.<locals>.callback>, 'classname'), ('(from)((?:\\s|\\\\\\s)+)', <function bygroups.<locals>.callback>, 'fromimport'), ('(import)((?:\\s|\\\\\\s)+)', <function bygroups.<locals>.callback>, 'import'), 'builtins', 'magicfuncs', 'magicvars', 'backtick', ('([rR]|[uUbB][rR]|[rR][uUbB])(""")', <function bygroups.<locals>.callback>, 'tdqs'), ("([rR]|[uUbB][rR]|[rR][uUbB])(''')", <function bygroups.<locals>.callback>, 'tsqs'), ('([rR]|[uUbB][rR]|[rR][uUbB])(")', <function bygroups.<locals>.callback>, 'dqs'), ("([rR]|[uUbB][rR]|[rR][uUbB])(')", <function bygroups.<locals>.callback>, 'sqs'), ('([uUbB]?)(""")', <function bygroups.<locals>.callback>, ('stringescape', 'tdqs')), ("([uUbB]?)(''')", <function bygroups.<locals>.callback>, ('stringescape', 'tsqs')), ('([uUbB]?)(")', <function bygroups.<locals>.callback>, ('stringescape', 'dqs')), ("([uUbB]?)(')", <function bygroups.<locals>.callback>, ('stringescape', 'sqs')), 'name', 'numbers']}
class xonsh.pyghooks.XonshLexer(*args, **kwargs)[source]

Xonsh console lexer for pygments.

get_tokens_unprocessed(text)[source]

Check first command, then call super.get_tokens_unprocessed with root or subproc state

aliases = ['xonsh', 'xsh']
filenames = ['*.xsh', '*xonshrc']
name = 'Xonsh lexer'
tokens = {'root': [('\\?', Token.Keyword), ('(?<=\\w)!', Token.Keyword), ('\\$\\w+', Token.Name.Variable), ('\\(', Token.Punctuation, 'py_bracket'), ('\\{', Token.Punctuation, 'py_curly_bracket'), 'mode_switch_brackets', inherit], 'backtick_re': [('[\\.\\^\\$\\*\\+\\?\\[\\]\\|]', Token.Literal.String.Regex), ('({[0-9]+}|{[0-9]+,[0-9]+})\\??', Token.Literal.String.Regex), ('\\\\([0-9]+|[AbBdDsSwWZabfnrtuUvx\\\\])', Token.Literal.String.Escape), ('`', Token.Literal.String.Backtick, '#pop'), ('[^`\\.\\^\\$\\*\\+\\?\\[\\]\\|]+', Token.Literal.String.Backtick)], 'mode_switch_brackets': [('(\\$)(\\{)', <function bygroups.<locals>.callback>, 'py_curly_bracket'), ('(@)(\\()', <function bygroups.<locals>.callback>, 'py_bracket'), ('([\\!\\$])(\\()', <function bygroups.<locals>.callback>, ('subproc_bracket', 'subproc_start')), ('(@\\$)(\\()', <function bygroups.<locals>.callback>, ('subproc_bracket', 'subproc_start')), ('([\\!\\$])(\\[)', <function bygroups.<locals>.callback>, ('subproc_square_bracket', 'subproc_start')), ('(g?)(`)', <function bygroups.<locals>.callback>, 'backtick_re')], 'subproc_start': [('\\s+', Token.Text.Whitespace), ('[^=\\s\\[\\]{}()$"\\\'`<&|;!]+(?=\\s|$|\\)|\\]|\\}|!)', <function subproc_cmd_callback>, '#pop'), ('', Token.Text.Whitespace, '#pop')], 'subproc': ['mode_switch_brackets', ('&&|\\|\\|', Token.Operator, 'subproc_start'), ('"(\\\\\\\\|\\\\[0-7]+|\\\\.|[^"\\\\])*"', Token.Literal.String.Double), ("'(\\\\\\\\|\\\\[0-7]+|\\\\.|[^'\\\\])*'", Token.Literal.String.Single), ('(?<=\\w|\\s)!', Token.Keyword, 'subproc_macro'), ('^!', Token.Keyword, 'subproc_macro'), (';', Token.Punctuation, 'subproc_start'), ('&|=', Token.Punctuation), ('\\|', Token.Punctuation, 'subproc_start'), ('\\s+', Token.Text), ('[^=\\s\\[\\]{}()$"\\\'`<&|;]+', <function subproc_arg_callback>), ('<', Token.Text), ('\\$\\w+', Token.Name.Variable)], 'subproc_macro': [('(\\s*)([^\\n]+)', <function bygroups.<locals>.callback>), ('', Token.Text.Whitespace, '#pop')], 'py_bracket': [('\\)', Token.Punctuation, '#pop'), 'root'], 'py_curly_bracket': [('\\}', Token.Punctuation, '#pop'), 'root'], 'subproc_square_bracket': [('\\]', Token.Punctuation, '#pop'), 'subproc'], 'subproc_bracket': [('\\)', Token.Punctuation, '#pop'), 'subproc']}
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
xonsh.pyghooks.XonshTerminal256Formatter[source]

alias of XonshTerminal256FormatterProxy

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.make_pygments_style(pallette)[source]

Makes a pygments style based on a color pallete.

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.pygments_style_by_name(name)[source]

Gets or makes a pygments color style by its name.

xonsh.pyghooks.subproc_arg_callback(_, match)[source]

Check if match contains valid path

xonsh.pyghooks.subproc_cmd_callback(_, match)[source]

Yield Builtin token if match contains valid command, otherwise fallback to fallback lexer.

xonsh.pyghooks.xonsh_style_proxy(styler)[source]

Factory for a proxy class to a xonsh style.