def _remove_infobar(): """remove the infobar for moc_control""" weechat.bar_remove(weechat.bar_search(SCRIPT_NAME))
def bufferbar_item_cb(*kwargs): global keydict window = kwargs[2] infolist = weechat.infolist_get("window", "", "") curBuffer = None while weechat.infolist_next(infolist): if weechat.infolist_pointer(infolist, "pointer") == window: curBuffer = weechat.infolist_pointer(infolist, "buffer") weechat.infolist_free(infolist) chars = 0 width = -1 bufferbarPtr = weechat.bar_search("bufferbar") bar = weechat.infolist_get("bar_window", "", "") while weechat.infolist_next(bar): if weechat.infolist_pointer(bar, "bar") == bufferbarPtr: width = weechat.infolist_integer(bar, "width") break weechat.infolist_free(bar) activeBuffers = {} hotlist = weechat.infolist_get("hotlist", "", "") while weechat.infolist_next(hotlist): number = str(weechat.infolist_integer(hotlist, "buffer_number")) priority = weechat.infolist_integer(hotlist, "priority") activeBuffers[number] = priority weechat.infolist_free(hotlist) result = weechat.color("red") + "[" + weechat.color("reset") chars += 1 first = True buffers = weechat.infolist_get("buffer", "", "") while weechat.infolist_next(buffers): if not weechat.infolist_integer(buffers, "active"): continue if not first: result += " " chars += 1 else: first = False if weechat.config_get_plugin("short_names") == "on": name = weechat.infolist_string(buffers, "short_name") else: name = weechat.infolist_string(buffers, "name") number = str(weechat.infolist_integer(buffers, "number")) numberstr = "[" + number + "]" if number in keydict: numberstr = keydict[number] + " " colorFg = weechat.config_get_plugin("color_default") if weechat.infolist_pointer(buffers, "pointer") == curBuffer: colorFg = weechat.config_get_plugin("color_current") elif number in activeBuffers: colorFg = weechat.config_get_plugin("color_hotlist_" + hotlistLevel[activeBuffers[number]]) length = len(numberstr.decode("utf-8")) + len(name.decode("utf-8")) if length > width - 2: numlen = len(numberstr.decode("utf-8")) l = width - 2 - numlen name = name[:l] length = l + numlen first = True if chars + length + 1 >= width: result += " " * (width - chars - 1) result += weechat.color("red") + "][" + weechat.color("reset") chars = 1 result += "%s%s%s%s%s%s" % ( weechat.color(weechat.config_get_plugin("color_number")), numberstr, weechat.color("reset"), weechat.color(colorFg), name, weechat.color("reset"), ) chars += length result += weechat.color("red") + "]" + weechat.color("reset") weechat.infolist_free(buffers) return result