本文整理匯總了Python中colored.fg方法的典型用法代碼示例。如果您正苦於以下問題:Python colored.fg方法的具體用法?Python colored.fg怎麽用?Python colored.fg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類colored
的用法示例。
在下文中一共展示了colored.fg方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: color_text
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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
示例2: colorize
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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))
示例3: colorize
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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))
示例4: display_list_models
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [as 別名]
def display_list_models():
models = sct.deepseg.models.list_models()
# Display beautiful output
color = {True: 'green', False: 'red'}
default = {True: '[*]', False: ''}
print("{:<25s}DESCRIPTION".format("MODEL"))
print("-" * 80)
for name_model, value in models.items():
path_model = sct.deepseg.models.folder(name_model)
print("{}{}".format(
colored.stylize(''.join((name_model, default[value['default']])).ljust(25),
colored.fg(color[sct.deepseg.models.is_valid(path_model)])),
colored.stylize(value['description'],
colored.fg(color[sct.deepseg.models.is_valid(path_model)]))
))
print(
'\nLegend: {} | {} | default: {}\n'.format(
colored.stylize("installed", colored.fg(color[True])),
colored.stylize("not installed", colored.fg(color[False])),
default[True]))
exit(0)
示例5: display_list_tasks
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [as 別名]
def display_list_tasks():
tasks = sct.deepseg.models.list_tasks()
# Display beautiful output
color = {True: 'green', False: 'red'}
default = {True: '[*]', False: ''}
print("{:<20s}{:<50s}MODELS".format("TASK", "DESCRIPTION"))
print("-" * 80)
for name_task, value in tasks.items():
path_models = [sct.deepseg.models.folder(name_model) for name_model in value['models']]
are_models_valid = [sct.deepseg.models.is_valid(path_model) for path_model in path_models]
task_status = colored.stylize(name_task.ljust(20),
colored.fg(color[all(are_models_valid)]))
description_status = colored.stylize(value['description'].ljust(50),
colored.fg(color[all(are_models_valid)]))
models_status = ', '.join([colored.stylize(model_name,
colored.fg(color[is_valid]))
for model_name, is_valid in zip(value['models'], are_models_valid)])
print("{}{}{}".format(task_status, description_status, models_status))
print(
'\nLegend: {} | {} | default: {}\n'.format(
colored.stylize("installed", colored.fg(color[True])),
colored.stylize("not installed", colored.fg(color[False])),
default[True]))
exit(0)
示例6: parseCookies
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [as 別名]
def parseCookies(self, cookie):
try:
cookies = cookie.split(';')
for i in cookies:
if len(i) != 0:
try:
key = i.split('=')[0]
value = i.split('=')[1]
self.new.update({key.strip():value.strip()})
except IndexError:
print(fg(1)+'Cookie Error: '+self.rs+str(i))
continue
except IndexError:
print(fg(1)+'Cookies Error: '+self.rs+str(cookie))
return self.new
#Handle the parsing of a user supplied proxy
示例7: print_logo
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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
###########################################################################
示例8: prnt_targets
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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
###########################################################################
示例9: hr_text
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [as 別名]
def hr_text(text):
t_len = len(text) + 2
pad_len = (TARGET_CHAR_WIDTH - t_len) // 2
padding = '-'.join(["" for i in range(pad_len)])
s = padding + " " + text + " " + padding
print(stylize(s, fg("yellow")))
示例10: hr
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [as 別名]
def hr(bold=False):
if bold:
print(stylize("--------------------------", fg("yellow")))
else:
print(stylize("--------------------------", fg("blue")))
示例11: compare_with_expected
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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
示例12: main
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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)
示例13: warn
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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')
示例14: error
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [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')
示例15: info
# 需要導入模塊: import colored [as 別名]
# 或者: from colored import fg [as 別名]
def info(self, msg):
msg = self._pad(msg)
msg = "%s %s[INFO] %s%s" % (self._logtime(), fg('cyan'), attr(0), msg)
return self.log(msg, 'info')