Set pygments syntax highlighting style.
510599
def set_style(self, style):
        """"""
        if style == "none":
            self.style = None
        elif prompt_toolkit is None:
            raise CoconutException("syntax highlighting is not supported on this Python version")
        elif style == "list":
            print("Coconut Styles: none, " + ", ".join(pygments.styles.get_all_styles()))
            sys.exit(0)
        elif style in pygments.styles.get_all_styles():
            self.style = style
        else:
            raise CoconutException("unrecognized pygments style", style, extra="use '--style list' to show all valid styles")
365617
def _color(self, msg, color):
        """"""
        kwargs = {'fg': color}
        return click.style(msg, **kwargs) if self.colorize else msg
1359985
def set(self, style={}):
        """"""
        _style = {}
        for attr in style:
            if attr in self.cmds and not style[attr] in self.cmds[attr]:
                print 'WARNING: ESC/POS PRINTING: ignoring invalid value: '+utfstr(style[attr])+' for style: '+utfstr(attr)
            else:
                self.stack[-1][attr] = self.enforce_type(attr, style[attr])
408243
def colored_pygments_excepthook(type_, value, tb):
    
    tbtext = ''.join(traceback.format_exception(type_, value, tb))
    try:
        from utool import util_str
        formatted_text = util_str.highlight_text(tbtext, lexer_name='pytb',
                                                 stripall=True)
    except Exception:
        # FIXME silent errro
        formatted_text = tbtext
        return sys.__excepthook__(type_, value, tb)
        #import utool as ut
        #if ut.SUPER_STRICT:
        #    raise
    sys.stderr.write(formatted_text)
214016
def highlight_block(self, text):
        """"""
        text = to_text_string(text)
        self.setFormat(0, len(text), self.formats["normal"])
        
        match = self.PROG.search(text)
        index = 0
        while match:
            for key, value in list(match.groupdict().items()):
                if value:
                    start, end = match.span(key)
                    index += end-start
                    self.setFormat(start, end-start, self.formats[key])
                    if value.lower() in ("subroutine", "module", "function"):
                        match1 = self.IDPROG.match(text, end)
                        if match1:
                            start1, end1 = match1.span(1)
                            self.setFormat(start1, end1-start1,
                                           self.formats["definition"])
                    
            match = self.PROG.search(text, match.end())
        
        self.highlight_spaces(text)
842808
def stylize(text, styles, reset=True):
    """"""
    terminator = attr("reset") if reset else ""
    return "{}{}{}".format("".join(styles), text, terminator)
619291
def set_pythonshell_font(self, font=None):
        """"""
        if font is None:
            font = QFont()
        for style in self.font_styles:
            style.apply_style(font=font,
                              is_default=style is self.default_style)
        self.ansi_handler.set_base_format(self.default_style.format)
697257
def use_colorscheme(self, name='default'):
        
        try:
            self.current_style = get_editor_style_by_name(name)
        except pygments.util.ClassNotFound:
            pass
850210
def set_color(
    fg=Color.normal,
    bg=Color.normal,
    fg_dark=False,
    bg_dark=False,
    underlined=False,
):
    
    _set_color(fg, bg, fg_dark, bg_dark, underlined)
768850
def configure(self, **kwargs):
        ''' 
        '''
        for kwarg in kwargs:
            value = kwargs[kwarg]

            if kwarg == 'level':
                self.set_level(value)

            elif kwarg == 'default_level':
                self.default_level = level_map.get(value, value)

            elif kwarg == 'datefmt':
                self.handlers[0].formatter.datefmt = value

            elif kwarg == 'msgfmt':
                self.handlers[0].formatter._style._fmt = value

            elif kwarg == 'stream':
                global fg, fx, _CHOSEN_PALETTE
                self.handlers[0].stream = value
                fg, fx, _CHOSEN_PALETTE = _find_palettes(value)

            elif kwarg == 'theme':
                if type(value) is str:
                    theme = _themes[value]
                    if value == 'plain':
                        fmtr =  logging.Formatter(style='{', **theme)
                    elif value == 'json':
                        fmtr =  _JSONFormatter(**theme)
                    else:
                        fmtr =  _ColorFormatter(tty=_is_a_tty, **theme)
                elif type(value) is dict:
                    if 'style' in value or 'icons' in value:
                        fmtr =  _ColorFormatter(tty=_is_a_tty, **theme)
                    else:
                        fmtr =  logging.Formatter(style='{', **theme)
                self.handlers[0].setFormatter(fmtr)

            elif kwarg == 'icons':
                if type(value) is str:
                    value = _icons[value]
                self.handlers[0].formatter._theme_icons = value

            elif kwarg == 'style':
                if type(value) is str:
                    value = _styles[value]
                self.handlers[0].formatter._theme_style = value

            elif kwarg == 'lexer':
                try:
                    self.handlers[0].formatter.set_lexer(value)
                except AttributeError as err:
                    self.error('lexer: ColorFormatter not available.')
            else:
                raise NameError('unknown keyword argument: %s' % kwarg)
539884
def install_code_colorscheme(self, name, style_dict):
        
        assert isinstance(name, six.text_type)
        assert isinstance(style_dict, dict)

        self.code_styles[name] = style_dict
347715
def highlight_syntax(src, lang, linenums=False):
    
    src = src.strip('\n')
    if not lang:
        lexer = TextLexer()
    else:
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except ValueError:
            lexer = TextLexer()
    formatter = HtmlFormatter(linenos=linenums, tab_length=TAB_LENGTH)
    html = highlight(src, lexer, formatter)

    if lang:
        open_code = OPEN_CODE % (LANG_TAG % (lang, ), )
    else:
        open_code = OPEN_CODE % u''
    html = html.replace('<div class="highlight"><pre>', open_code, 1)
    html = html.replace('</pre></div>', CLOSE_CODE)
    return html
853049
def highlight_block(self, text):
        """"""
        text = to_text_string(text)
        if text.startswith("+++"):
            self.setFormat(0, len(text), self.formats["keyword"])
        elif text.startswith("---"):
            self.setFormat(0, len(text), self.formats["keyword"])
        elif text.startswith("+"):
            self.setFormat(0, len(text), self.formats["string"])
        elif text.startswith("-"):
            self.setFormat(0, len(text), self.formats["number"])
        elif text.startswith("@"):
            self.setFormat(0, len(text), self.formats["builtin"])
        
        self.highlight_spaces(text)
510218
public static void setStyle() {

        int style = Font.PLAIN;

        if (ckbbold.isSelected()) {
            style |= Font.BOLD;
        }

        if (ckbitalic.isSelected()) {
            style |= Font.ITALIC;
        }

        fOwner.tTree.setFont(fOwner.txtCommand.getFont().deriveFont(style));
        fOwner.txtCommand.setFont(
            fOwner.txtCommand.getFont().deriveFont(style));
        fOwner.txtResult.setFont(
            fOwner.txtResult.getFont().deriveFont(style));
    }
946624
function highlight(node, ok) {
        if (!node) return;
        if (self.options.markParen) {
          self.options.markParen(node, ok);
        }
        else {
          node.style.fontWeight = "bold";
          node.style.color = ok ? "#8F8" : "#F88";
        }
      }
294679
def _syntax_style_changed(self):
        """"""
        if self._highlighter is None:
            # ignore premature calls
            return
        if self.syntax_style:
            self._highlighter._style = create_style_class(self.syntax_style)
            self._highlighter._clear_caches()
        else:
            self._highlighter.set_style_sheet(self.style_sheet)
248696
def py_syntax_highlight(self, s):
        
        if not self.enable:
            return s
        state = 0
        spaces = " \t\n"
        ops = ".,;:+-*/%&!=|(){}[]^<>"
        i = 0
        cur_token = ""
        color_args = {0: {}, len(s): {}}  # type: typing.Dict[int,typing.Dict[str]]  # pos in s -> color kwargs

        def finish_identifier():
            """
            Reset color to standard for current identifier.
            """
            if cur_token in py_keywords:
                color_args[max([k for k in color_args.keys() if k < i])] = {"color": self.fg_colors[0]}

        while i < len(s):
            c = s[i]
            i += 1
            if c == "\n":
                if state == 3:
                    finish_identifier()
                color_args[i] = {}
                state = 0
            elif state == 0:
                if c in spaces:
                    pass
                elif c in ops:
                    color_args[i - 1] = {"color": self.fg_colors[0]}
                    color_args[i] = {}
                elif c == "#":
                    color_args[i - 1] = {"color": self.fg_colors[3]}
                    state = 6
                elif c == '"':
                    color_args[i - 1] = {"color": self.fg_colors[2]}
                    state = 1
                elif c == "'":
                    color_args[i - 1] = {"color": self.fg_colors[2]}
                    state = 2
                else:
                    cur_token = c
                    color_args[i - 1] = {}
                    state = 3
            elif state == 1:  # string via "
                if c == "\\":
                    state = 4
                elif c == "\"":
                    color_args[i] = {}
                    state = 0
            elif state == 2:  # string via '
                if c == "\\":
                    state = 5
                elif c == "'":
                    color_args[i] = {}
                    state = 0
            elif state == 3:  # identifier
                if c in spaces + ops + "#\"'":
                    finish_identifier()
                    color_args[i] = {}
                    state = 0
                    i -= 1
                else:
                    cur_token += c
            elif state == 4:  # escape in "
                state = 1
            elif state == 5:  # escape in '
                state = 2
            elif state == 6:  # comment
                pass
        if state == 3:
            finish_identifier()
        out = ""
        i = 0
        while i < len(s):
            j = min([k for k in color_args.keys() if k > i])
            out += self.color(s[i:j], **color_args[i])
            i = j
        return out