2 use vars qw($VERSION %IRSSI);
4 use Irssi qw(command signal_add signal_add_first active_win
5 settings_get_str settings_get_bool channels windows
6 settings_add_str settings_add_bool get_irssi_dir
7 window_find_refnum signal_stop);
11 contact => 'juerd@juerd.nl',
12 name => 'Scroll buffer restorer',
13 description => 'Saves the buffer for /upgrade, so that no information is lost',
14 license => 'Public Domain',
15 url => 'http://juerd.nl/irssi/',
16 changed => 'Mon May 13 19:41 CET 2002',
17 changes => 'Severe formatting bug removed * oops, I ' .
18 'exposed Irssi to ircII foolishness * sorry ' .
19 '** removed logging stuff (this is a fix)',
20 note1 => 'This script HAS TO BE in your scripts/autorun!',
21 note2 => 'Perl support must be static or in startup',
24 # Q: How can I get a very smooth and clean upgrade?
26 # A: /set -clear upgrade_separator
27 # /set upgrade_suppress_join ON (default)
28 # /set channel_sync OFF
30 # Q: Can I use color in the upgrade_separator?
31 # Q: Is it possible to save my command history?
32 # Q: Can I prevent the screen from blinking?
33 # Q: Can you make it faster?
35 # A: Probably not, but if you can do it, tell me how.
43 open BUF, sprintf('>%s/scrollbuffer', get_irssi_dir) or die $!;
44 print BUF join("\0", map $_->{server}->{address} . $_->{name}, channels), "\n";
45 for my $window (windows) {
46 next unless defined $window;
47 next if $window->{name} eq 'status';
48 my $view = $window->view;
49 my $line = $view->get_lines;
54 $buf .= $line->get_text(1) . "\n";
57 redo if defined $line;
60 printf BUF "%s:%s\n%s", $window->{refnum}, $lines, $buf;
63 unlink sprintf("%s/sessionconfig", get_irssi_dir);
64 command 'layout save';
69 open BUF, sprintf('<%s/scrollbuffer', get_irssi_dir) or die $!;
70 my @suppress = split /\0/, <BUF>;
71 if (settings_get_bool 'upgrade_suppress_join') {
73 @suppress{@suppress} = (2) x @suppress;
75 active_win->command('^window scroll off');
76 while (my $bla = <BUF>){
78 my ($refnum, $lines) = split /:/, $bla;
80 my $window = window_find_refnum $refnum;
81 unless (defined $window){
85 my $view = $window->view;
86 $view->remove_all_lines();
89 $buf .= <BUF> for 1..$lines;
90 my $sep = settings_get_str 'upgrade_separator';
91 $sep .= "\n" if $sep ne '';
92 $window->gui_printtext_after(undef, MSGLEVEL_CLIENTNOTICE, "$buf\cO$sep");
95 active_win->command('^window scroll on');
96 active_win->command('^scrollback end');
100 my ($first, $second) = @_;
102 unless scalar keys %suppress
103 and settings_get_bool 'upgrade_suppress_join';
104 my $key = $first->{address} .
105 (grep { (s/^://, /^[#!+&]/) } split ' ', $second)[0];
106 if (exists $suppress{$key} and $suppress{$key}--) {
108 delete $suppress{$key} unless $suppress{$key};
112 settings_add_str 'buffer', 'upgrade_separator' => '=Upgrade=';
113 settings_add_bool 'buffer', 'upgrade_suppress_join' => 1;
115 signal_add_first 'session save' => 'upgrade';
116 signal_add_first 'session restore' => 'restore';
117 signal_add 'event 366' => 'suppress';
118 signal_add 'event join' => 'suppress';
120 unless (-f sprintf('%s/scripts/autorun/buf.pl', get_irssi_dir)) {
121 Irssi::print('PUT THIS SCRIPT IN ~/.irssi/scripts/autorun/ BEFORE /UPGRADING!!');