summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/python/awl.py45
1 files changed, 37 insertions, 8 deletions
diff --git a/scripts/python/awl.py b/scripts/python/awl.py
index cf8bfd434..798b3542f 100644
--- a/scripts/python/awl.py
+++ b/scripts/python/awl.py
@@ -5,22 +5,42 @@
The script is in the public domain.
Leonid Evdokimov (weechat at darkk dot net dot ru)
http://darkk.net.ru/weechat/awl.py
+
+0.1 - initial commit
+0.2 - added `show_servers` option
+0.3 - infobar is actually redrawed only if that's necessary
"""
#######################################################################
import weechat
+from itertools import ifilter
-version = "0.1"
+VERSION = "0.3"
+NAME = "awl"
# how often to refresh infobar
timer_interval = 1
+blist = ()
def cleanup():
weechat.remove_infobar(-1)
return weechat.PLUGIN_RC_OK
+def cfg_boolean(key, default = False):
+ map = {True: 'ON', False: 'OFF'}
+ value = weechat.get_plugin_config(key).upper()
+ if not value in map.values():
+ if value:
+ weechat.prnt("[%s]: invalid %s value (%s), resetting to %s" % (NAME, key, value, map[default]))
+ weechat.set_plugin_config(key, map[default])
+ value = default
+ else:
+ value = ifilter(lambda p: p[1] == value, map.iteritems()).next()[0]
+ return value
+
def update_channels():
- the_string = [];
+ global blist
+ names = ()
buffers = weechat.get_buffer_info()
if buffers != None:
for index, buffer in buffers.iteritems():
@@ -29,19 +49,28 @@ def update_channels():
if len(buffer['channel']):
name = buffer['channel']
elif len(buffer['server']):
- name = "[" + buffer['server'] + "]"
+ if cfg_boolean('show_servers'):
+ name = "[" + buffer['server'] + "]"
+ else:
+ continue
else:
name = "?"
- the_string.append("%i:%s" % (index, name))
- the_string = " ".join(the_string)
- weechat.remove_infobar(-1)
- weechat.print_infobar(0, the_string);
+ names += ("%i:%s" % (index, name), )
+ if (names != blist):
+ the_string = " ".join(names)
+ blist = names
+ weechat.remove_infobar(-1)
+ weechat.print_infobar(0, the_string);
def on_timer():
update_channels()
return weechat.PLUGIN_RC_OK
-if weechat.register("awl", version, "cleanup", "bufferlist in infobar"):
+if weechat.register(NAME, VERSION, "cleanup", "bufferlist in infobar"):
#message handlers are called __before__ buflist is changed, so we don't use them
weechat.add_timer_handler(timer_interval, "on_timer")
+ cfg_boolean('show_servers', False)
update_channels()
+
+# vim:set tabstop=4 softtabstop=4 shiftwidth=4:
+# vim:set expandtab: