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
25use strict;
26use Irssi 20021105;
27use Irssi::TextUI;
28
29use 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    sbitems     => 'inputlength',
37    license     => 'BSD License or something more liberal',
38    url         => 'http://www.irssi.de./',
39    changed     => '2003-01-13T13:17:44Z'
40);
41
42sub beancounter {
43    my ( $sbItem, $get_size_only ) = @_;
44
45    my ( $width, $padChar, $padNum, $length );
46
47	#
48	# getting settings
49	#
50    $width = Irssi::settings_get_int ( 'inputlength_width' );
51	$padChar = Irssi::settings_get_str ( 'inputlength_padding_char' );
52
53	#
54	# only one char allowed
55	#
56    $padChar =~ s/^(.).*?$/$1/;
57
58	#
59	# do we have to deal wit numbers for padding?
60    #
61    if ( $padChar =~ m/\d/ ) {
62		$padNum = $padChar;
63		$padChar = '-';
64	};
65
66	#
67	# getting formatted lengh
68	#
69	$length = Irssi::parse_special ( "\$[-!$width$padChar]\@L" );
70
71	#
72	# did we have a number?
73	#
74    $length =~ s/$padChar/$padNum/g if ( $padNum ne '' );
75
76    $sbItem->default_handler ( $get_size_only, "{sb $length}", undef, 1 );
77}
78
79Irssi::statusbar_item_register ( 'inputlength', 0, 'beancounter' );
80#
81# ToDo:
82#  - statusbar item register doesnt support function references.
83#    so we have to stuck to the string and wait for cras.
84#
85
86Irssi::signal_add_last 'gui key pressed' => sub {
87    Irssi::statusbar_items_redraw ( 'inputlength' );
88};
89
90Irssi::settings_add_int ( 'inputlength', 'inputlength_width', 0 );
91#
92# setting:
93#
94# 0 means it resizes automatically
95# greater means it has at least a size of n chars.
96# it will grow if the space is to space is too small
97#
98
99Irssi::settings_add_str ( 'inputlength', 'inputlength_padding_char', " " );
100#
101# char to pad with
102#
103#  you can use any char you like here. :) even numbers should work
104#
105
106