Skip to content

Instantly share code, notes, and snippets.

@sm00th
Created January 31, 2012 08:42
Show Gist options
  • Save sm00th/1709496 to your computer and use it in GitHub Desktop.
Save sm00th/1709496 to your computer and use it in GitHub Desktop.
UTF8 version of il.pl irssi script.
#
# 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 <[email protected]> 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 Encode;
use vars qw($VERSION %IRSSI);
$VERSION = '0.0.5';
%IRSSI = (
authors => 'Marcus Rueckert',
contact => '[email protected]',
name => 'inputlength',
description => 'adds a statusbar item which show length of the inputline',
license => 'BSD License or something more liberal',
url => 'http://www.irssi.de./',
changed => '2003-01-13T13:17:44Z'
);
sub beancounter {
my ( $sbItem, $get_size_only ) = @_;
my ( $width, $length );
# getting settings
#
$width = Irssi::settings_get_int ( 'inputlength_width' );
# getting formatted lengh
#
$length = sprintf( "%" . $width . "d", length( decode_utf8( Irssi::parse_special( "\$L" ) ) ) );
# did we have a number?
#
$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
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment