diff options
| author | ailin-nemui | 2015-11-16 19:32:11 -0300 | 
|---|---|---|
| committer | dequis | 2015-11-16 19:34:05 -0300 | 
| commit | 2bc8e3368c0b842f1fe6fad069915a4bb90b1fa2 (patch) | |
| tree | cafd9a0ee1dace65772f70f6147598227c38a35b /scripts/sbclearmatch.pl | |
| parent | b8965d1651f89ebcd395de3309c1255542ad4c78 (diff) | |
| download | scripts.irssi.org-2bc8e3368c0b842f1fe6fad069915a4bb90b1fa2.tar.bz2 | |
Add all of nei's scripts from nei's website
Diffstat (limited to 'scripts/sbclearmatch.pl')
| -rw-r--r-- | scripts/sbclearmatch.pl | 93 | 
1 files changed, 93 insertions, 0 deletions
| diff --git a/scripts/sbclearmatch.pl b/scripts/sbclearmatch.pl new file mode 100644 index 0000000..c2fb87f --- /dev/null +++ b/scripts/sbclearmatch.pl @@ -0,0 +1,93 @@ +use strict; +use warnings; +use Irssi; +use Irssi::TextUI; + +our $VERSION = '0.2'; # 6c39400282189a0 +our %IRSSI = ( +    authors     => 'Nei', +    contact     => 'Nei @ anti@conference.jabber.teamidiot.de', +    url         => "http://anti.teamidiot.de/", +    name        => 'sbclearmatch', +    description => 'clear matching lines in scrollback', +    license     => 'GPLv2 or later', +); + +sub cmd_help { +    my ($args) = @_; +    if ($args =~ /^scrollback *$/i) { +	print CLIENTCRAP <<HELP + +SCROLLBACK CLEARMATCH [-level <level>] [-regexp] [-case] [-word] [-all] [<pattern>] + +    CLEARMATCH: Clears the screen and the buffer of matching text. + +    -regexp:    The given text pattern is a regular expression. +    -case:      Performs a case-sensitive matching. +    -word:      The text must match full words. +HELP + +    } +} + + +sub cmd_sb_clearmatch { +    my ($args, $server, $witem) = @_; +    my ($options, $pattern) = Irssi::command_parse_options('scrollback clearmatch', $args); + +    my $level; +    if (defined $options->{level}) { +	$level = $options->{level}; +	$level =~ y/,/ /; +	$level = Irssi::combine_level(0, $level); +    } +    else { +	return unless length $pattern; +	$level = MSGLEVEL_ALL; +    } + +    my $regex; +    if (length $pattern) { +	my $flags = defined $options->{case} ? '' : '(?i)'; +	my $b = defined $options->{word} ? '\b' : ''; +	if (defined $options->{regexp}) { +	    local $@; +	    eval { $regex = qr/$flags$b$pattern$b/; 1 } +		or do { +		    print CLIENTERROR "Pattern did not compile: " . do { $@ =~ /(.*) at / && $1 }; +		    return; +		}; +	} +	else { +	    $regex = qr/$flags$b\Q$pattern\E$b/; +	} +    } + +    my $current_win = ref $witem ? $witem->window : Irssi::active_win; + +    for my $win (defined $options->{all} ? Irssi::windows : $current_win) { +	my $view = $win->view; +	my $line = $view->get_lines; +	my $need_redraw; +	my $bottom = $view->{bottom}; + +	while ($line) { +	    my $line_level = $line->{info}{level}; +	    my $next = $line->next; +	    if ($line_level & $level && $line->get_text(0) =~ $regex) { +		$view->remove_line($line); +		$need_redraw = 1; +	    } +	    $line = $next; +	} + +	if ($need_redraw) { +	    $win->command('^scrollback end') if $bottom && !$win->view->{bottom}; +	    $view->redraw; +	} +    } +} + +Irssi::command_bind        'scrollback clearmatch' => 'cmd_sb_clearmatch'; +Irssi::command_set_options 'scrollback clearmatch' => '-level regexp case word all'; +Irssi::command_bind_last 'help' => 'cmd_help'; | 
