File: color_popup.pl

package info (click to toggle)
weechat-scripts 20140928-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,064 kB
  • ctags: 5,521
  • sloc: python: 31,594; perl: 26,797; ruby: 1,648; tcl: 224; sh: 8; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,431 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use strict; use warnings;
$INC{'Encode/ConfigLocal.pm'}=1;
require Encode;
use utf8;

# to read the following docs, you can use "perldoc color_popup.pl"

=head1 NAME

color_popup - show mirc colors when needed

=head1 SYNOPSIS

the color numbers will be shown when a color control code is
present.

=cut

use constant SCRIPT_NAME => 'color_popup';
weechat::register(SCRIPT_NAME, 'Nei <anti.teamidiot.de>', '0.3', 'GPL3', 'show mirc color codes', '', '') || return;

my %ones = map { $_ => 1 } 0, 8, 14, 15;
my $popup =
	(join '',
	 map {
		 "\03" . ($ones{0+$_} // 0) . ',' . (sprintf "%02d", $_)x2
	 } 0..15
	) . "\03"
	;

weechat::hook_modifier('input_text_display_with_cursor', 'color_popup', '');

## color_popup -- show mirc colors
## () - modifier handler
## $_[2] - buffer pointer
## $_[3] - input string
## returns modified input string
sub color_popup {
	Encode::_utf8_on($_[3]);
	my $cc = qr/(?:\03(?:\d{1,2}(?:,(?:\d{1,2})?)?)?|\02|\x1d|\x0f|\x12|\x15|\x16|\x1f)/;
	my ($p1, $x, $p2) = split /((?:$cc)?\x19b#)/, $_[3], 2;
	for ($p1, $p2) {
		s/($cc)/$1■/g if weechat::config_string_to_boolean(weechat::config_get_plugin('reveal'));
		Encode::_utf8_on($_ = weechat::hook_modifier_exec(irc_color_decode => 1, weechat::hook_modifier_exec(irc_color_encode => 1, $_)));
	}
	$x .= ' ' . weechat::hook_modifier_exec(
		irc_color_decode => 1, $popup
	   ) if $x =~ /^\03/ and weechat::current_buffer() eq $_[2];
	"$p1$x$p2"
}