-
Notifications
You must be signed in to change notification settings - Fork 234
/
showinactive.pl
113 lines (88 loc) · 3.02 KB
/
showinactive.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# This script replaces the following three scripts:
#
# hilightwin, noisyquery, showhilight
#
# It makes the following changes/improvements
# - The text which is shown in your active irssi window is cleaned up after a window change
# - The hilightwin now has the window number so you can see which window had the original info
# - Also privates are shown in current window.
#
# Don't forget to create a window named hilight for the hilightwin functionality!
#
use strict;
use Irssi;
use Irssi::TextUI;
use vars qw($VERSION %IRSSI);
$VERSION = "1.0";
%IRSSI = (
authors => "Peter 'kinlo' Leurs",
contact => "peter\@pfoe.be",
name => "showinactive",
description => "Show whatever needs your attention in active window, and cleans your windows afterwards. Also provides a hilight window. This is a combination of the hilightwin, noisyquery and showhilight scripts",
license => "GNU GPLv2",
changed => "Tue 12 Jul 2016 22:40:40 CEST"
);
# First create a function to write self-erasing/hilightwin text + a cleanup function that is hooked to window changes
my $bookmark_id=0;
sub print_inactive {
my ($text, $window_from) = @_;
# $text =~ s/%/%%/g;
my $window_active = Irssi::active_win();
my $window_hilight = Irssi::window_find_name('hilight');
my $showinactive = 1;
my $showinhilight = 0;
if ($window_hilight) {
$showinhilight = 1;
if ($window_hilight->{refnum} == $window_active->{refnum}) {
$showinactive = 0;
}
}
# anti flood this window protection
if ($bookmark_id > 100) {
$showinactive = 0;
}
if ($window_from->{refnum} == $window_active->{refnum}) {
$showinactive = 0;
}
if ($showinactive) {
$window_active->print("%Y>>>%w ".$text, MSGLEVEL_CLIENTCRAP);
$window_active->view()->set_bookmark_bottom("showinactive_$bookmark_id");
$bookmark_id++;
}
if ($showinhilight) {
$window_hilight->print($text, MSGLEVEL_CLIENTCRAP);
}
}
sub sig_window_changed {
my (undef, $oldwindow) = @_;
if ($oldwindow) {
for(my $i=0; $i<$bookmark_id; $i++) {
my $line = $oldwindow->view()->get_bookmark("showinactive_$i");
$oldwindow->view()->remove_line($line) if defined $line;
}
$bookmark_id=0;
}
}
Irssi::signal_add('window changed', 'sig_window_changed');
# Now that we have self-erasing functionality:
# implement noisyquery:
sub sig_query_created() {
my ($query, $auto) = @_;
my $refnum = $query->window()->{refnum};
if ($auto) {
print_inactive("Query started with ".$query->{name}." in window $refnum", $query->window());
$query->{server}->command("whois ".$query->{name});
}
}
Irssi::signal_add_last('query created', 'sig_query_created');
# and implement hilightwin/showhilight
sub sig_printtext {
my ($dest, $text, $stripped) = @_;
# Sanitize input
$text =~ s/%/%%/g;
if (($dest->{level} & (MSGLEVEL_HILIGHT|MSGLEVEL_MSGS)) && (($dest->{level} & MSGLEVEL_NOHILIGHT) == 0)) {
$text = $dest->{target}.":%K[%w".$dest->{window}->{refnum}."%K]:".$text;
print_inactive($text, $dest->{window});
}
}
Irssi::signal_add('print text', 'sig_printtext');