html/wisestamp.pl
1 #################################
2 # WISESTAMP MANUAL #
3 #################################
4 # #
5 # /set wisestamp_indent [num] #
6 # #
7 #################################
8
9 use Irssi;
10 use strict;
11 use vars qw($VERSION %IRSSI);
12
13 $VERSION = "1.1";
14 %IRSSI = (
15 authors => 'Antti Ruokomäki',
16 contact => 'antti.ruokomaki@mbnet.fi',
17 name => 'wisestamp',
18 description => 'If timestamp_timeout is used, the text '.
19 'will be indented when the stamp is hidden',
20 license => 'Public Domain',
21 changed => 'Wed Apr 12 22:46:00 2006'
22 );
23
24
25 my $timeout;
26 my $indent_str;
27
28 # $inprogress prevents infinite printint loops
29 my $inprogress = 0;
30
31 # The main function
32 sub show_stamp_shadow {
33
34 return if ($inprogress
35 || $timeout == '0'
36 || Irssi::settings_get_bool('timestamps') == 0);
37
38 $inprogress = 1;
39
40 my ($destination, $text, $stripped) = @_;
41 my $last_stamp = $destination->{window}->{last_timestamp};
42 my $time_from_last_stamp = time() - $last_stamp;
43
44 # Add indent if timestamp is hidden
45 if( $time_from_last_stamp < $timeout ) {
46 $text = $indent_str.$text;
47 }
48
49 # Output the manipulated text
50 Irssi::signal_emit('print text', $destination, $text, $stripped);
51 $inprogress = 0;
52 Irssi::signal_stop();
53 }
54
55
56 # Reset settings on startup and when settings change
57 sub check_settings {
58
59 # Recalculate the indent string
60 my $indent = Irssi::settings_get_int('wisestamp_indent');
61 $indent_str = '';
62 for (my $count=0; $count<$indent; $count++) {
63 $indent_str .= ' ';
64 }
65
66 # Check out the timeout
67 $timeout = Irssi::settings_get_str('timestamp_timeout');
68 }
69
70
71 Irssi::settings_add_int('wisestamp', 'wisestamp_indent', 5);
72 Irssi::signal_add('setup changed' , \&check_settings);
73 Irssi::signal_add('print text' , \&show_stamp_shadow);
74
75 check_settings();