comparison irssi/scripts/queryresume.pl @ 148:4e92ca6c779a

add irssi conf
author zegervdv <zegervdv@me.com>
date Sat, 18 Oct 2014 10:06:58 +0200
parents
children
comparison
equal deleted inserted replaced
147:0d420021bd5d 148:4e92ca6c779a
1 # QueryResume by Stefan Tomanek <[email protected]>
2 #
3 use strict;
4
5 use vars qw($VERSION %IRSSI);
6 $VERSION = '2003021201';
7 %IRSSI = (
8 authors => 'Stefan \'tommie\' Tomanek',
9 contact => '[email protected]',
10 name => 'QueryResume',
11 description => 'restores the last lines of a query on re-creation',
12 license => 'GPLv2',
13 modules => 'Date::Format File::Glob',
14 changed => $VERSION,
15 );
16
17 use Irssi 20020324;
18 use Date::Format;
19 use File::Glob ':glob';
20
21 sub draw_box ($$$$) {
22 my ($title, $text, $footer, $colour) = @_;
23 my $box = '';
24 $box .= '%R,--[%n%9%U'.$title.'%U%9%R]%n'."\n";
25 foreach (split(/\n/, $text)) {
26 $box .= '%R|%n '.$_."\n";
27 }
28 $box .= '%R`--<%n'.$footer.'%R>->%n';
29 $box =~ s/%.//g unless $colour;
30 return $box;
31 }
32
33 sub sig_window_item_new ($$) {
34 my ($win, $witem) = @_;
35 return unless (ref $witem && $witem->{type} eq 'QUERY');
36 my @data;
37 my $filename = Irssi::settings_get_str('autolog_path');
38 my $servertag = $witem->{server}->{tag};
39 my $name = lc $witem->{name};
40 $filename =~ s/(\$tag|\$1)/$servertag/g;
41 $filename =~ s/\$0/$name/g;
42 my @lt = localtime(time);
43 my $zone;
44 $filename = strftime($filename, @lt, $zone);
45 $filename =~ s/(\[|\])/\\$1/g;
46 local *F;
47 open(F, "<".bsd_glob($filename));
48 my $lines = Irssi::settings_get_int('queryresume_lines');
49 foreach (<F>) {
50 unless (/^--- Log/) {
51 push(@data, $_);
52 shift(@data) if (@data > $lines);
53 }
54 }
55 my $text;
56 $text .= $_ foreach @data;
57 $text =~ s/%/%%/g;
58 $witem->print(draw_box('QueryResume', $text, $filename, 1), MSGLEVEL_CLIENTCRAP) if $text;
59 }
60
61 Irssi::settings_add_int($IRSSI{name}, 'queryresume_lines', 10);
62
63 Irssi::signal_add('window item new', 'sig_window_item_new');
64