Skip to content

Instantly share code, notes, and snippets.

@dato
Forked from anonymous/gist:95312
Created April 14, 2009 18:49
Show Gist options
  • Save dato/95345 to your computer and use it in GitHub Desktop.
Save dato/95345 to your computer and use it in GitHub Desktop.
use Irssi;
use Irssi::TextUI;
use strict;
our %IRSSI = (
authors => 'Decklin Foster',
contact => '[email protected]',
name => 'tweetlen',
description => 'Update length of tweet in statusbar',
license => 'ISC',
);
Irssi::statusbar_item_register('tweetlen', undef, 'tweetlen_sb');
Irssi::signal_add_last('gui key pressed', 'key_pressed');
sub key_pressed {
Irssi::statusbar_items_redraw('tweetlen');
}
sub tweetlen_sb {
my ($item, $size_only) = @_;
my @items = Irssi::active_win->items;
if (! @items || $items[0]->{name} ne "#twitter") {
$item->default_handler($size_only, "", undef, 1);
return;
}
my $chars = 140 - length(Irssi::parse_special("\$L"));
if ($chars < 10) {
$chars = "%R$chars%n";
} elsif ($chars < 20) {
$chars = "%M$chars%n";
}
$item->default_handler($size_only, "{sb $chars}", undef, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment