X-Git-Url: https://git.madduck.net/code/irssi/scripts-bc-bd.git/blobdiff_plain/82252cc29ce711c0368f2bfc0646b4de04597448..a2216768e3b5ad42e86de97b6a2d931cb79978bd:/chanact.pl?ds=sidebyside diff --git a/chanact.pl b/chanact.pl index 1444248..cecd635 100644 --- a/chanact.pl +++ b/chanact.pl @@ -4,14 +4,14 @@ use Irssi::TextUI; use vars qw($VERSION %IRSSI); -$VERSION = "0.5.10"; +$VERSION = "0.5.11"; %IRSSI = ( - authors => 'BC-bd, Veli', - contact => 'bd@bc-bd.org, veli@piipiip.net', - name => 'chanact', - description => 'Adds new powerful and customizable [Act: ...] item (chanelnames,modes,alias). Lets you give alias characters to windows so that you can select those with meta-', - license => 'GNU GPLv2 or later', - url => 'https://bc-bd.org/svn/repos/irssi/chanact' + authors => 'BC-bd, Veli', + contact => 'bd@bc-bd.org, veli@piipiip.net', + name => 'chanact', + description => 'Adds new powerful and customizable [Act: ...] item (chanelnames,modes,alias). Lets you give alias characters to windows so that you can select those with meta-', + license => 'GNU GPLv2 or later', + url => 'http://bc-bd.org/blog/irssi/' ); # Adds new powerful and customizable [Act: ...] item (chanelnames,modes,alias). @@ -26,17 +26,18 @@ $VERSION = "0.5.10"; # Contributors ######### # -# veli@piipiip.net /window_alias code -# qrczak@knm.org.pl chanact_abbreviate_names -# qerub@home.se Extra chanact_show_mode and chanact_chop_status -# madduck@madduck.net Better channel aliasing (case-sensitive, cross-network) +# veli@piipiip.net /window_alias code +# qrczak@knm.org.pl chanact_abbreviate_names +# qerub@home.se Extra chanact_show_mode and chanact_chop_status +# madduck@madduck.net Better channel aliasing (case-sensitive, cross-network) +# chanact_filter_windowlist # Jan 'jast' Krueger , 2004-06-22 # Ivo Timmermans win->{hilight} patch -# +# ######### # USAGE ### -# +# # copy the script to ~/.irssi/scripts/ # # In irssi: @@ -52,7 +53,7 @@ $VERSION = "0.5.10"; # # To see all chanact options type: # -# / set chanact_ +# /set chanact_ # # After these steps you have your new statusbar item and you can start giving # aliases to your windows. Go to the window you want to give the alias to @@ -77,16 +78,16 @@ $VERSION = "0.5.10"; ######### # # /set chanact_chop_status -# * ON : shorten (Status) to S -# * OFF : don't do it +# * ON : shorten (Status) to S +# * OFF : don't do it # # /set chanact_show_mode -# * ON : show channel modes -# * OFF : don't show channel modes +# * ON : show channel modes +# * OFF : don't show channel modes # # /set chanact_sort_by_activity -# * ON : sorts the list by last activity -# * OFF : sorts the list by window number +# * ON : sorts the list by last activity +# * OFF : sorts the list by window number # # /set chanact_display # * string : Format String for one Channel. The following $'s are expanded: @@ -96,11 +97,11 @@ $VERSION = "0.5.10"; # $H : Start highlightning # $S : Stop highlightning # * example: -# +# # /set chanact_display $H$N:$M.$S$C -# +# # will give you on #irssi.de if you have voice -# +# # [3:+.#irssi.de] # # with '3:+.' highlighted and the channel name printed in regular color @@ -108,57 +109,69 @@ $VERSION = "0.5.10"; # /set chanact_display_alias # as 'chanact_display' but is used if the window has an alias and # 'chanact_show_alias' is set to on. -# +# # /set chanact_show_names # * ON : show the channelnames after the number/alias # * OFF : don't show the names # # /set chanact_abbreviate_names -# * 0 : don't abbreviate -# * : strip channel name prefix character and leave only -# that many characters of the proper name +# * 0 : don't abbreviate +# * : strip channel name prefix character and leave only +# that many characters of the proper name # # /set chanact_show_alias # * ON : show the aliase instead of the refnum # * OFF : shot the refnum # # /set chanact_header -# * : Characters to be displayed at the start of the item. -# Defaults to: "Act: " +# * : Characters to be displayed at the start of the item. +# Defaults to: "Act: " # # /set chanact_separator # * : Charater to use between the channel entries # # /set chanact_autorenumber # * ON : Move the window automatically to first available slot -# starting from "chanact_renumber_start" when assigning -# an alias to window. Also moves the window back to a -# first available slot from refnum 1 when the window -# loses it's alias. +# starting from "chanact_renumber_start" when assigning +# an alias to window. Also moves the window back to a +# first available slot from refnum 1 when the window +# loses it's alias. # * OFF : Don't move the windows automatically # # /set chanact_renumber_start -# * : Move the window to first available slot after this -# num when "chanact_autorenumber" is ON. +# * : Move the window to first available slot after this +# num when "chanact_autorenumber" is ON. # # /set chanact_remove_hash -# * ON : Remove &#+!= from channel names -# * OFF : Don't touch channel names +# * ON : Remove &#+!= from channel names +# * OFF : Don't touch channel names # # /set chanact_remove_prefix -# * : Regular expression used to remove from the -# beginning of the channel name. -# * example : -# To shorten a lot of debian channels: -# -# /set chanact_remove_prefix deb(ian.(devel-)?)? +# * : Regular expression used to remove from the +# beginning of the channel name. +# * example : +# To shorten a lot of debian channels: +# +# /set chanact_remove_prefix deb(ian.(devel-)?)? # # /set chanact_filter -# * 0 : show all channels -# * 1 : hide channels without activity -# * 2 : hide channels with only join/part/etc messages -# * 3 : hide channels with text messages -# * 4 : hide all channels (now why would you want to do that) +# * 0 : show all channels +# * 1 : hide channels without activity +# * 2 : hide channels with only join/part/etc messages +# * 3 : hide channels with text messages +# * 4 : hide all channels (now why would you want to do that) +# +# /set chanact_filter_windowlist +# * : space-separated list of windows for which to use +# chanact_filter_windowlist_level instead of +# chanact_filter. +# The special string @QUERIES matches all queries. +# +# /set chanact_filter_windowlist_level +# like chanact_filter for windows in chanact_filter_windowlist. Defaults to +# chanact_filter<4 ? 4 : 2, making chanact_filter_windowlist a list of +# windows never to show if chanact_filter<4, and a list of windows to show +# when there is reasonable activity if all channels would be hidden. # ######### # HINTS @@ -167,7 +180,7 @@ $VERSION = "0.5.10"; # If you have trouble with wrong colored entries your 'default.theme' might # be too old. Try on a shell: # -# $ mv ~/.irssi/default.theme /tmp/ +# $ mv ~/.irssi/default.theme /tmp/ # # And in irssi: # /reload @@ -186,10 +199,10 @@ my %show = ( my ($actString,$needRemake); sub expand { - my ($string, %format) = @_; - my ($exp, $repl); - $string =~ s/\$$exp/$repl/g while (($exp, $repl) = each(%format)); - return $string; + my ($string, %format) = @_; + my ($exp, $repl); + $string =~ s/\$$exp/$repl/g while (($exp, $repl) = each(%format)); + return $string; } # method will get called every time the statusbar item will be displayed @@ -203,19 +216,20 @@ sub chanact { if ($needRemake) { remake(); } - + $item->default_handler($get_size_only, $actString, undef, 1); } # this is the real creation method sub remake() { my ($afternumber,$finish,$hilight,$mode,$number,$display,@windows); - my $separator = Irssi::settings_get_str('chanact_separator'); + my $separator = Irssi::settings_get_str('chanact_separator'); my $abbrev = Irssi::settings_get_int('chanact_abbreviate_names'); my $remove_prefix = Irssi::settings_get_str('chanact_remove_prefix'); my $remove_hash = Irssi::settings_get_bool('chanact_remove_hash'); + my $windowlist = Irssi::settings_get_str('chanact_filter_windowlist'); - if (Irssi::settings_get_bool('chanact_sort_by_activity')) { + if (Irssi::settings_get_bool('chanact_sort_by_activity')) { @windows = sort { ($b->{last_line} <=> $a->{last_line}) } Irssi::windows; } else { @@ -225,7 +239,7 @@ sub remake() { $actString = ""; foreach my $win (@windows) { - + # since irssi is single threaded this shouldn't happen !ref($win) && next; @@ -233,20 +247,37 @@ sub remake() { !ref($active) && next; my $name = $win->get_active_name; + my $type = $active->{type}; + + # determine whether we have a match with the windowlist + my @windowlist = split ' ', $windowlist; + my $match_windowlist = grep { $_ eq $name } @windowlist; + if ($type eq 'QUERY') { + # if this is a query, also try to match @QUERIES + $match_windowlist ||= grep { $_ eq '@QUERIES' } @windowlist; + } - # skip windows that have only activity below the filter setting - next if (Irssi::settings_get_int('chanact_filter') > $win->{data_level}); + my $filter_level = Irssi::settings_get_int('chanact_filter'); + if ($match_windowlist) { + # window matches windowlist so use + # chanact_filter_windowlist_level to override + # chanact_filter + $filter_level = Irssi::settings_get_int('chanact_filter_windowlist_level'); + } + # skip windows with data of level lower than the applicable + # filter setting + next if ($win->{data_level} < $filter_level); # (status) is an awfull long name, so make it short to 'S' # some people don't like it, so make it configurable if (Irssi::settings_get_bool('chanact_chop_status') - && $name eq "(status)") { + && $name eq "(status)") { $name = "S"; } - + # check if we should show the mode $mode = ""; - if ($active->{type} eq "CHANNEL") { + if ($type eq "CHANNEL") { my $server = $win->{active_server}; !ref($server) && next; @@ -255,7 +286,7 @@ sub remake() { my $nick = $channel->nick_find($server->{nick}); !ref($nick) && next; - + if ($nick->{op}) { $mode = "@"; } elsif ($nick->{voice}) { @@ -286,13 +317,13 @@ sub remake() { $name =~ s/^[&#+!=]//; } - if (Irssi::settings_get_bool('chanact_show_alias') == 1 && + if (Irssi::settings_get_bool('chanact_show_alias') == 1 && $win->{name} =~ /^([a-zA-Z+]):(.+)$/) { $number = "$1"; - $display = Irssi::settings_get_str('chanact_display_alias'); + $display = Irssi::settings_get_str('chanact_display_alias'); } else { $number = $win->{refnum}; - $display = Irssi::settings_get_str('chanact_display'); + $display = Irssi::settings_get_str('chanact_display'); } $actString .= expand($display,"C",$name,"N",$number,"M",$mode,"H",$hilight,"S","}{sb_background}").$separator; @@ -302,7 +333,7 @@ sub remake() { if ($actString ne "") { # Remove the last separator $actString =~ s/$separator$//; - + if (Irssi::settings_get_int('chanact_filter')) { $actString = "{sb ".Irssi::settings_get_str('chanact_header').$actString."}"; } else { @@ -332,29 +363,29 @@ sub chanactHasChanged() sub cmd_window_unalias { my ($data, $server, $witem) = @_; my $rn_start = Irssi::settings_get_int('chanact_renumber_start'); - - unless ($data =~ /^[a-zA-Z]$/ || + + unless ($data =~ /^[a-zA-Z]$/ || Irssi::active_win()->{name} =~ /^[a-zA-Z]$/) { Irssi::print("Usage: /window_unalias "); Irssi::print("or /window_alias in window that has an alias."); return; } - + if ($data eq '') { $data = Irssi::active_win()->{name}; } if (my $oldwin = Irssi::window_find_name($data)) { $oldwin->set_name(undef); Irssi::print("Removed alias with the key '$data'."); - - if (Irssi::settings_get_bool('chanact_autorenumber') == 1 && + + if (Irssi::settings_get_bool('chanact_autorenumber') == 1 && $oldwin->{refnum} >= $rn_start) { my $old_refnum = $oldwin->{refnum}; - + # Find the first available slot and move the window my $newnum = 1; while (Irssi::window_find_refnum($newnum) ne "") { $newnum++; } $oldwin->set_refnum($newnum); - + Irssi::print("and moved it to from $old_refnum to $newnum"); } } @@ -372,23 +403,23 @@ sub cmd_window_alias { } cmd_window_unalias($data, $server, $witem); - + my $window = $witem->window(); my $winnum = $window->{refnum}; - + if (Irssi::settings_get_bool('chanact_autorenumber') == 1 && $window->{refnum} < $rn_start) { my $old_refnum = $window->{refnum}; $winnum = $rn_start; - + # Find the first available slot and move the window while (Irssi::window_find_refnum($winnum) ne "") { $winnum++; } $window->set_refnum($winnum); - + Irssi::print("Moved the window from $old_refnum to $winnum"); } - + my $winname = $witem->{name}; my $winserver = $window->{active_server}->{tag}; my $winhandle = "$winserver/$winname"; @@ -439,6 +470,9 @@ Irssi::settings_add_str('chanact', 'chanact_header', "Act: "); Irssi::settings_add_bool('chanact', 'chanact_chop_status', 1); Irssi::settings_add_bool('chanact', 'chanact_sort_by_activity', 1); Irssi::settings_add_int('chanact', 'chanact_filter', 0); +Irssi::settings_add_str('chanact', 'chanact_filter_windowlist', ""); +Irssi::settings_add_int('chanact', 'chanact_filter_windowlist_level', + Irssi::settings_get_int('chanact_filter') < 4 ? 4 : 2); # register the statusbar item Irssi::statusbar_item_register('chanact', '$0', 'chanact'); @@ -464,27 +498,33 @@ Irssi::signal_add_last('window refnum changed', 'refnum_changed'); ### # # Changelog -# +# +# 0.5.11 +# - added chanact_filter_windowlist, which is a space-separated list of +# windows for which to use chanact_filter_windowlist_level instead of +# chanact_filter. You can use @QUERIES to match all queries +# (madduck@madduck.net). +# # 0.5.10 -# - fixed irssi crash when using Irssi::print from within remake() -# - added option to filter out some data levels, based on a patch by -# Juergen Jung , see -# https://bc-bd.org/trac/irssi/ticket/15 -# + retired chanact_show_all in favour of chanact_filter +# - fixed irssi crash when using Irssi::print from within remake() +# - added option to filter out some data levels, based on a patch by +# Juergen Jung , see +# https://bc-bd.org/trac/irssi/ticket/15 +# + retired chanact_show_all in favour of chanact_filter # # 0.5.9 -# - changes by stefan voelkel -# + sort channels by activity, see -# https://bc-bd.org/trac/irssi/ticket/5, based on a patch by jan -# krueger -# + fixed chrash on /exec -interactive, see -# https://bc-bd.org/trac/irssi/ticket/7 +# - changes by stefan voelkel +# + sort channels by activity, see +# https://bc-bd.org/trac/irssi/ticket/5, based on a patch by jan +# krueger +# + fixed chrash on /exec -interactive, see +# https://bc-bd.org/trac/irssi/ticket/7 # -# - changes by Jan 'jast' Krueger , 2004-06-22 -# + updated documentation in script's comments +# - changes by Jan 'jast' Krueger , 2004-06-22 +# + updated documentation in script's comments # -# - changes by Ivo Timmermans -# + honor actcolor /hilight setting if present +# - changes by Ivo Timmermans +# + honor actcolor /hilight setting if present # # 0.5.8 # - made aliases case-sensitive and include network in channel names by madduck @@ -494,10 +534,10 @@ Irssi::signal_add_last('window refnum changed', 'refnum_changed'); # # 0.5.6 # - fixed a bug (#1) reported by Wouter Coekaert -# +# # 0.5.5 # - some speedups from David Leadbeater -# +# # # 0.5.4 # - added help for chanact_display_alias @@ -511,7 +551,7 @@ Irssi::signal_add_last('window refnum changed', 'refnum_changed'); # - removed unused chanact_show_name settings (thx to Qerub) # - fixed $mode display # - guarded reference operations to (hopefully) fix errors on server disconnect -# +# # 0.5.1 # - small typo fixed # @@ -519,7 +559,7 @@ Irssi::signal_add_last('window refnum changed', 'refnum_changed'); # - changed chanact_show_mode to chanact_display. reversed changes from # Qerub through that, but kept funcionality. # - removed chanact_color_all since it is no longer needed -# +# # 0.4.3 # - changes by Qerub # + added chanact_show_mode to show the mode just before the channel name @@ -570,3 +610,5 @@ Irssi::signal_add_last('window refnum changed', 'refnum_changed'); # ### ################ +# +# vim:noet