当前位置: 首页>>代码示例>>Python>>正文


Python colored.bg方法代码示例

本文整理汇总了Python中colored.bg方法的典型用法代码示例。如果您正苦于以下问题:Python colored.bg方法的具体用法?Python colored.bg怎么用?Python colored.bg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colored的用法示例。


在下文中一共展示了colored.bg方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: color_text

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def color_text(text_array, levels, color_fg=True):
	out = []

	l_max = np.amax(levels)
	l_min = np.amin(levels)

	l_max = max(l_max, 1.0)

	for l, s in zip(levels, text_array):
		l_n = (l - l_min) / (l_max + EPSILON)
		l_n = max(0.0, min(1.0, l_n))
		if color_fg:
			color = fg(int(math.floor(DARK_GREY + l_n * (WHITE-DARK_GREY))))
		else:
			color = bg(int(math.floor(BG_BLACK + l_n * (BG_DARK_GREY-BG_BLACK))))
		out.append(stylize(s, color))
	return out 
开发者ID:Octavian-ai,项目名称:shortest-path,代码行数:19,代码来源:print_util.py

示例2: colorize

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def colorize(message, format, color=False):
    '''
    Returns the given message in a colorized format
    string with ANSI escape codes for colorized console outputs:
    - message:   the message to be formatted.
    - format:    triple containing format information:
                 (bg-color, fg-color, bf-boolean) supported colors are
                 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'
    - color:     boolean determining whether or not the colorization
                 is to be actually performed.
    '''
    if color is False: return message
    (bg, fg, bold) = format
    params = []
    if bold:
        params.append(colored.attr('bold'))
    if bg:
        params.append(colored.bg(bg))
    if fg:
        params.append(colored.fg(fg))

    return colored.stylize(message, set(params)) 
开发者ID:danielnyga,项目名称:pracmln,代码行数:24,代码来源:util.py

示例3: colorize

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def colorize(message, format, color=False):
    '''
    Returns the given message in a colorized format
    string with ANSI escape codes for colorized console outputs:
    - message:   the message to be formatted.
    - format:    triple containing format information:
                 (bg-color, fg-color, bf-boolean) supported colors are
                 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'
    - color:     boolean determining whether or not the colorization
                 is to be actually performed.
    '''

    if color is False: return message
    (bg, fg, bold) = format
    params = []
    if bold:
        params.append(colored.attr('bold'))
    if bg:
        params.append(colored.bg(bg))
    if fg:
        params.append(colored.fg(fg))

    return colored.stylize(message, set(params)) 
开发者ID:danielnyga,项目名称:pracmln,代码行数:25,代码来源:util.py

示例4: compare_with_expected

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def compare_with_expected( in_hex, expected ):
    nearest = HEX( in_hex )
    # Look up the matched hex value (e.g. xterm colors 10 and 46 are
    # the same hex value)
    match = _xterm_colors[nearest] == _xterm_colors[expected]

    e_str = '%s%s##%s' % (fg( expected ), bg( expected ), attr('reset'))
    n_str = '%s%s##%s' % (fg( nearest ), bg( nearest ), attr('reset'))
    print( "%s: %s => %s = %s" % ( 'pass' if match else 'FAIL', in_hex, n_str, e_str) )

    return match 
开发者ID:dslackw,项目名称:colored,代码行数:13,代码来源:test_hex_1.py

示例5: main

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def main():

    for color in range(0, 256):
        print("%s This text is colored %s" % (fg(color), attr("reset")))
        print("%s This background is colored %s" % (bg(color), attr("reset")))
        time.sleep(0.1) 
开发者ID:dslackw,项目名称:colored,代码行数:8,代码来源:test_1.py

示例6: _limited_answer

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def _limited_answer(answer):
    return colored.bg('dark_goldenrod') + colored.fg('yellow_1') \
        + ' ' +  answer + ' ' \
        + colored.attr('reset') + "\n" 
开发者ID:chubin,项目名称:cheat.sh,代码行数:6,代码来源:ansi.py

示例7: _colorize

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def _colorize(text):
    return \
        re.sub(
            r"`(.*?)`",
            colored.bg("dark_gray") \
                + colored.fg("white") \
                + " " + r"\1" + " " \
                + colored.attr('reset'),
            re.sub(
                r"\*\*(.*?)\*\*",
                colored.attr('bold') \
                    + colored.fg("white") \
                    + r"\1" \
                    + colored.attr('reset'),
                text)) 
开发者ID:chubin,项目名称:cheat.sh,代码行数:17,代码来源:markdown.py

示例8: colorize_internal_firstpage_v1

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def colorize_internal_firstpage_v1(answer):
    """
    Colorize "/:firstpage-v1".
    Legacy.
    """

    def _colorize_line(line):
        if line.startswith('T'):
            line = colored.fg("grey_62") + line + colored.attr('reset')
            line = re.sub(r"\{(.*?)\}", colored.fg("orange_3") + r"\1"+colored.fg('grey_35'), line)
            return line

        line = re.sub(r"\[(F.*?)\]",
                      colored.bg("black") + colored.fg("cyan") + r"[\1]"+colored.attr('reset'),
                      line)
        line = re.sub(r"\[(g.*?)\]",
                      colored.bg("dark_gray")+colored.fg("grey_0")+r"[\1]"+colored.attr('reset'),
                      line)
        line = re.sub(r"\{(.*?)\}",
                      colored.fg("orange_3") + r"\1"+colored.attr('reset'),
                      line)
        line = re.sub(r"<(.*?)>",
                      colored.fg("cyan") + r"\1"+colored.attr('reset'),
                      line)
        return line

    lines = answer.splitlines()
    answer_lines = lines[:9]
    answer_lines.append(colored.fg('grey_35')+lines[9]+colored.attr('reset'))
    for line in lines[10:]:
        answer_lines.append(_colorize_line(line))
    answer = "\n".join(answer_lines) + "\n"

    return answer 
开发者ID:chubin,项目名称:cheat.sh,代码行数:36,代码来源:internal.py

示例9: PRINT

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def PRINT(self, str, appendGrandmasterTag=True, endStr='\n', outputColor='aquamarine_3'):
		if appendGrandmasterTag is False:
			print("%s%s%s%s" % (fg(outputColor), bg('black'), str, attr('reset')), end=endStr)
		else:
			print("%s%s[GM]%s %s%s%s%s" % (fg("purple_1b"), bg('black'), attr('reset'), fg(outputColor), bg('black'), str, attr('reset')), end=endStr)

# who reinvents wheels? https://gist.github.com/garrettdreyfus/8153571 
开发者ID:GuardianFirewall,项目名称:grandmaster,代码行数:9,代码来源:helpers.py

示例10: color_text

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def color_text(text_array, levels, color_fg=True):
	out = []

	levels = normalize_levels(text_array, levels)

	for l, s in zip(levels, text_array):
		if color_fg:
			color = fg(int(math.floor(DARK_GREY + l * (WHITE-DARK_GREY))))
		else:
			color = bg(int(math.floor(BG_BLACK + l * (BG_DARK_GREY-BG_BLACK))))
		out.append(stylize(s, color))
	return out 
开发者ID:Octavian-ai,项目名称:mac-graph,代码行数:14,代码来源:print_util.py

示例11: _visualize

# 需要导入模块: import colored [as 别名]
# 或者: from colored import bg [as 别名]
def _visualize(answers, request_options, search_mode=False):

    highlight = not bool(request_options and request_options.get('no-terminal'))
    color_style = (request_options or {}).get('style', '')
    if color_style not in CONFIG['frontend.styles']:
        color_style = ''

    found = True
    result = ""
    for answer_dict in answers:
        topic = answer_dict['topic']
        topic_type = answer_dict['topic_type']
        answer = answer_dict['answer']
        found = found and not topic_type == 'unknown'

        if search_mode and topic != 'LIMITED':
            if not highlight:
                result += "\n[%s]\n" % topic
            else:
                result += "\n%s%s %s %s%s\n" % (
                    colored.bg('dark_gray'), colored.attr("res_underlined"),
                    topic,
                    colored.attr("res_underlined"), colored.attr('reset'))

        if answer_dict['format'] in ['ansi', 'text']:
            result += answer
        elif topic == ':firstpage-v1':
            result += fmt.internal.colorize_internal_firstpage_v1(answer)
        elif topic == 'LIMITED':
            result += _limited_answer(topic)
        else:
            result += _colorize_ansi_answer(
                topic, answer, color_style,
                highlight_all=highlight,
                highlight_code=(topic_type == 'question'
                                and not request_options.get('add_comments')
                                and not request_options.get('remove_text')),
                language=answer_dict.get("filetype"))

    if request_options.get('no-terminal'):
        result = remove_ansi(result)

    result = result.strip('\n') + "\n"
    return result, found 
开发者ID:chubin,项目名称:cheat.sh,代码行数:46,代码来源:ansi.py


注:本文中的colored.bg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。