148
|
1 # trackbar.pl
|
|
2 #
|
|
3 # This little script will do just one thing: it will draw a line each time you
|
|
4 # switch away from a window. This way, you always know just upto where you've
|
|
5 # been reading that window :) It also removes the previous drawn line, so you
|
|
6 # don't see double lines.
|
|
7 #
|
|
8 # Usage:
|
|
9 #
|
|
10 # The script works right out of the box, but if you want you can change
|
|
11 # the working by /set'ing the following variables:
|
|
12 #
|
|
13 # trackbar_string The characters to repeat to draw the bar
|
|
14 # trackbar_style The style for the bar, %r is red for example
|
|
15 # See formats.txt that came with irssi
|
|
16 #
|
|
17 # /mark is a command that will redraw the line at the bottom. However! This
|
|
18 # requires irssi version after 20021228. otherwise you'll get the error
|
|
19 # redraw: unknown command, and your screen is all goofed up :)
|
|
20 #
|
|
21 # /upgrade & buf.pl notice: This version tries to remove the trackbars before
|
|
22 # the upgrade is done, so buf.pl does not restore them, as they are not removeable
|
|
23 # afterwards by trackbar. Unfortiounatly, to make this work, trackbar and buf.pl
|
|
24 # need to be loaded in a specific order. Please experiment to see which order works
|
|
25 # for you (strangely, it differs from configuration to configuration, something I will
|
|
26 # try to fix in a next version)
|
|
27 #
|
|
28 # Authors:
|
|
29 # - Main maintainer & author: Peter 'kinlo' Leurs
|
|
30 # - Many thanks to Timo 'cras' Sirainen for placing me on my way
|
|
31 # - on-upgrade-remove-line patch by Uwe Dudenhoeffer
|
|
32 #
|
|
33 # Version history:
|
|
34 # 1.4: - Changed our's by my's so the irssi script header is valid
|
|
35 # - Removed utf-8 support. In theory, the script should work w/o any
|
|
36 # problems for utf-8, just set trackbar_string to a valid utf-8 character
|
|
37 # and everything *should* work. However, this script is being plagued by
|
|
38 # irssi internal bugs. The function Irssi::settings_get_str does NOT handle
|
|
39 # unicode strings properly, hence you will notice problems when setting the bar
|
|
40 # to a unicode char. For changing your bar to utf-8 symbols, read the line sub.
|
|
41 # 1.3: - Upgrade now removes the trackbars.
|
|
42 # - Some code cleanups, other defaults
|
|
43 # - /mark sets the line to the bottom
|
|
44 # 1.2: - Support for utf-8
|
|
45 # - How the bar looks can now be configured with trackbar_string
|
|
46 # and trackbar_style
|
|
47 # 1.1: - Fixed bug when closing window
|
|
48 # 1.0: - Initial release
|
|
49 #
|
|
50 #
|
|
51 # Call for help!
|
|
52 #
|
|
53 # There is a trackbar version 2.0 that properly handles resizes and immediate config change
|
|
54 # activation. However, there is/are some bug(s) in irssi's main buffer/window code that causes
|
|
55 # irssi to 'forget' lines, which is ofcourse completly unaccepteable. I haven't found the time
|
|
56 # nor do I know the irssi's internals enough to find and fix this bug, if you want to help, please
|
|
57 # contact me, I'll give you a copy of the 2.0 version that will immediatly show you the problems.
|
|
58 #
|
|
59 # Known bugs:
|
|
60 # - if you /clear a window, it will be uncleared when returning to the window
|
|
61 # - UTF-8 characters in the trackbar_string doesnt work. This is an irssi bug.
|
|
62 # - if you resize your irssi (in xterm or so) the bar is not resized
|
|
63 # - changing the trackbar style is only visible after returning to a window
|
|
64 # however, changing style/resize takes in effect after you left the window.
|
|
65 #
|
|
66 # Whishlist/todo:
|
|
67 # - instead of drawing a line, just invert timestamp or something,
|
|
68 # to save a line (but I don't think this is possible with current irssi)
|
|
69 # - some pageup keybinding possibility, to scroll up upto the trackbar
|
|
70 # - <@coekie> kinlo: if i switch to another window, in another split window, i
|
|
71 # want the trackbar to go down in the previouswindow in that splitwindow :)
|
|
72 # - < bob_2> anyway to clear the line once the window is read?
|
|
73 # - < elho> kinlo: wishlist item: a string that gets prepended to the repeating pattern
|
|
74 # - < elho> an option to still have the timestamp in front of the bar
|
|
75 # - < elho> oh and an option to not draw it in the status window :P
|
|
76 #
|
|
77 # BTW: when you have feature requests, mailing a patch that works is the fastest way
|
|
78 # to get it added :p
|
|
79
|
|
80 use strict;
|
|
81 use 5.6.1;
|
|
82 use Irssi;
|
|
83 use Irssi::TextUI;
|
|
84
|
|
85 my $VERSION = "1.4";
|
|
86
|
|
87 my %IRSSI = (
|
|
88 authors => "Peter 'kinlo' Leurs",
|
|
89 contact => "peter\@pfoe.be",
|
|
90 name => "trackbar",
|
|
91 description => "Shows a bar where you've last read a window",
|
|
92 license => "GPLv2",
|
|
93 url => "http://www.pfoe.be/~peter/trackbar/",
|
|
94 changed => "Thu Feb 20 16:18:08 2003",
|
|
95 );
|
|
96
|
|
97 my %config;
|
|
98
|
|
99 Irssi::settings_add_str('trackbar', 'trackbar_string' => '-');
|
|
100 $config{'trackbar_string'} = Irssi::settings_get_str('trackbar_string');
|
|
101
|
|
102 Irssi::settings_add_str('trackbar', 'trackbar_style' => '%K');
|
|
103 $config{'trackbar_style'} = Irssi::settings_get_str('trackbar_style');
|
|
104
|
|
105 Irssi::signal_add(
|
|
106 'setup changed' => sub {
|
|
107 $config{'trackbar_string'} = Irssi::settings_get_str('trackbar_string');
|
|
108 $config{'trackbar_style'} = Irssi::settings_get_str('trackbar_style');
|
|
109 if ($config{'trackbar_style'} =~ /(?<!%)[^%]|%%|%$/) {
|
|
110 Irssi::print(
|
|
111 "trackbar: %RWarning!%n 'trackbar_style' seems to contain "
|
|
112 . "printable characters. Only use format codes (read "
|
|
113 . "formats.txt).", MSGLEVEL_CLIENTERROR);
|
|
114 }
|
|
115 }
|
|
116 );
|
|
117
|
|
118 Irssi::signal_add(
|
|
119 'window changed' => sub {
|
|
120 my (undef, $oldwindow) = @_;
|
|
121
|
|
122 if ($oldwindow) {
|
|
123 my $line = $oldwindow->view()->get_bookmark('trackbar');
|
|
124 $oldwindow->view()->remove_line($line) if defined $line;
|
|
125 $oldwindow->print(line($oldwindow->{'width'}), MSGLEVEL_NEVER);
|
|
126 $oldwindow->view()->set_bookmark_bottom('trackbar');
|
|
127 }
|
|
128 }
|
|
129 );
|
|
130
|
|
131 sub line {
|
|
132 my $width = shift;
|
|
133 my $string = $config{'trackbar_string'};
|
|
134 $string = '-' unless defined $string;
|
|
135
|
|
136 # There is a bug in irssi's utf-8 handling on config file settings, as you
|
|
137 # can reproduce/see yourself by the following code sniplet:
|
|
138 #
|
|
139 # my $quake = pack 'U*', 8364; # EUR symbol
|
|
140 # Irssi::settings_add_str 'temp', 'temp_foo' => $quake;
|
|
141 # Irssi::print length $quake;
|
|
142 # # prints 1
|
|
143 # Irssi::print length Irssi::settings_get_str 'temp_foo';
|
|
144 # # prints 3
|
|
145 #
|
|
146 #
|
|
147 # Trackbar used to have a workaround, but on recent versions of perl/irssi
|
|
148 # it does no longer work. Therefore, if you want your trackbar to contain
|
|
149 # unicode characters, uncomment the line below for a nice full line, or set
|
|
150 # the string to whatever char you want.
|
|
151
|
|
152 # $string = pack('U*', 0x2500);
|
|
153
|
|
154
|
|
155 my $length = length $string;
|
|
156
|
|
157 if ($length == 0) {
|
|
158 $string = '-';
|
|
159 $length = 1;
|
|
160 }
|
|
161
|
|
162 my $times = $width / $length;
|
|
163 $times = int(1 + $times) if $times != int($times);
|
|
164 $string =~ s/%/%%/g;
|
|
165 return $config{'trackbar_style'} . substr($string x $times, 0, $width);
|
|
166 }
|
|
167
|
|
168 # Remove trackbars on upgrade - but this doesn't really work if the scripts are not loaded in the correct order... watch out!
|
|
169
|
|
170 Irssi::signal_add_first( 'session save' => sub {
|
|
171 for my $window (Irssi::windows) {
|
|
172 next unless defined $window;
|
|
173 my $line = $window->view()->get_bookmark('trackbar');
|
|
174 $window->view()->remove_line($line) if defined $line;
|
|
175 }
|
|
176 }
|
|
177 );
|
|
178
|
|
179 sub cmd_mark {
|
|
180 my $window = Irssi::active_win();
|
|
181 # return unless defined $window;
|
|
182 my $line = $window->view()->get_bookmark('trackbar');
|
|
183 $window->view()->remove_line($line) if defined $line;
|
|
184 $window->print(line($window->{'width'}), MSGLEVEL_NEVER);
|
|
185 $window->view()->set_bookmark_bottom('trackbar');
|
|
186 Irssi::command("redraw");
|
|
187 }
|
|
188
|
|
189 Irssi::command_bind('mark', 'cmd_mark');
|