]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
[inputlength] Add feature to count backwards from a maximum desired length inputlength_countdown
authorGeorgios Kontaxis <redacted>
Sat, 15 Aug 2026 17:37:46 +0000 (17:37 +0000)
committerGeorgios Kontaxis <redacted>
Sun, 16 Aug 2026 11:32:12 +0000 (11:32 +0000)
scripts/il.pl

index 0f5574d929d305a4d69ede5f021140ac1c6dfef5..dee0f8007c74fc748a23826290c142ec66890857 100644 (file)
 #
 
 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:
 #
git clone https://git.99rst.org/PROJECT