當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。