]> git.madduck.net Git - code/irssi/scripts-bc-bd.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

allow per-window level specifications
authormartin f. krafft <madduck@madduck.net>
Wed, 27 May 2009 10:01:45 +0000 (12:01 +0200)
committermartin f. krafft <madduck@madduck.net>
Wed, 27 May 2009 10:01:45 +0000 (12:01 +0200)
Signed-off-by: martin f. krafft <madduck@madduck.net>
chanact.pl

index 44b071af02d874d7e0732a7b90a90b3f05b1ba9a..e98348e8b6c68b7f6edba26fd63139e0f0943086 100644 (file)
@@ -165,13 +165,17 @@ $VERSION = "0.5.11";
 #              * <string> : space-separated list of windows for which to use
 #                              chanact_filter_windowlist_level instead of
 #                              chanact_filter.
+#                              Alternatively, an entry can be postfixed with
+#                              a colon (':') and the level to use for that
+#                              window.
 #                              The special string @QUERIES matches all queries.
 #
 # /set chanact_filter_windowlist_level <int>
-#   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.
+#   like chanact_filter for windows in chanact_filter_windowlist, which do not
+#   have a specific value. 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
@@ -220,6 +224,18 @@ sub chanact {
        $item->default_handler($get_size_only, $actString, undef, 1);
 }
 
+sub get_filterlevel {
+       my $windows = shift;
+       my $kwregexp = '(?:' . join('|', map quotemeta, @_) . ')';
+       my $defaultlevel = Irssi::settings_get_int('chanact_filter_windowlist_level');
+       foreach my $win (@$windows) {
+               return ($1 ? $1 : $defaultlevel) if $win =~ /^$kwregexp(?:\:(\d+))?$/;
+       }
+       return undef;
+}
+
+use Data::Dumper;
+
 # this is the real creation method
 sub remake() {
        my ($afternumber,$finish,$hilight,$mode,$number,$display,@windows);
@@ -227,7 +243,7 @@ sub remake() {
        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');
+       my @windowlist = split ' ', Irssi::settings_get_str('chanact_filter_windowlist');
 
        if (Irssi::settings_get_bool('chanact_sort_by_activity')) {
                @windows = sort { ($b->{last_line} <=> $a->{last_line}) }
@@ -249,24 +265,26 @@ sub remake() {
                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;
-               }
-
-               # choose filter_level according to whether the window is in
-               # the windowlist
-               my $filter_level = $match_windowlist
-                       ? Irssi::settings_get_int('chanact_filter_windowlist_level')
-                       : Irssi::settings_get_int('chanact_filter');
-
-               # skip windows with data of level lower than the applicable
-               # filter setting
+               ## determine the filter_level to use to determine whether the
+               ## activity on the current window is worth the bother
+               #
+               my @matchlist; push @matchlist, $name;
+               # if this is a query, also try to match @QUERIES
+               push @matchlist, '@QUERIES' if ($type eq 'QUERY');
+               # get_filterlevel matches all items in @matchlist against the
+               # @windowlist and returns the applicable filterlevel
+               my $filter_level = get_filterlevel(\@windowlist, @matchlist);
+               # if we don't have a match (undef), then use the
+               # chanact_filter value
+               $filter_level = Irssi::settings_get_int('chanact_filter') unless $filter_level;
+
+               # now, skip windows with data of level lower than the
+               # filter level
                next if ($win->{data_level} < $filter_level);
 
+               # alright, the activity is important, let's show the window
+               my $level = $win->{data_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')
@@ -501,7 +519,8 @@ Irssi::signal_add_last('window refnum changed', 'refnum_changed');
 # 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
+#        chanact_filter. Each window can also have a specific level
+#        specified. You can use @QUERIES to match all queries
 #        (madduck@madduck.net).
 #
 # 0.5.10