d34n

trackbar-soliton 1.7.4.3

Jul 5th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.25 KB | None | 0 0
  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. # trackbar_require_seen Only clear the trackbar if it has been scrolled to
  17. #
  18. # /mark is a command that will redraw the line at the bottom. However! This
  19. # requires irssi version after 20021228. otherwise you'll get the error
  20. # redraw: unknown command, and your screen is all goofed up :)
  21. #
  22. # /trackbar
  23. # /trackbar goto Jump to where the trackbar is, to pick up reading
  24. #
  25. # /trackbar keep Keep this window's trackbar where it is the next time
  26. # you switch windows (then this flag is cleared again)
  27. #
  28. # /mark
  29. # /trackbar mark Remove the old trackbar and mark the bottom of this
  30. # window with a new trackbar
  31. #
  32. # /trackbar remove Remove this window's trackbar
  33. #
  34. # /trackbar removeall Remove all windows' trackbars
  35. #
  36. # /trackbar resize Force resize of trackbars
  37. #
  38. # /upgrade & buf.pl notice: This version tries to remove the trackbars before
  39. # the upgrade is done, so buf.pl does not restore them, as they are not removeable
  40. # afterwards by trackbar. Unfortiounatly, to make this work, trackbar and buf.pl
  41. # need to be loaded in a specific order. Please experiment to see which order works
  42. # for you (strangely, it differs from configuration to configuration, something I will
  43. # try to fix in a next version)
  44. #
  45. # Authors:
  46. # - Main maintainer & author: Peter 'kinlo' Leurs
  47. # - Many thanks to Timo 'cras' Sirainen for placing me on my way
  48. # - on-upgrade-remove-line patch by Uwe Dudenhoeffer
  49. #
  50. # Version history:
  51. # 1.4: - Changed our's by my's so the irssi script header is valid
  52. # - Removed utf-8 support. In theory, the script should work w/o any
  53. # problems for utf-8, just set trackbar_string to a valid utf-8 character
  54. # and everything *should* work. However, this script is being plagued by
  55. # irssi internal bugs. The function Irssi::settings_get_str does NOT handle
  56. # unicode strings properly, hence you will notice problems when setting the bar
  57. # to a unicode char. For changing your bar to utf-8 symbols, read the line sub.
  58. # 1.3: - Upgrade now removes the trackbars.
  59. # - Some code cleanups, other defaults
  60. # - /mark sets the line to the bottom
  61. # 1.2: - Support for utf-8
  62. # - How the bar looks can now be configured with trackbar_string
  63. # and trackbar_style
  64. # 1.1: - Fixed bug when closing window
  65. # 1.0: - Initial release
  66. #
  67. #
  68. # Call for help!
  69. #
  70. # There is a trackbar version 2.0 that properly handles resizes and immediate config change
  71. # activation. However, there is/are some bug(s) in irssi's main buffer/window code that causes
  72. # irssi to 'forget' lines, which is ofcourse completly unaccepteable. I haven't found the time
  73. # nor do I know the irssi's internals enough to find and fix this bug, if you want to help, please
  74. # contact me, I'll give you a copy of the 2.0 version that will immediatly show you the problems.
  75. #
  76. # Known bugs:
  77. # - if you /clear a window, it will be uncleared when returning to the window
  78. # - UTF-8 characters in the trackbar_string doesnt work. This is an irssi bug.
  79. # - if you resize your irssi (in xterm or so) the bar is not resized
  80. # - changing the trackbar style is only visible after returning to a window
  81. # however, changing style/resize takes in effect after you left the window.
  82. #
  83. # Whishlist/todo:
  84. # - instead of drawing a line, just invert timestamp or something,
  85. # to save a line (but I don't think this is possible with current irssi)
  86. # - some pageup keybinding possibility, to scroll up upto the trackbar
  87. # - <@coekie> kinlo: if i switch to another window, in another split window, i
  88. # want the trackbar to go down in the previouswindow in that splitwindow :)
  89. # - < bob_2> anyway to clear the line once the window is read?
  90. # - < elho> kinlo: wishlist item: a string that gets prepended to the repeating pattern
  91. # - < elho> an option to still have the timestamp in front of the bar
  92. # - < elho> oh and an option to not draw it in the status window :P
  93. #
  94. # BTW: when you have feature requests, mailing a patch that works is the fastest way
  95. # to get it added :p
  96.  
  97. use strict;
  98. use warnings;
  99. use Encode;
  100. use Irssi;
  101. use Irssi::TextUI;
  102. use POSIX qw(strftime);
  103.  
  104. our $VERSION = "1.4.7.3";
  105.  
  106. our %IRSSI = (
  107. authors => "Peter 'kinlo' Leurs",
  108. contact => "peter\@pfoe.be",
  109. name => "trackbar",
  110. description => "Shows a bar where you've last read a window",
  111. license => "GPLv2",
  112. url => "http://www.pfoe.be/~peter/trackbar/",
  113. changed => "Thu Feb 20 16:18:08 2003",
  114. );
  115.  
  116. my %config;
  117.  
  118. Irssi::theme_register([
  119. 'trackbar_not_found', '%R>>%n %_Trackbar:%_ No trackbar found in this window.',
  120. ]);
  121.  
  122. Irssi::settings_add_str('trackbar', 'trackbar_string', '-');
  123. Irssi::settings_add_str('trackbar', 'trackbar_style', '%K');
  124. Irssi::settings_add_bool('trackbar', 'trackbar_require_seen', 0);
  125.  
  126. sub update_config {
  127. $config{style} = Irssi::settings_get_str('trackbar_style');
  128. $config{string} = Irssi::settings_get_str('trackbar_string');
  129. $config{require_seen} = Irssi::settings_get_bool('trackbar_require_seen');
  130. }
  131.  
  132. update_config();
  133.  
  134. Irssi::signal_add('setup changed' => 'update_config');
  135.  
  136. my (%keep_trackbar, %unseen_trackbar);
  137.  
  138. sub remove_one_trackbar {
  139. my $win = shift;
  140. my $view = shift || $win->view;
  141. my $line = $view->get_bookmark('trackbar');
  142. if (defined $line) {
  143. my $bottom = $view->{bottom};
  144. $view->remove_line($line);
  145. $win->command('^scrollback end') if $bottom && !$win->view->{bottom};
  146. $view->redraw;
  147. }
  148. }
  149.  
  150. sub add_one_trackbar {
  151. my $win = shift;
  152. my $view = shift || $win->view;
  153. $win->print(line($win->{width}), MSGLEVEL_NEVER);
  154. $view->set_bookmark_bottom('trackbar');
  155. $unseen_trackbar{ $win->{_irssi} } = 1;
  156. $view->redraw;
  157. }
  158.  
  159. sub update_one_trackbar {
  160. my $win = shift;
  161. my $view = shift || $win->view;
  162. remove_one_trackbar($win, $view);
  163. add_one_trackbar($win, $view);
  164. }
  165.  
  166. Irssi::signal_add(
  167. 'window changed' => sub {
  168. my ($newwindow, $oldwindow) = @_;
  169. return unless $oldwindow;
  170. trackbar_update_seen($newwindow);
  171. return if delete $keep_trackbar{ $oldwindow->{_irssi} };
  172. trackbar_update_seen($oldwindow);
  173. return if $config{require_seen} && $unseen_trackbar{ $oldwindow->{_irssi } };
  174.  
  175. update_one_trackbar($oldwindow);
  176. }
  177. );
  178.  
  179. sub trackbar_update_seen {
  180. my $win = shift;
  181. return unless $win;
  182. my $view = $win->view;
  183. my $line = $view->get_bookmark('trackbar');
  184. unless ($line) {
  185. delete $unseen_trackbar{ $win->{_irssi} };
  186. return;
  187. }
  188. my $startline = $view->{startline};
  189. return unless $startline;
  190.  
  191. if ($startline->{info}{time} < $line->{info}{time}
  192. || $startline->{_irssi} == $line->{_irssi}) {
  193. delete $unseen_trackbar{ $win->{_irssi} };
  194. }
  195. }
  196.  
  197. Irssi::signal_register({'gui page scrolled' => [qw/Irssi::UI::Window/]});
  198. Irssi::signal_add_last('gui page scrolled' => 'trackbar_update_seen');
  199.  
  200.  
  201. sub line {
  202. my $width = shift;
  203. my $string = $config{string};
  204. $string = '-' unless length $string;
  205.  
  206. Encode::_utf8_on($string);
  207. my $length = length $string;
  208.  
  209. if ($length == 0) {
  210. $string = '-';
  211. $length = 1;
  212. }
  213.  
  214. my $times = $width / $length;
  215. $times = int(1 + $times) if $times != int($times);
  216. $string =~ s/%/%%/g;
  217. return $config{style} . substr($string x $times, 0, $width);
  218. }
  219.  
  220. # Remove trackbars on upgrade - but this doesn't really work if the scripts are not loaded in the correct order... watch out!
  221.  
  222. sub remove_all_trackbars {
  223. for my $window (Irssi::windows) {
  224. next unless ref $window;
  225. remove_one_trackbar($window);
  226. }
  227. }
  228.  
  229. Irssi::signal_add_first( 'session save' => 'remove_all_trackbars' );
  230.  
  231. sub UNLOAD {
  232. remove_all_trackbars();
  233. }
  234.  
  235. sub resize_trackbars {
  236. for my $win (Irssi::windows) {
  237. next unless ref $win;
  238. my $view = $win->view;
  239. my $line = $view->get_bookmark('trackbar');
  240. next unless $line;
  241. my $bottom = $view->{bottom};
  242. $win->print_after($line, MSGLEVEL_NEVER, line($win->{width}), $line->{info}{time});
  243. $view->set_bookmark('trackbar', $win->last_line_insert);
  244. $view->redraw;
  245. $view->remove_line($line);
  246. $win->command('^scrollback end') if $bottom && !$win->view->{bottom};
  247. $view->redraw;
  248. }
  249. }
  250.  
  251. Irssi::signal_add_last( 'mainwindow resized' => 'resize_trackbars');
  252.  
  253. sub goto_trackbar {
  254. my $win = Irssi::active_win;
  255. my $line = $win->view->get_bookmark('trackbar');
  256.  
  257. if ($line) {
  258. $win->command("scrollback goto ". strftime("%d %H:%M:%S", localtime($line->{info}{time})));
  259. } else {
  260. $win->printformat(MSGLEVEL_CLIENTCRAP, 'trackbar_not_found');
  261. }
  262. }
  263.  
  264. sub cmd_mark {
  265. update_one_trackbar(Irssi::active_win);
  266. }
  267.  
  268. sub cmd_trackbar_remove_one {
  269. remove_one_trackbar(Irssi::active_win);
  270. }
  271.  
  272. sub cmd_keep_once {
  273. $keep_trackbar{ Irssi::active_win->{_irssi} } = 1;
  274. }
  275.  
  276. sub trackbar_runsub {
  277. my ($data, $server, $item) = @_;
  278. $data =~ s/\s+$//g;
  279.  
  280. if ($data) {
  281. Irssi::command_runsub('trackbar', $data, $server, $item);
  282. } else {
  283. goto_trackbar();
  284. }
  285. }
  286.  
  287. Irssi::command_bind('trackbar goto' => 'goto_trackbar');
  288. Irssi::command_bind('trackbar keep' => 'cmd_keep_once');
  289. Irssi::command_bind('trackbar mark' => 'cmd_mark');
  290. Irssi::command_bind('trackbar remove' => 'cmd_trackbar_remove_one');
  291. Irssi::command_bind('trackbar removeall' => 'remove_all_trackbars');
  292. Irssi::command_bind('trackbar resize' => 'resize_trackbars');
  293. Irssi::command_bind('trackbar' => 'trackbar_runsub');
  294. Irssi::command_bind('mark' => 'cmd_mark');
Advertisement
Add Comment
Please, Sign In to add comment