summaryrefslogtreecommitdiffstats
path: root/scripts/figlet.pl
blob: 3f8ca6d6ba328f5de3cf165979680d3601d33f49 (plain)
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
51
52
53
54
55
56
57
58
use IPC::Open3;
use strict;
use vars qw($VERSION %IRSSI);

use Irssi qw(command_bind active_win);
$VERSION = "1.14";
%IRSSI = (
    authors	=> 'Juerd',
    contact	=> 'juerd@juerd.nl',
    name	=> 'Figlet',
    description	=> 'Safe figlet implementation (with color support!)',
    license	=> 'Public Domain',
    url		=> 'http://juerd.nl/irssi/',
    changed	=> 'Sun 10 Mar 14:46 CET 2002',
    changes	=> 'No more zombie processes',
);

command_bind(
    figlet => sub {
	my ($msg) = @_;
	my @figlet;
	my $prefix = '';
	while ($msg =~ s/
	    ^(
		[^\cC\cB\cO\c_]+
	    |
		(?:
		    \cC\d*(?:,\d*)?
		|
		    [\cB\cO\c_]
		)+
	    )
	//x) {
	    my $part = $1;
	    if ($part =~ /[\cC\cB\cO\c_]/) {
		if (@figlet) {
		    $_ .= $part for @figlet;
		} else {
		    $prefix = $part;
		}
	    } else {
		my $i = 0;
		my $pid = open3(undef, *FIG, *FIG,  qw(figlet -k), $part);
		while (<FIG>) {
		    chomp;
		    $figlet[$i++] .= $_;
		}
		close FIG;
		waitpid $pid, 0;
	    }
	}
	for (@figlet) {
	    (my $copy = $_) =~ s/\cC\d*(?:,\d*)?|[\cB\cO\c_]//g;
	    next unless $copy =~ /\S/;
	    active_win->command("say $prefix$_");
	}
    }
);