-
Notifications
You must be signed in to change notification settings - Fork 6
/
compact.pl
60 lines (45 loc) · 1.7 KB
/
compact.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use Irssi;
use strict;
use Irssi::TextUI;
use Data::Dumper;
use vars qw($VERSION %IRSSI);
$VERSION = "0.0.0";
%IRSSI = (
authors => 'Wouter Coekaerts',
contact => 'wouter@coekaerts.be, coekie@#irssi',
name => 'compact',
description => 'combines multiple lines from same person into one',
license => 'GPL v2 or later',
url => 'http://wouter.coekaerts.be/irssi/',
);
my %last_public_check;
Irssi::signal_add_priority("message public", sub {
my ($server, $msg, $nick, $address, $target) = @_;
my $chan = $server->channel_find($target);
return if (!$chan);
my $win = $chan->window();
my $view = $win->view;
my $check = $server->{tag} . ' ' . $target . ' ' . $nick;
if ($last_public_check{$win->{refnum}} eq $check) { # from same nick to same channel
# get last lines (is there no better way?)
$view->set_bookmark_bottom('bottom');
my $last = $view->get_bookmark('bottom');
#print Dumper($last);
my $secondlast = $last->prev();
my $lastpublic = $view->get_bookmark('lastpublic');
if ($lastpublic && $secondlast->{'_irssi'} == $lastpublic->{'_irssi'}) { # no line between 2 previous publics, so we can combine
my $secondlast_text = $secondlast->get_text(1);
# remove them
$view->remove_line($last);
$view->remove_line($secondlast);
# replace with a combined line (which doesn't get logged)
$msg =~ s/%/%%/g;
$secondlast_text =~ s/%/%%/g;
$win->print($secondlast_text . ' | ' . $msg, MSGLEVEL_NEVER);
# removing lines needs redraw... unless we could somehow prevent the last message from being printed, but still get logged
$view->redraw();
}
}
$last_public_check{$win->{refnum}} = $check;
$view->set_bookmark_bottom('lastpublic');
}, Irssi::SIGNAL_PRIORITY_LOW + 1);