aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Feist <shabble@metavore.org>2010-12-02 10:48:26 +0000
committerTom Feist <shabble@metavore.org>2010-12-02 10:48:26 +0000
commitd65fdd6056d05dec68d526e477dc1a5b030c926a (patch)
tree45de93c77cb4078fe3b571ab4dc6d114c207f191
parentsb_position: /sb commands now work and cause the update as expected (diff)
downloadirssi-scripts-d65fdd6056d05dec68d526e477dc1a5b030c926a.tar.gz
irssi-scripts-d65fdd6056d05dec68d526e477dc1a5b030c926a.zip
sb_position: account for empty_linecount to fix incorrect position on /clear,
add use TextUI.
-rw-r--r--sb-position/sb_position.pl22
1 files changed, 16 insertions, 6 deletions
diff --git a/sb-position/sb_position.pl b/sb-position/sb_position.pl
index 744229f..5fb9654 100644
--- a/sb-position/sb_position.pl
+++ b/sb-position/sb_position.pl
@@ -21,6 +21,7 @@ use strict;
use warnings;
use Irssi;
+use Irssi::TextUI;
use POSIX qw(ceil);
{ package Irssi::Nick }
@@ -35,8 +36,8 @@ our %IRSSI = (
changed => '2010-12-02'
);
-my ($buf, $size, $pos, $height);
-my ($pages, $cur_page, $buf_percent);
+my ($buf, $size, $pos, $height, $empty);
+my ($pages, $cur_page, $buf_pos_cache);
init();
@@ -76,10 +77,18 @@ sub update_position {
$height = $view->{height};
$size = $buf->{lines_count};
- $pages = ceil($size / $height);
- $pages = 1 unless $pages;
+ $empty = $view->{empty_linecount};
+ $empty = 0 unless $empty;
- $cur_page = ceil(($size - $pos + $height -1) / $height);
+ # $size -= $empty;
+
+ $pages = ceil($size / $height);
+ $pages = 1 unless $pages;
+
+ $pos = $pos < 0 ? 0 : $pos;
+
+ $buf_pos_cache = $size - $pos + ($height - $empty) - 1;
+ $cur_page = ceil($buf_pos_cache / $height);
Irssi::statusbar_items_redraw('position');
}
@@ -91,11 +100,12 @@ sub position_statusbar {
if ($size < $height) {
$percent = 100;
} else {
- $percent = ceil(($size - $pos - 1 + $height) / $size * 100);
+ $percent = ceil($buf_pos_cache / $size * 100);
}
# Alternate view.
#my $sb = "p=$pos, s=$size, h=$height, pp:$cur_page/$pages $percent%%";
my $sb = "Page: $cur_page/$pages $percent%%";
+
$statusbar_item->default_handler($get_size_only, "{sb $sb}", 0, 1);
}