From: Georgios Kontaxis Date: Sat, 15 Aug 2026 17:37:46 +0000 (+0000) Subject: [inputlength] Add feature to count backwards from a maximum desired length X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=refs%2Fheads%2Finputlength_countdown;p=irssi-scripts.irssi.org.git [inputlength] Add feature to count backwards from a maximum desired length --- diff --git a/scripts/il.pl b/scripts/il.pl index 0f5574d..dee0f80 100644 --- a/scripts/il.pl +++ b/scripts/il.pl @@ -23,11 +23,13 @@ # use strict; +use warnings; + use Irssi 20021105; use Irssi::TextUI; use vars qw($VERSION %IRSSI); -$VERSION = '0.0.6'; +$VERSION = '0.1.0'; %IRSSI = ( authors => 'Marcus Rueckert', contact => 'darix@irssi.org', @@ -36,7 +38,7 @@ $VERSION = '0.0.6'; sbitems => 'inputlength', license => 'BSD License or something more liberal', url => 'http://www.irssi.de./', - changed => '2021-01-11' + changed => '2026-08-15' ); my $help = << "END"; @@ -54,18 +56,27 @@ my $help = << "END"; %9Settings%9 /set inputlength_width 0 /set inputlength_padding_char + /set inputlength_max 0 END sub beancounter { my ( $sbItem, $get_size_only ) = @_; - my ( $width, $padChar, $padNum, $length ); + my ( $width, $padChar, $padNum, $maxLength, $txtLength, $length ); # # getting settings # $width = Irssi::settings_get_int ( 'inputlength_width' ); $padChar = Irssi::settings_get_str ( 'inputlength_padding_char' ); + $maxLength = Irssi::settings_get_int ( 'inputlength_max' ); + + $txtLength = Irssi::parse_special("\$\@L"); + + # count remaining instead of encountered characters + if ($maxLength > 0) { + $txtLength = $maxLength - $txtLength; + } # # only one char allowed @@ -83,14 +94,14 @@ sub beancounter { # # getting formatted lengh # - $length = Irssi::parse_special ( "\$[-!$width$padChar]\@L" ); + $length = Irssi::parse_special ( "\$[-!$width$padChar]0", "$txtLength" ); # # did we have a number? # - $length =~ s/$padChar/$padNum/g if ( $padNum ne '' ); + $length =~ s/$padChar/$padNum/g if ( defined $padNum && $padNum ne '' ); - $sbItem->default_handler ( $get_size_only, "{sb $length}", undef, 1 ); + $sbItem->default_handler ( $get_size_only, "{sb $length}", "", 1 ); } Irssi::statusbar_item_register ( 'inputlength', 0, 'beancounter' ); @@ -105,6 +116,7 @@ Irssi::signal_add_last 'gui key pressed' => sub { }; Irssi::settings_add_int ( 'inputlength', 'inputlength_width', 0 ); +Irssi::settings_add_int ( 'inputlength', 'inputlength_max', 0 ); # # setting: #