html/il.pl


   1 #
   2 # for all who dont like perl:
   3 #   inputlength = "{sb length: $@L}";
   4 #
   5 #  with leading spaces: (3 spaces in example)
   6 #    inputlength = "{sb $[-!3]@L}"; 
   7 #
   8 #  with leading char "-"
   9 #
  10 #    inputlength = "{sb $[-!3-]@L}"; 
  11 #
  12 #   you cant use numbers here. if you want to use the numbers use the 
  13 #   perl script
  14 #
  15 #
  16 # thanks to: Wouter Coekaerts <wouter@coekaerts.be> aka coekie
  17 #
  18 # add one of these 2 lines to your config in statusbar items section
  19 # 
  20 # the perl scripts  reacts on every keypress and updates the counter. 
  21 # if you dont need/want this the settings are maybe enough for you.
  22 # with the settings the item is update with a small delay.
  23 #
  24 
  25 use strict;
  26 use Irssi 20021105; 
  27 use Irssi::TextUI;
  28 
  29 use vars qw($VERSION %IRSSI);
  30 $VERSION = '0.0.5';
  31 %IRSSI = (
  32     authors     => 'Marcus Rueckert',
  33     contact     => 'darix@irssi.org',
  34     name        => 'inputlength',
  35     description => 'adds a statusbar item which show length of the inputline',
  36     license     => 'BSD License or something more liberal',
  37     url         => 'http://www.irssi.de./',
  38     changed     => '2003-01-13T13:17:44Z'
  39 );
  40 
  41 sub beancounter {
  42     my ( $sbItem, $get_size_only ) = @_;
  43 
  44     my ( $width, $padChar, $padNum, $length ); 
  45 
  46 	#
  47 	# getting settings
  48 	#
  49     $width = Irssi::settings_get_int ( 'inputlength_width' );
  50 	$padChar = Irssi::settings_get_str ( 'inputlength_padding_char' );
  51 
  52 	#
  53 	# only one char allowed
  54 	#
  55     $padChar =~ s/^(.).*?$/$1/;
  56 
  57 	#
  58 	# do we have to deal wit numbers for padding?
  59     #  
  60     if ( $padChar =~ m/\d/ ) {
  61 		$padNum = $padChar;
  62 		$padChar = '-';
  63 	};
  64 
  65 	#
  66 	# getting formatted lengh
  67 	#
  68 	$length = Irssi::parse_special ( "\$[-!$width$padChar]\@L" );
  69 
  70 	#
  71 	# did we have a number?
  72 	#
  73     $length =~ s/$padChar/$padNum/g if ( $padNum ne '' );
  74 
  75     $sbItem->default_handler ( $get_size_only, "{sb $length}", undef, 1 );
  76 }
  77 
  78 Irssi::statusbar_item_register ( 'inputlength', 0, 'beancounter' );
  79 #
  80 # ToDo:
  81 #  - statusbar item register doesnt support function references. 
  82 #    so we have to stuck to the string and wait for cras.
  83 #
  84 
  85 Irssi::signal_add_last 'gui key pressed' => sub {
  86     Irssi::statusbar_items_redraw ( 'inputlength' );
  87 };
  88 
  89 Irssi::settings_add_int ( 'inputlength', 'inputlength_width', 0 );
  90 #
  91 # setting:
  92 # 
  93 # 0 means it resizes automatically
  94 # greater means it has at least a size of n chars.
  95 # it will grow if the space is to space is too small
  96 #
  97  
  98 Irssi::settings_add_str ( 'inputlength', 'inputlength_padding_char', " " );
  99 #
 100 # char to pad with
 101 #
 102 #  you can use any char you like here. :) even numbers should work
 103 #
 104