Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # trackbar.pl
- #
- # This little script will do just one thing: it will draw a line each time you
- # switch away from a window. This way, you always know just upto where you've
- # been reading that window :) It also removes the previous drawn line, so you
- # don't see double lines.
- #
- # Usage:
- #
- # The script works right out of the box, but if you want you can change
- # the working by /set'ing the following variables:
- #
- # trackbar_string The characters to repeat to draw the bar
- # trackbar_style The style for the bar, %r is red for example
- # See formats.txt that came with irssi
- # trackbar_require_seen Only clear the trackbar if it has been scrolled to
- #
- # /mark is a command that will redraw the line at the bottom. However! This
- # requires irssi version after 20021228. otherwise you'll get the error
- # redraw: unknown command, and your screen is all goofed up :)
- #
- # /trackbar
- # /trackbar goto Jump to where the trackbar is, to pick up reading
- #
- # /trackbar keep Keep this window's trackbar where it is the next time
- # you switch windows (then this flag is cleared again)
- #
- # /mark
- # /trackbar mark Remove the old trackbar and mark the bottom of this
- # window with a new trackbar
- #
- # /trackbar remove Remove this window's trackbar
- #
- # /trackbar removeall Remove all windows' trackbars
- #
- # /trackbar resize Force resize of trackbars
- #
- # /upgrade & buf.pl notice: This version tries to remove the trackbars before
- # the upgrade is done, so buf.pl does not restore them, as they are not removeable
- # afterwards by trackbar. Unfortiounatly, to make this work, trackbar and buf.pl
- # need to be loaded in a specific order. Please experiment to see which order works
- # for you (strangely, it differs from configuration to configuration, something I will
- # try to fix in a next version)
- #
- # Authors:
- # - Main maintainer & author: Peter 'kinlo' Leurs
- # - Many thanks to Timo 'cras' Sirainen for placing me on my way
- # - on-upgrade-remove-line patch by Uwe Dudenhoeffer
- #
- # Version history:
- # 1.4: - Changed our's by my's so the irssi script header is valid
- # - Removed utf-8 support. In theory, the script should work w/o any
- # problems for utf-8, just set trackbar_string to a valid utf-8 character
- # and everything *should* work. However, this script is being plagued by
- # irssi internal bugs. The function Irssi::settings_get_str does NOT handle
- # unicode strings properly, hence you will notice problems when setting the bar
- # to a unicode char. For changing your bar to utf-8 symbols, read the line sub.
- # 1.3: - Upgrade now removes the trackbars.
- # - Some code cleanups, other defaults
- # - /mark sets the line to the bottom
- # 1.2: - Support for utf-8
- # - How the bar looks can now be configured with trackbar_string
- # and trackbar_style
- # 1.1: - Fixed bug when closing window
- # 1.0: - Initial release
- #
- #
- # Call for help!
- #
- # There is a trackbar version 2.0 that properly handles resizes and immediate config change
- # activation. However, there is/are some bug(s) in irssi's main buffer/window code that causes
- # irssi to 'forget' lines, which is ofcourse completly unaccepteable. I haven't found the time
- # nor do I know the irssi's internals enough to find and fix this bug, if you want to help, please
- # contact me, I'll give you a copy of the 2.0 version that will immediatly show you the problems.
- #
- # Known bugs:
- # - if you /clear a window, it will be uncleared when returning to the window
- # - UTF-8 characters in the trackbar_string doesnt work. This is an irssi bug.
- # - if you resize your irssi (in xterm or so) the bar is not resized
- # - changing the trackbar style is only visible after returning to a window
- # however, changing style/resize takes in effect after you left the window.
- #
- # Whishlist/todo:
- # - instead of drawing a line, just invert timestamp or something,
- # to save a line (but I don't think this is possible with current irssi)
- # - some pageup keybinding possibility, to scroll up upto the trackbar
- # - <@coekie> kinlo: if i switch to another window, in another split window, i
- # want the trackbar to go down in the previouswindow in that splitwindow :)
- # - < bob_2> anyway to clear the line once the window is read?
- # - < elho> kinlo: wishlist item: a string that gets prepended to the repeating pattern
- # - < elho> an option to still have the timestamp in front of the bar
- # - < elho> oh and an option to not draw it in the status window :P
- #
- # BTW: when you have feature requests, mailing a patch that works is the fastest way
- # to get it added :p
- use strict;
- use warnings;
- use Encode;
- use Irssi;
- use Irssi::TextUI;
- use POSIX qw(strftime);
- our $VERSION = "1.4.7.3";
- our %IRSSI = (
- authors => "Peter 'kinlo' Leurs",
- contact => "peter\@pfoe.be",
- name => "trackbar",
- description => "Shows a bar where you've last read a window",
- license => "GPLv2",
- url => "http://www.pfoe.be/~peter/trackbar/",
- changed => "Thu Feb 20 16:18:08 2003",
- );
- my %config;
- Irssi::theme_register([
- 'trackbar_not_found', '%R>>%n %_Trackbar:%_ No trackbar found in this window.',
- ]);
- Irssi::settings_add_str('trackbar', 'trackbar_string', '-');
- Irssi::settings_add_str('trackbar', 'trackbar_style', '%K');
- Irssi::settings_add_bool('trackbar', 'trackbar_require_seen', 0);
- sub update_config {
- $config{style} = Irssi::settings_get_str('trackbar_style');
- $config{string} = Irssi::settings_get_str('trackbar_string');
- $config{require_seen} = Irssi::settings_get_bool('trackbar_require_seen');
- }
- update_config();
- Irssi::signal_add('setup changed' => 'update_config');
- my (%keep_trackbar, %unseen_trackbar);
- sub remove_one_trackbar {
- my $win = shift;
- my $view = shift || $win->view;
- my $line = $view->get_bookmark('trackbar');
- if (defined $line) {
- my $bottom = $view->{bottom};
- $view->remove_line($line);
- $win->command('^scrollback end') if $bottom && !$win->view->{bottom};
- $view->redraw;
- }
- }
- sub add_one_trackbar {
- my $win = shift;
- my $view = shift || $win->view;
- $win->print(line($win->{width}), MSGLEVEL_NEVER);
- $view->set_bookmark_bottom('trackbar');
- $unseen_trackbar{ $win->{_irssi} } = 1;
- $view->redraw;
- }
- sub update_one_trackbar {
- my $win = shift;
- my $view = shift || $win->view;
- remove_one_trackbar($win, $view);
- add_one_trackbar($win, $view);
- }
- Irssi::signal_add(
- 'window changed' => sub {
- my ($newwindow, $oldwindow) = @_;
- return unless $oldwindow;
- trackbar_update_seen($newwindow);
- return if delete $keep_trackbar{ $oldwindow->{_irssi} };
- trackbar_update_seen($oldwindow);
- return if $config{require_seen} && $unseen_trackbar{ $oldwindow->{_irssi } };
- update_one_trackbar($oldwindow);
- }
- );
- sub trackbar_update_seen {
- my $win = shift;
- return unless $win;
- my $view = $win->view;
- my $line = $view->get_bookmark('trackbar');
- unless ($line) {
- delete $unseen_trackbar{ $win->{_irssi} };
- return;
- }
- my $startline = $view->{startline};
- return unless $startline;
- if ($startline->{info}{time} < $line->{info}{time}
- || $startline->{_irssi} == $line->{_irssi}) {
- delete $unseen_trackbar{ $win->{_irssi} };
- }
- }
- Irssi::signal_register({'gui page scrolled' => [qw/Irssi::UI::Window/]});
- Irssi::signal_add_last('gui page scrolled' => 'trackbar_update_seen');
- sub line {
- my $width = shift;
- my $string = $config{string};
- $string = '-' unless length $string;
- Encode::_utf8_on($string);
- my $length = length $string;
- if ($length == 0) {
- $string = '-';
- $length = 1;
- }
- my $times = $width / $length;
- $times = int(1 + $times) if $times != int($times);
- $string =~ s/%/%%/g;
- return $config{style} . substr($string x $times, 0, $width);
- }
- # Remove trackbars on upgrade - but this doesn't really work if the scripts are not loaded in the correct order... watch out!
- sub remove_all_trackbars {
- for my $window (Irssi::windows) {
- next unless ref $window;
- remove_one_trackbar($window);
- }
- }
- Irssi::signal_add_first( 'session save' => 'remove_all_trackbars' );
- sub UNLOAD {
- remove_all_trackbars();
- }
- sub resize_trackbars {
- for my $win (Irssi::windows) {
- next unless ref $win;
- my $view = $win->view;
- my $line = $view->get_bookmark('trackbar');
- next unless $line;
- my $bottom = $view->{bottom};
- $win->print_after($line, MSGLEVEL_NEVER, line($win->{width}), $line->{info}{time});
- $view->set_bookmark('trackbar', $win->last_line_insert);
- $view->redraw;
- $view->remove_line($line);
- $win->command('^scrollback end') if $bottom && !$win->view->{bottom};
- $view->redraw;
- }
- }
- Irssi::signal_add_last( 'mainwindow resized' => 'resize_trackbars');
- sub goto_trackbar {
- my $win = Irssi::active_win;
- my $line = $win->view->get_bookmark('trackbar');
- if ($line) {
- $win->command("scrollback goto ". strftime("%d %H:%M:%S", localtime($line->{info}{time})));
- } else {
- $win->printformat(MSGLEVEL_CLIENTCRAP, 'trackbar_not_found');
- }
- }
- sub cmd_mark {
- update_one_trackbar(Irssi::active_win);
- }
- sub cmd_trackbar_remove_one {
- remove_one_trackbar(Irssi::active_win);
- }
- sub cmd_keep_once {
- $keep_trackbar{ Irssi::active_win->{_irssi} } = 1;
- }
- sub trackbar_runsub {
- my ($data, $server, $item) = @_;
- $data =~ s/\s+$//g;
- if ($data) {
- Irssi::command_runsub('trackbar', $data, $server, $item);
- } else {
- goto_trackbar();
- }
- }
- Irssi::command_bind('trackbar goto' => 'goto_trackbar');
- Irssi::command_bind('trackbar keep' => 'cmd_keep_once');
- Irssi::command_bind('trackbar mark' => 'cmd_mark');
- Irssi::command_bind('trackbar remove' => 'cmd_trackbar_remove_one');
- Irssi::command_bind('trackbar removeall' => 'remove_all_trackbars');
- Irssi::command_bind('trackbar resize' => 'resize_trackbars');
- Irssi::command_bind('trackbar' => 'trackbar_runsub');
- Irssi::command_bind('mark' => 'cmd_mark');
Advertisement
Add Comment
Please, Sign In to add comment