本文整理汇总了Python中weechat.color函数的典型用法代码示例。如果您正苦于以下问题:Python color函数的具体用法?Python color怎么用?Python color使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了color函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: imap_get_unread
def imap_get_unread(data):
"""Return the unread count."""
imap = Imap()
if not w.config_get_plugin('message'):
output = ""
else:
output = '%s' % (
string_eval_expression(w.config_get_plugin('message')))
any_with_unread = False
mailboxes = w.config_get_plugin('mailboxes').split(',')
count = []
for mailbox in mailboxes:
mailbox = mailbox.strip()
unreadCount = imap.unreadCount(mailbox)
if unreadCount > 0:
any_with_unread = True
count.append('%s%s: %s%s' % (
w.color(w.config_get_plugin('mailbox_color')),
mailbox,
w.color(w.config_get_plugin('count_color')),
unreadCount))
imap.logout()
sep = '%s' % (
string_eval_expression(w.config_get_plugin('separator')))
output = output + sep.join(count) + w.color('reset')
return output if any_with_unread else ''
示例2: get_list_commands
def get_list_commands(plugin, input_cmd, input_args):
"""Get list of commands (beginning with current input)."""
global cmdhelp_settings
infolist = weechat.infolist_get('hook', '', 'command,%s*' % input_cmd)
commands = []
plugin_names = []
while weechat.infolist_next(infolist):
commands.append(weechat.infolist_string(infolist, 'command'))
plugin_names.append(
weechat.infolist_string(infolist, 'plugin_name') or 'core')
weechat.infolist_free(infolist)
if commands:
if len(commands) > 1 or commands[0].lower() != input_cmd.lower():
commands2 = []
for index, command in enumerate(commands):
if commands.count(command) > 1:
commands2.append('%s(%s)' % (command, plugin_names[index]))
else:
commands2.append(command)
return '%s%d commands: %s%s' % (
weechat.color(cmdhelp_settings['color_list_count']),
len(commands2),
weechat.color(cmdhelp_settings['color_list']),
', '.join(commands2))
return None
示例3: print_as_lines
def print_as_lines(target, matches, data, limit, total):
"""Prints the output as a line-separated list of nicks."""
prefix = fmt_prefix(data)
mstring = "{}{}".format(fmt_mode_char(data["mode"]), "" if data["set"] else " removal")
mask = fmt_banmask(data["mask"])
target_in_prefix = "_target_" in prefix
i = 0
for name in matches:
if target_in_prefix:
pf = prefix.replace("_target_", "{}{}{}".format(
w.color(w.info_get("irc_nick_color_name", name)),
name, w.color("reset")))
else:
pf = prefix
if (total - (limit - i) == 1) or (i >= limit):
left = total - i
left -= 1 if target_in_prefix else 0
w.prnt(target, "{}\tand {} more match{}..".format(pf, left, "es" if left != 1 else ""))
break
if target_in_prefix:
w.prnt(target, "{}\tmatches {} {}".format(pf, mstring, mask))
else:
w.prnt(target, "{}\t{} {} matches {}".format(pf, mstring, mask, fmt_nick(name)))
i += 1
示例4: format_option
def format_option(match):
"""Replace ${xxx} by its value in option format."""
global cmdhelp_settings, cmdhelp_option_infolist
global cmdhelp_option_infolist_fields
string = match.group()
end = string.find('}')
if end < 0:
return string
field = string[2:end]
color1 = ''
color2 = ''
pos = field.find(':')
if pos:
color1 = field[0:pos]
field = field[pos+1:]
if color1:
color1 = weechat.color(color1)
color2 = weechat.color(cmdhelp_settings['color_option_help'])
fieldtype = cmdhelp_option_infolist_fields.get(field, '')
if fieldtype == 'i':
string = str(weechat.infolist_integer(cmdhelp_option_infolist, field))
elif fieldtype == 's':
string = weechat.infolist_string(cmdhelp_option_infolist, field)
elif fieldtype == 'p':
string = weechat.infolist_pointer(cmdhelp_option_infolist, field)
elif fieldtype == 't':
date = weechat.infolist_time(cmdhelp_option_infolist, field)
# since WeeChat 2.2, infolist_time returns a long integer instead of
# a string
if not isinstance(date, str):
date = time.strftime('%F %T', time.localtime(int(date)))
string = date
return '%s%s%s' % (color1, string, color2)
示例5: get_help_option
def get_help_option(input_args):
"""Get help about option or values authorized for option."""
global cmdhelp_settings, cmdhelp_option_infolist
global cmdhelp_option_infolist_fields
pos = input_args.find(' ')
if pos > 0:
option = input_args[0:pos]
else:
option = input_args
options, description = get_option_list_and_desc(option, False)
if not options and not description:
options, description = get_option_list_and_desc('%s*' % option, True)
if len(options) > 1:
try:
max_options = int(cmdhelp_settings['max_options'])
except ValueError:
max_options = 5
if len(options) > max_options:
text = '%s...' % ', '.join(options[0:max_options])
else:
text = ', '.join(options)
return '%s%d options: %s%s' % (
weechat.color(cmdhelp_settings['color_list_count']),
len(options),
weechat.color(cmdhelp_settings['color_list']),
text)
if description:
return '%s%s' % (weechat.color(cmdhelp_settings['color_option_help']),
description)
return '%sNo help for option %s' % (
weechat.color(cmdhelp_settings['color_no_help']), option)
示例6: vdm_display
def vdm_display(vdm):
""" Display VDMs in buffer. """
global vdm_buffer
weechat.buffer_set(vdm_buffer, "unread", "1")
if weechat.config_get_plugin("number_as_prefix") == "on":
separator = "\t"
else:
separator = " > "
colors = weechat.config_get_plugin("colors").split(";");
vdm2 = vdm[:]
if weechat.config_get_plugin("reverse") == "on":
vdm2.reverse()
for index, item in enumerate(vdm2):
item_id = item["id"]
item_text = item["text"]
if sys.version_info < (3,):
# python 2.x: convert unicode to str (in python 3.x, id and text are already strings)
item_id = item_id.encode("UTF-8")
item_text = item_text.encode("UTF-8")
weechat.prnt_date_tags(vdm_buffer,
0, "notify_message",
"%s%s%s%s%s" %
(weechat.color(weechat.config_get_plugin("color_number")),
item_id,
separator,
weechat.color(colors[0]),
item_text))
colors.append(colors.pop(0))
if index == len(vdm) - 1:
weechat.prnt(vdm_buffer, "------")
elif weechat.config_get_plugin("blank_line") == "on":
weechat.prnt(vdm_buffer, "")
示例7: find_and_process_urls
def find_and_process_urls(string, use_color=True):
new_message = string
color = weechat.color(weechat.config_get_plugin("color"))
reset = weechat.color('reset')
for url in urlRe.findall(string):
max_url_length = int(weechat.config_get_plugin('urllength'))
if len(url) > max_url_length and not should_ignore_url(url):
short_url = get_shortened_url(url)
if use_color:
new_message = new_message.replace(
url, '%(url)s %(color)s[%(short_url)s]%(reset)s' % dict(
color=color,
short_url=short_url,
reset=reset,
url=url
)
)
else:
new_message = new_message.replace(url, short_url)
elif use_color:
# Highlight the URL, even if we aren't going to shorting it
new_message = new_message.replace(
url, '%(color)s %(url)s %(reset)s' % dict(
color=color,
reset=reset,
url=url
)
)
return new_message
示例8: conversation_cb
def conversation_cb(data, buffer, args):
"""
Follows the reply trail until the original was found.
NOTE: This might block for a while.
"""
global twitter
conversation = []
reply_id = args
# Loop as long as there was a reply_id.
while reply_id:
try:
conversation.append(twitter.get_tweet(reply_id))
reply_id = conversation[-1].in_reply_to_status_id
except TwitterError as error:
print_error(error)
break
if conversation:
# Reverse the conversation to get the oldest first.
conversation.reverse()
# Now display the conversation.
print_to_current("%s-------------------" % wc.color("magenta"))
for tweet in conversation:
nick_color = wc.info_get("irc_nick_color", tweet.screen_name)
screen_name = nick_color + tweet.screen_name
expand_urls = wc.config_string_to_boolean(wc.config_get_plugin("expand_urls"))
text = tweet.txt_unescaped
if expand_urls:
text = tweet.txt
output = "%s\t%s" % (screen_name, text)
if tweet.is_retweet:
output += " (RT by @%s)" % tweet.rtscreen_name
output += "\n[#STATUSID: %s]" % tweet.id
print_to_current(output)
print_to_current("%s-------------------" % wc.color("magenta"))
return wc.WEECHAT_RC_OK
示例9: show_favorites_cb
def show_favorites_cb(data, buffer, args):
"""
Show all the tweets that are favourited by the user.
"""
global twitter
try:
favs = twitter.get_favorites()
except TwitterError as error:
print_error(error)
return wc.WEECHAT_RC_OK
if favs:
print_to_current("%sFAVOURITES\t%s-------------------" %
(wc.color("yellow"), wc.color("magenta")))
for fav in favs:
nick_color = wc.info_get("irc_nick_color", fav.screen_name)
screen_name = nick_color + fav.screen_name
expand_urls = wc.config_string_to_boolean(wc.config_get_plugin("expand_urls"))
text = fav.text_unescaped
if expand_urls:
text = fav.text
output = "%s\t%s" % (screen_name, text)
if fav.is_retweet:
output += " (RT by @%s)" % fav.rtscreen_name
output += "\n[#STATUSID: %s]" % fav.id
print_to_current(output)
print_to_current("%s-------------------" % wc.color("magenta"))
return wc.WEECHAT_RC_OK
示例10: urlbar_item_cb
def urlbar_item_cb(data, item, window):
''' Callback that prints the lines in the urlbar '''
global DISPLAY_ALL, urls
try:
visible_amount = int(weechat.config_get_plugin('visible_amount'))
except ValueError:
weechat.prnt('', 'Invalid value for visible_amount setting.')
if not urls:
return 'Empty URL list'
if DISPLAY_ALL:
DISPLAY_ALL = False
printlist = urls
else:
printlist = urls[-visible_amount:]
result = ''
for index, url in enumerate(printlist):
if weechat.config_get_plugin('show_index') == 'on':
index = index+1
result += '%s%2d%s %s \r' %\
(weechat.color("yellow"), index, weechat.color("bar_fg"), url)
else:
result += '%s%s \r' %(weechat.color('bar_fg'), url)
return result
示例11: refresh_line
def refresh_line(self, y):
format = "%%s%%s %%s%%-%ds%%s%%s %%s - %%s" % (self.max_buffer_width-4)
color_time = "cyan"
color_buffer = "red"
color_info = "green"
color_url = "blue"
color_bg_selected = "red"
if y == self.current_line:
color_time = "%s,%s" % (color_time, color_bg_selected)
color_buffer = "%s,%s" % (color_buffer, color_bg_selected)
color_info = "%s,%s" % (color_info, color_bg_selected)
color_url = "%s,%s" % (color_url, color_bg_selected)
color_time = weechat.color(color_time)
color_buffer = weechat.color(color_buffer)
color_info = weechat.color(color_info)
color_url = weechat.color(color_url)
text = ''
if len(self.urls) - 1 > y :
url = self.urls[y]
url_info = self.url_infos[url]
text = format % (color_time,
url_info['time'],
color_buffer,
url_info['buffer'],
color_info,
url_info['info'],
color_url,
url_info['url']
)
weechat.prnt_y(self.url_buffer,y,text)
示例12: nameday_print
def nameday_print(days):
"""Print name day for today and option N days in future."""
global nameday_i18n
today = date.today()
current_time = time.time()
string = '%02d/%02d: %s' % (today.day, today.month,
nameday_get_date(today, gender=True,
colorMale='color_male',
colorFemale='color_female'))
if days < 0:
days = 0
elif days > 50:
days = 50
if days > 0:
string += '%s (' % weechat.color('reset')
for i in range(1, days + 1):
if i > 1:
string += '%s, ' % weechat.color('reset')
date2 = date.fromtimestamp(current_time + ((3600 * 24) * i))
string += '%02d/%02d: %s' % (date2.day, date2.month,
nameday_get_date(date2, gender=True,
colorMale='color_male',
colorFemale='color_female'))
string += '%s)' % weechat.color('reset')
weechat.prnt('', string)
示例13: tc_bar_item
def tc_bar_item (data, item, window):
'''Item constructor'''
global laenge, cursor_pos, tc_input_text, count_over
count_over = "0"
# reverse check for max_chars
reverse_chars = (int(max_chars) - laenge)
if reverse_chars == 0:
reverse_chars = "%s" % ("0")
else:
if reverse_chars < 0:
count_over = "%s%s%s" % (w.color(warn_colour),str(reverse_chars*-1), w.color('default'))
reverse_chars = "%s" % ("0")
else:
reverse_chars = str(reverse_chars)
out_format = format
if laenge >= int(warn):
laenge_warn = "%s%s%s" % (w.color(warn_colour), str(laenge), w.color('default'))
out_format = out_format.replace('%L', laenge_warn)
else:
out_format = out_format.replace('%L', str(laenge))
out_format = out_format.replace('%P', str(cursor_pos))
out_format = out_format.replace('%R', reverse_chars)
out_format = out_format.replace('%C', count_over)
tc_input_text = out_format
return tc_input_text
示例14: search_whois_cb
def search_whois_cb(data, signal, hashtable):
ht = hashtable["output"] # string
ret = re.search(r"(\S+) \* :(.+)$", ht, re.M)
if ret:
masked_ip = ret.group(1)
w.prnt_date_tags("", 0, "no_log", "RESULT about {}{}".format(w.color("*lightblue"), masked_ip))
lst = stick(masked_ip)
for dic in lst:
w.prnt_date_tags(
"",
0,
"no_log",
"\n ".join(
[
"{}#{}: {}".format(w.color("_lightgreen"), dic["number"], dic["login_time"]),
"names: {}{}{} / {} / {}".format(
w.color("*lightred"),
dic["login_nick"][0],
w.color("chat"),
dic["login_nick"][1],
dic["login_nick"][2],
),
"channels: {}".format(dic["login_channels"]),
]
),
)
# else:
# w.prnt_date_tags("", 0, "no_log", "error: Not Found MASKED_IP")
return w.WEECHAT_RC_OK
示例15: tc_bar_item
def tc_bar_item (data, item, window):
'''Item constructor'''
global length, cursor_pos, tc_input_text, count_over,tc_options
count_over = '0'
# reverse check for max_chars
reverse_chars = (int(tc_options['max_chars']) - length)
# reverse_chars = (int(max_chars) - length)
if reverse_chars == 0:
reverse_chars = "%s" % ("0")
else:
if reverse_chars < 0:
count_over = "%s%s%s" % (w.color(tc_options['warn_colour']),str(reverse_chars*-1), w.color('default'))
reverse_chars = "%s" % ("0")
tc_action_cb()
else:
reverse_chars = str(reverse_chars)
out_format = tc_options['format']
if length >= int(tc_options['warn']):
length_warn = "%s%s%s" % (w.color(tc_options['warn_colour']), str(length), w.color('default'))
out_format = out_format.replace('%L', length_warn)
else:
out_format = out_format.replace('%L', str(length))
out_format = out_format.replace('%P', str(cursor_pos))
out_format = out_format.replace('%R', reverse_chars)
out_format = out_format.replace('%C', count_over)
tc_input_text = out_format
return tc_input_text