weechat

- me personal weechat setup 🔵🟢
git clone git://git.acid.vegas/weechat.git
Log | Files | Refs | Archive | README

color_popup.pl (1402B)

      1 use strict; use warnings;
      2 $INC{'Encode/ConfigLocal.pm'}=1;
      3 require Encode;
      4 use utf8;
      5 
      6 use constant SCRIPT_NAME => 'color_popup';
      7 weechat::register(SCRIPT_NAME, 'Nei <anti.teamidiot.de>', '0.4', 'GPL3', 'show mirc color codes', '', '') || return;
      8 
      9 my %ones = map { $_ => 1 } 0, 8, 14, 15, 42, 43, 45, 53 .. 58, 65 .. 86, 95 .. 98;
     10 weechat::hook_modifier('input_text_display_with_cursor', 'color_popup', '');
     11 
     12 ## color_popup -- show mirc colors
     13 ## () - modifier handler
     14 ## $_[2] - buffer pointer
     15 ## $_[3] - input string
     16 ## returns modified input string
     17 sub color_popup {
     18 	Encode::_utf8_on($_[3]);
     19 	my $cc = qr/(?:\03(?:\d{1,2}(?:,(?:\d{1,2})?)?)?|\02|\x1d|\x0f|\x12|\x15|\x16|\x1f)/;
     20 	my ($p1, $x, $p2) = split /((?:$cc)?\x19b#)/, $_[3], 2;
     21 	for ($p1, $p2) {
     22 		s/($cc)/$1â– /g if weechat::config_string_to_boolean(weechat::config_get_plugin('reveal'));
     23 		Encode::_utf8_on($_ = weechat::hook_modifier_exec(irc_color_decode => 1, weechat::hook_modifier_exec(irc_color_encode => 1, $_)));
     24 	}
     25 	$x .= ' ' . weechat::hook_modifier_exec(
     26 	    irc_color_decode => 1, sub {
     27 		$x =~ /\cC(\d{1,2})(,(\d{1,2})?)?/;
     28 		my ($fg, $bg) = ($1//-1, $3//-1);
     29 		my $sc = $bg >= 0 ? $bg : $2?-1:$fg;
     30 		(join '', map {
     31 		     "\03" . ($ones{0+$_} // 0) . ",$_$_"
     32 		}
     33 		    $sc >= 0 ? grep /^0?$sc/, '00' .. '99' : ('00' .. '15'))
     34 		. "\03"
     35 	    }->()
     36 	   ) if $x =~ /^\03/ and weechat::current_buffer() eq $_[2];
     37 	"$p1$x$p2"
     38 }