-
Notifications
You must be signed in to change notification settings - Fork 234
/
il.pl
133 lines (115 loc) · 3.13 KB
/
il.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
# for all who dont like perl:
# inputlength = "{sb length: $@L}";
#
# with leading spaces: (3 spaces in example)
# inputlength = "{sb $[-!3]@L}";
#
# with leading char "-"
#
# inputlength = "{sb $[-!3-]@L}";
#
# you cant use numbers here. if you want to use the numbers use the
# perl script
#
#
# thanks to: Wouter Coekaerts <wouter@coekaerts.be> aka coekie
#
# add one of these 2 lines to your config in statusbar items section
#
# the perl scripts reacts on every keypress and updates the counter.
# if you dont need/want this the settings are maybe enough for you.
# with the settings the item is update with a small delay.
#
use strict;
use Irssi 20021105;
use Irssi::TextUI;
use vars qw($VERSION %IRSSI);
$VERSION = '0.0.6';
%IRSSI = (
authors => 'Marcus Rueckert',
contact => 'darix@irssi.org',
name => 'inputlength',
description => 'adds a statusbar item which show length of the inputline',
sbitems => 'inputlength',
license => 'BSD License or something more liberal',
url => 'http://www.irssi.de./',
changed => '2021-01-11'
);
my $help = << "END";
%9Name%9
$IRSSI{name}
%9Version%9
$VERSION
%9Description%9
$IRSSI{description}
To activate the inputlength indicator do:
/STATUSBAR window add inputlength
Statusbar syntax was changed in Irssi 1.2.
/STATUSBAR ADDITEM inputlength window
%9Settings%9
/set inputlength_width 0
/set inputlength_padding_char
END
sub beancounter {
my ( $sbItem, $get_size_only ) = @_;
my ( $width, $padChar, $padNum, $length );
#
# getting settings
#
$width = Irssi::settings_get_int ( 'inputlength_width' );
$padChar = Irssi::settings_get_str ( 'inputlength_padding_char' );
#
# only one char allowed
#
$padChar =~ s/^(.).*?$/$1/;
#
# do we have to deal wit numbers for padding?
#
if ( $padChar =~ m/\d/ ) {
$padNum = $padChar;
$padChar = '-';
};
#
# getting formatted lengh
#
$length = Irssi::parse_special ( "\$[-!$width$padChar]\@L" );
#
# did we have a number?
#
$length =~ s/$padChar/$padNum/g if ( $padNum ne '' );
$sbItem->default_handler ( $get_size_only, "{sb $length}", undef, 1 );
}
Irssi::statusbar_item_register ( 'inputlength', 0, 'beancounter' );
#
# ToDo:
# - statusbar item register doesnt support function references.
# so we have to stuck to the string and wait for cras.
#
Irssi::signal_add_last 'gui key pressed' => sub {
Irssi::statusbar_items_redraw ( 'inputlength' );
};
Irssi::settings_add_int ( 'inputlength', 'inputlength_width', 0 );
#
# setting:
#
# 0 means it resizes automatically
# greater means it has at least a size of n chars.
# it will grow if the space is to space is too small
#
Irssi::settings_add_str ( 'inputlength', 'inputlength_padding_char', " " );
#
# char to pad with
#
# you can use any char you like here. :) even numbers should work
#
sub cmd_help {
my ($args, $server, $witem)=@_;
$args=~ s/\s+//g;
if ($IRSSI{name} eq $args) {
Irssi::print($help, MSGLEVEL_CLIENTCRAP);
Irssi::signal_stop();
}
}
Irssi::command_bind('help', \&cmd_help);
Irssi::command_bind($IRSSI{name}, sub { cmd_help($IRSSI{name}); } );