2002-03-10 16:28:38 -05:00
|
|
|
use strict;
|
|
|
|
use vars qw($VERSION %IRSSI);
|
|
|
|
|
2005-08-15 18:32:26 -04:00
|
|
|
use Irssi qw(command signal_add signal_add_first active_win
|
|
|
|
settings_get_str settings_get_bool channels windows
|
|
|
|
settings_add_str settings_add_bool get_irssi_dir
|
|
|
|
window_find_refnum signal_stop);
|
2016-09-21 22:21:15 -04:00
|
|
|
$VERSION = '2.20';
|
2002-03-10 16:28:38 -05:00
|
|
|
%IRSSI = (
|
2005-08-15 18:32:26 -04:00
|
|
|
authors => 'Juerd',
|
|
|
|
contact => 'juerd@juerd.nl',
|
|
|
|
name => 'Scroll buffer restorer',
|
|
|
|
description => 'Saves the buffer for /upgrade, so that no information is lost',
|
|
|
|
license => 'Public Domain',
|
|
|
|
url => 'http://juerd.nl/irssi/',
|
2016-09-21 22:21:15 -04:00
|
|
|
changed => 'Thu Sep 22 01:37 CEST 2016',
|
|
|
|
changes => 'Fixed file permissions (leaked everything via filesystem)',
|
2005-08-15 18:32:26 -04:00
|
|
|
note1 => 'This script HAS TO BE in your scripts/autorun!',
|
|
|
|
note2 => 'Perl support must be static or in startup',
|
2002-03-10 16:28:38 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
# Q: How can I get a very smooth and clean upgrade?
|
2005-08-15 18:32:26 -04:00
|
|
|
#
|
2002-03-10 16:28:38 -05:00
|
|
|
# A: /set -clear upgrade_separator
|
|
|
|
# /set upgrade_suppress_join ON (default)
|
|
|
|
# /set channel_sync OFF
|
|
|
|
|
|
|
|
# Q: Can I use color in the upgrade_separator?
|
|
|
|
# Q: Is it possible to save my command history?
|
|
|
|
# Q: Can I prevent the screen from blinking?
|
|
|
|
# Q: Can you make it faster?
|
2005-08-15 18:32:26 -04:00
|
|
|
#
|
2002-03-10 16:28:38 -05:00
|
|
|
# A: Probably not, but if you can do it, tell me how.
|
|
|
|
|
|
|
|
use Irssi::TextUI;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
my %suppress;
|
|
|
|
|
2016-09-21 22:21:15 -04:00
|
|
|
sub _filename { sprintf '%s/scrollbuffer', get_irssi_dir }
|
|
|
|
|
2002-03-10 16:28:38 -05:00
|
|
|
sub upgrade {
|
2016-09-21 22:21:15 -04:00
|
|
|
my $fn = _filename;
|
|
|
|
my $old_umask = umask 0077;
|
|
|
|
open my $fh, q{>}, $fn or die "open $fn: $!";
|
|
|
|
umask $old_umask;
|
|
|
|
|
|
|
|
print $fh join("\0", map $_->{server}->{address} . $_->{name}, channels), "\n";
|
2005-08-15 18:32:26 -04:00
|
|
|
for my $window (windows) {
|
2002-03-10 16:28:38 -05:00
|
|
|
next unless defined $window;
|
|
|
|
next if $window->{name} eq 'status';
|
2005-08-15 18:32:26 -04:00
|
|
|
my $view = $window->view;
|
|
|
|
my $line = $view->get_lines;
|
2002-03-10 16:28:38 -05:00
|
|
|
my $lines = 0;
|
|
|
|
my $buf = '';
|
|
|
|
if (defined $line){
|
|
|
|
{
|
|
|
|
$buf .= $line->get_text(1) . "\n";
|
2005-08-15 18:32:26 -04:00
|
|
|
$line = $line->next;
|
2002-03-10 16:28:38 -05:00
|
|
|
$lines++;
|
|
|
|
redo if defined $line;
|
|
|
|
}
|
|
|
|
}
|
2016-09-21 22:21:15 -04:00
|
|
|
printf $fh "%s:%s\n%s", $window->{refnum}, $lines, $buf;
|
2002-03-10 16:28:38 -05:00
|
|
|
}
|
2016-09-21 22:21:15 -04:00
|
|
|
close $fh;
|
2005-08-15 18:32:26 -04:00
|
|
|
unlink sprintf("%s/sessionconfig", get_irssi_dir);
|
|
|
|
command 'layout save';
|
|
|
|
command 'save';
|
2002-03-10 16:28:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub restore {
|
2016-09-21 22:21:15 -04:00
|
|
|
my $fn = _filename;
|
|
|
|
open my $fh, q{<}, $fn or die "open $fn: $!";
|
|
|
|
unlink $fn or warn "unlink $fn: $!";
|
|
|
|
|
|
|
|
my @suppress = split /\0/, readline $fh;
|
2005-08-15 18:32:26 -04:00
|
|
|
if (settings_get_bool 'upgrade_suppress_join') {
|
2002-03-10 16:28:38 -05:00
|
|
|
chomp $suppress[-1];
|
|
|
|
@suppress{@suppress} = (2) x @suppress;
|
|
|
|
}
|
2005-08-15 18:32:26 -04:00
|
|
|
active_win->command('^window scroll off');
|
2016-09-21 22:21:15 -04:00
|
|
|
while (my $bla = readline $fh){
|
2002-03-10 16:28:38 -05:00
|
|
|
chomp $bla;
|
|
|
|
my ($refnum, $lines) = split /:/, $bla;
|
|
|
|
next unless $lines;
|
2005-08-15 18:32:26 -04:00
|
|
|
my $window = window_find_refnum $refnum;
|
2002-03-10 16:28:38 -05:00
|
|
|
unless (defined $window){
|
2016-09-21 22:21:15 -04:00
|
|
|
readline $fh for 1..$lines;
|
2002-03-10 16:28:38 -05:00
|
|
|
next;
|
|
|
|
}
|
2005-08-15 18:32:26 -04:00
|
|
|
my $view = $window->view;
|
2002-03-10 16:28:38 -05:00
|
|
|
$view->remove_all_lines();
|
|
|
|
$view->redraw();
|
|
|
|
my $buf = '';
|
2016-09-21 22:21:15 -04:00
|
|
|
$buf .= readline $fh for 1..$lines;
|
2005-08-15 18:32:26 -04:00
|
|
|
my $sep = settings_get_str 'upgrade_separator';
|
2002-03-10 16:28:38 -05:00
|
|
|
$sep .= "\n" if $sep ne '';
|
|
|
|
$window->gui_printtext_after(undef, MSGLEVEL_CLIENTNOTICE, "$buf\cO$sep");
|
|
|
|
$view->redraw();
|
|
|
|
}
|
2005-08-15 18:32:26 -04:00
|
|
|
active_win->command('^window scroll on');
|
|
|
|
active_win->command('^scrollback end');
|
2002-03-10 16:28:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub suppress {
|
|
|
|
my ($first, $second) = @_;
|
2015-06-12 13:40:15 -04:00
|
|
|
return unless scalar keys %suppress and settings_get_bool 'upgrade_suppress_join';
|
|
|
|
my $key_part = (grep { /^:?[#!+&]/ } split ' ', $second)[0];
|
|
|
|
$key_part =~ s/^://;
|
|
|
|
my $key = $first->{address} . $key_part;
|
2002-03-10 16:28:38 -05:00
|
|
|
if (exists $suppress{$key} and $suppress{$key}--) {
|
2015-06-12 13:40:15 -04:00
|
|
|
signal_stop();
|
|
|
|
delete $suppress{$key} unless $suppress{$key};
|
2002-03-10 16:28:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-15 18:32:26 -04:00
|
|
|
settings_add_str 'buffer', 'upgrade_separator' => '=Upgrade=';
|
|
|
|
settings_add_bool 'buffer', 'upgrade_suppress_join' => 1;
|
2002-03-10 16:28:38 -05:00
|
|
|
|
2005-08-15 18:32:26 -04:00
|
|
|
signal_add_first 'session save' => 'upgrade';
|
|
|
|
signal_add_first 'session restore' => 'restore';
|
|
|
|
signal_add 'event 366' => 'suppress';
|
|
|
|
signal_add 'event join' => 'suppress';
|
2002-03-10 16:28:38 -05:00
|
|
|
|
2005-08-15 18:32:26 -04:00
|
|
|
unless (-f sprintf('%s/scripts/autorun/buf.pl', get_irssi_dir)) {
|
2002-03-10 16:28:38 -05:00
|
|
|
Irssi::print('PUT THIS SCRIPT IN ~/.irssi/scripts/autorun/ BEFORE /UPGRADING!!');
|
|
|
|
}
|
2016-09-21 22:21:15 -04:00
|
|
|
|
|
|
|
# Remove any left-over file. If 'session' doesn't exist (created by irssi
|
|
|
|
# during /UPGRADE), neither should our file.
|
|
|
|
unless (-e sprintf('%s/session', get_irssi_dir)) {
|
|
|
|
my $fn = _filename;
|
|
|
|
unlink $fn or warn "unlink $fn: $!" if -e $fn;
|
|
|
|
}
|