# encoding: utf-8 # # Copyright (C) 2009 by RegEchse # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # # Provides a (title bar) item with word wrapped buffer title # # History: # 2009-12-06, RegEchse # version 0.1: first public release # # KNOWN ISSUE: # Word wrapping breaks up color display in irc topics. # Due to this problem colors are currently removed before wrapping. # (Maybe support for topic color could be added if anybody wants it.) VERSION = "0.1" ITEM_NAME = "buffer_title_word_wrapped" W = Weechat def weechat_init W.register("title_wrapper", "RegEchse", VERSION, "GPL3", "does (better) word wrapping for multilined title bar", "", "") W.bar_item_new(ITEM_NAME, "build_callback", "") W.hook_signal("buffer_title_changed", "update_title", "") W.hook_command("title_wrapper", "shows some useful information (usage of bar item)", "", "", "", "usage", "") return W::WEECHAT_RC_OK end def usage(data, buffer, args) W.print("", < characters. To use the bar item /set weechat.bar.title.items "#{ITEM_NAME}" and /set weechat.bar.title.filling_top_bottom vertical Note: weechat.bar.title.size defaults to 1 which has to be set to either - a value > 1 to have a fixed line size for title bar or - 0 for auto resized title bar. If you use the latter one you might also consider setting weechat.bar.title.size_max. HELP end def update_title(data, signal, signal_data) W.bar_item_update(ITEM_NAME) return W::WEECHAT_RC_OK end def build_callback(data, item, window) buf = W.window_get_pointer(window, "buffer") text = W.buffer_get_string(buf, "title") width = W.window_get_integer(window, "win_width") if(W.buffer_get_string(buf, "plugin") == "irc") text = W.hook_modifier_exec("irc_color_decode", "0", text) end all = "" while( tmp = text.slice!(0, width) ) i = tmp.rindex(" ") if(text.empty?) all << tmp break elsif(i == width || (text[0,1] == " " && text = text[1..-1]) || i.nil? || tmp[0...i].rstrip.empty?) all << tmp << "\n" else all << tmp[0...i] << "\n" text = tmp[(i+1)..-1] + text end end return all.chomp end