Return a string highlighted for a terminal.
435069
def _highlight(string, color):
	''''''
	if CONFIG['color']:
		if color < 8:
			return '\033[{color}m{string}\033[0m'.format(string = string, color = color+30)
		else:
			return '\033[{color}m{string}\033[0m'.format(string = string, color = color+82)
	else:
		return string
1085242
def _format_json(data, theme):
    """"""
    output = json.dumps(data, indent=2, sort_keys=True)

    if pygments and sys.stdout.isatty():
        style = get_style_by_name(theme)
        formatter = Terminal256Formatter(style=style)
        return pygments.highlight(output, JsonLexer(), formatter)

    return output
326351
def pretty_str(self, indent=0):
        
        if self.body:
            return '\n'.join(stmt.pretty_str(indent) for stmt in self.body)
        else:
            return (' ' * indent) + '[empty]'
480384
def prompt(self):
        """"""
        if self.prompt_string is not None:
            return self.prompt_string

        if not self.color_enabled:
            return (' '.join(self.command) + '>> ').encode('utf8')

        color = '34'
        sub_color = '37'

        prompt_cmd = [
            self.colorize('1;' + color, part) if part != self.cmd_sub_str else
            self.colorize('0;' + sub_color, u'\u2026') for part in self.command
        ]

        return ' '.join(prompt_cmd) + self.colorize('0;' + color, '>> ')
402413
def pretty_str(self, indent=0):
        
        indent = ' ' * indent
        if self.value is not None:
            return '{}{} {}'.format(indent, self.name, pretty_str(self.value))
        return indent + self.name
383827
public static function highLight(String $str, Array $settings = []) : String
    {
        return Helper::highLight($str, $settings);
    }
1272927
function highlightTokens(defs: Object, text: string) {
  return text.replace(jsTokens, function(...args) {
    const type = getTokenType(args);
    const colorize = defs[type];
    if (colorize) {
      return args[0]
        .split(NEWLINE)
        .map(str => colorize(str))
        .join("\n");
    } else {
      return args[0];
    }
  });
}
722324
def highlight(string, fg=None, bg=None, indices=[], end='\n',
              target=sys.stdout):
    
    if not string or not indices or (fg is bg is None):
        return

    p = 0

    # The lambda syntax is necessary to support both Python 2 and 3
    for k, g in itertools.groupby(enumerate(sorted(indices)),
                                  lambda x: x[0]-x[1]):
        tmp = list(map(operator.itemgetter(1), g))
        s, e = tmp[0], tmp[-1]+1
        target.write(string[p:s])
        target.flush()  # Needed for Python 3.x
        _color_manager.set_color(fg, bg)
        target.write(string[s:e])
        target.flush()  # Needed for Python 3.x
        _color_manager.set_defaults()
        p = e

    if p < len(string):
        target.write(string[p:])

    target.write(end)
1150071
def indication(self, *args, **kwargs):
        """"""
        if not self.current_terminal:
            raise RuntimeError("no active terminal")
        if not isinstance(self.current_terminal, Server):
            raise RuntimeError("current terminal not a server")

        self.current_terminal.indication(*args, **kwargs)
138613
def pretty_str(self, indent=0):
        
        return '{}{} {} = {}'.format(' ' * indent, self.result, self.name,
                                     pretty_str(self.value))
990737
def highlight_at!(y, x)
      update_highlighter if @highlighter_tokens.nil?

      fail(HighlighterUnknownSegment, "line: #{y}") if @highlighter_tokens[@offset_y + y].nil?
      fail(HighlighterUnknownSegment, "line: #{y} char: #{x}") if @highlighter_tokens[@offset_y + y][x].nil?

      @highlighter_tokens[@offset_y + y][x]
    end
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)
696493
def color_msg(msg, color):
    "  "
    return ''.join((COLORS.get(color, COLORS['endc']), msg, COLORS['endc']))
160329
function color(c, bold, msg) {
  return bold ? clic.xterm(c).bold(msg) : clic.xterm(c)(msg);
}
134495
def color_prompt(self):
        '''  '''
        prompt = '[' + colorize('psiTurk', 'bold')
        server_string = ''
        server_status = self.server.is_server_running()
        if server_status == 'yes':
            server_string = colorize('on', 'green')
        elif server_status == 'no':
            server_string = colorize('off', 'red')
        elif server_status == 'maybe':
            server_string = colorize('unknown', 'yellow')
        elif server_status == 'blocked':
            server_string = colorize('blocked', 'red')
        prompt += ' server:' + server_string
        prompt += ' mode:' + colorize('cabin', 'bold')
        prompt += ']$ '
        self.prompt = prompt
892068
def getlines(filename, opts=default_opts):
    
    if get_option('reload_on_change', opts): checkcache(filename)
    fmt = get_option('output', opts)
    highlight_opts = {'bg': fmt}
    cs = opts.get('style')

    # Colorstyle of Terminal255Formatter takes precidence over
    # light/dark colorthemes of TerminalFormatter
    if cs:
        highlight_opts['style'] = cs
        fmt = cs

    if filename not in file_cache:
        update_cache(filename, opts)
        filename = pyc2py(filename)
        if filename not in file_cache: return None
        pass
    lines = file_cache[filename].lines
    if fmt not in lines.keys():
        lines[fmt] = highlight_array(lines['plain'], **highlight_opts)
        pass
    return lines[fmt]
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