當前位置: 首頁>>代碼示例>>Python>>正文


Python colored.attr方法代碼示例

本文整理匯總了Python中colored.attr方法的典型用法代碼示例。如果您正苦於以下問題:Python colored.attr方法的具體用法?Python colored.attr怎麽用?Python colored.attr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在colored的用法示例。


在下文中一共展示了colored.attr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __str__

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def __str__(self):
        answer = ""
        skip_next = False
        for i, line in enumerate(self.field):
            for j, c in enumerate(line):
                fg_ansi = ""
                bg_ansi = ""
                stop = ""

                if self.field[i][j].foreground:
                    fg_ansi = '\033[38;2;%s;%s;%sm' % rgb_from_str(self.field[i][j].foreground)
                    stop = colored.attr("reset")

                if self.field[i][j].background:
                    bg_ansi = '\033[48;2;%s;%s;%sm' % rgb_from_str(self.field[i][j].background)
                    stop = colored.attr("reset")

                char = c.char or " "
                if not skip_next:
                    answer += fg_ansi + bg_ansi + char.encode('utf-8') + stop
                skip_next = wcswidth(char) == 2

            # answer += "...\n"
            answer += "\n"
        return answer 
開發者ID:chubin,項目名稱:rate.sx,代碼行數:27,代碼來源:panela_colors.py

示例2: colorize

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [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 attr [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: print_logo

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def print_logo():

	print ('%s\n%s' % (fg(1), attr(1)))
	print ('%s  /$$$$$$$    /$$$$$$   /$$$$$$$$ %s' % (fg(1), attr(1)))
	print ('%s | $$__  $$  /$$__  $$ | $$_____/ %s' % (fg(1), attr(1)))
	print ('%s | $$  \ $$ | $$  \ $$ | $$       %s' % (fg(1), attr(1)))
	print ('%s | $$$$$$$  | $$$$$$$$ | $$$$$    %s' % (fg(1), attr(1)))
	print ('%s | $$$$$$$  | $$$$$$$$ | $$$$$    %s' % (fg(1), attr(1)))
	print ('%s | $$__  $$ | $$__  $$ | $$__/    %s' % (fg(1), attr(1)))
	print ('%s | $$  \ $$ | $$  | $$ | $$       %s' % (fg(1), attr(1)))
	print ('%s | $$  \ $$ | $$  | $$ | $$       %s' % (fg(1), attr(1)))
	print ('%s | $$$$$$$/ | $$  | $$ | $$       %s' % (fg(1), attr(1)))
	print ('%s |_______/  |__/  |__/ |__/       %s' % (fg(1), attr(1)))
	print "\n"
	print ('%s 	version [0.2.0] %s' % (fg(1), attr('reset')))
 	print "\n"
	return
########################################################################### 
開發者ID:engMaher,項目名稱:BAF,代碼行數:20,代碼來源:BAF_0.2.0.py

示例5: prnt_targets

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def prnt_targets(ip_lst):

	n=len(ip_lst)
	print ('%s\n%s' % (fg(1), attr(1)))
	print ('%s  printing ips & ports .. refer to the targets.txt file for processing them with your own flavor ;) %s' % (fg(1), attr('reset')))
	print ('%s\n%s' % (fg(2), attr(1)))
	for i in range(0,n):
		print(i,ip_lst[i],port_lst[i])
		if(i==0):
			with open("output.txt", "w") as text_file:
    				text_file.write(ip_lst[i]+":"+port_lst[i]+'\n')
		else:
			with open("output.txt", "a") as text_file:
    				text_file.write(ip_lst[i]+":"+port_lst[i]+'\n')
	return
########################################################################### 
開發者ID:engMaher,項目名稱:BAF,代碼行數:18,代碼來源:BAF_0.2.0.py

示例6: compare_with_expected

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [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

示例7: main

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [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

示例8: __log_to_stdout

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def __log_to_stdout(color, date, tag, message):

    """Write entry to stdout"""

    entry = "%s[%s] %s - %s %s\n" % (color, date, tag, message, attr(0))
    __log(stdout, entry)


# Low level file print 
開發者ID:android-dtf,項目名稱:dtf,代碼行數:11,代碼來源:logging.py

示例9: error

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def error(message):

    """Color format a message for errors"""

    if __use_colors():
        return "%s%s%s" % (COLOR_ERR, message, attr(0))
    else:
        return message 
開發者ID:android-dtf,項目名稱:dtf,代碼行數:10,代碼來源:colors.py

示例10: warning

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def warning(message):

    """Color format a message for warnings"""

    if __use_colors():
        return "%s%s%s" % (COLOR_WARN, message, attr(0))
    else:
        return message 
開發者ID:android-dtf,項目名稱:dtf,代碼行數:10,代碼來源:colors.py

示例11: info

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def info(message):

    """Color format a message for informational messages"""

    if __use_colors():
        return "%s%s%s" % (COLOR_INFO, message, attr(0))
    else:
        return message 
開發者ID:android-dtf,項目名稱:dtf,代碼行數:10,代碼來源:colors.py

示例12: verbose

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def verbose(message):

    """Color format a message for verbose messages"""

    if __use_colors():
        return "%s%s%s" % (COLOR_VERB, message, attr(0))
    else:
        return message 
開發者ID:android-dtf,項目名稱:dtf,代碼行數:10,代碼來源:colors.py

示例13: bold

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def bold(message):

    """Format a bold message"""

    if __use_colors():
        return "%s%s%s" % (attr('bold'), message, attr(0))
    else:
        return message 
開發者ID:android-dtf,項目名稱:dtf,代碼行數:10,代碼來源:colors.py

示例14: warn

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def warn(self, msg):
        msg = self._pad(msg)
        msg = "%s %s[WARN]  %s%s" % (self._logtime(), fg('yellow'), attr(0), msg)
        return self.log(msg, 'warn') 
開發者ID:ethgasstation,項目名稱:ethgasstation-backend,代碼行數:6,代碼來源:output.py

示例15: error

# 需要導入模塊: import colored [as 別名]
# 或者: from colored import attr [as 別名]
def error(self, msg):
        msg = self._pad(msg)
        msg = "%s %s[ERROR] %s%s" % (self._logtime(), fg('red'), attr(0), msg)
        return self.log(msg, 'error') 
開發者ID:ethgasstation,項目名稱:ethgasstation-backend,代碼行數:6,代碼來源:output.py


注:本文中的colored.attr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。