# # Copyright (c) 2008 by FlashCode # # 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 . # # Display infolist in a buffer. # # History: # 2008-12-12, FlashCode : # version 0.1-dev: development version # 2008-12-12, FlashCode : # script creation use strict; my $version = "0.1-dev"; my $buffer = ""; my $buffer_title = "infolist.pl $version"; sub buffer_set_title { # get list of infolist available my $list = ""; my $infolist = weechat::infolist_get("hook", "", "infolist"); while (weechat::infolist_next($infolist)) { $list .= " ".weechat::infolist_string($infolist, "infolist_name"); } weechat::infolist_free($infolist); weechat::buffer_set($buffer, "title", $buffer_title." | Infolists:".$list); } sub buffer_input { my ($name, $args) = split(/ /, $_[2], 2); $args = "" if (! defined $args); my $infolist = weechat::infolist_get($name, "", $args); my $item_count = 0; weechat::buffer_clear($buffer); while (weechat::infolist_next($infolist)) { $item_count++; weechat::print($buffer, "") if ($item_count > 1); weechat::print($buffer, weechat::color("green")."[" .weechat::color("lightgreen")."item " .weechat::color("white").$item_count .weechat::color("green")."]"); my @fields = split(/,/, weechat::infolist_fields($infolist)); foreach my $field (@fields) { my ($type, $name) = split(/:/, $field, 2); my $value = ""; $value = weechat::infolist_integer($infolist, $name) if ($type eq "i"); $value = weechat::infolist_string($infolist, $name) if ($type eq "s"); $value = weechat::infolist_pointer($infolist, $name) if ($type eq "p"); $value = weechat::infolist_time($infolist, $name) if ($type eq "t"); my $name_end = "." x (30 - length($name)); weechat::print($buffer, " ".$name.$name_end.": ".weechat::color("cyan").$value); } } weechat::infolist_free($infolist); return weechat::WEECHAT_RC_OK; } sub buffer_close { $buffer = ""; return weechat::WEECHAT_RC_OK; } sub buffer_new { $buffer = weechat::buffer_new("infolist", "buffer_input", "", "buffer_close", ""); buffer_set_title if ($buffer ne "") } sub infolist_cmd { if ($buffer eq "") { buffer_new(); weechat::buffer_set($buffer, "display", "1"); } return weechat::WEECHAT_RC_OK; } weechat::register("infolist", "FlashCode ", $version, "GPL3", "Display infolist in a buffer", "", ""); weechat::hook_command("infolist", "Open buffer used to display infolists", "", "", "", "infolist_cmd", "");