| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||||||||||||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # (C) Paul Evans, 2014 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Convert::Color::mIRC; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use base qw( Convert::Color::RGB8 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | __PACKAGE__->register_color_space( 'mirc' ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | C<Convert::Color::XTerm> - indexed colors used by mIRC | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Directly: | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | use Convert::Color::mIRC; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $red = Convert::Color::mIRC->new( 3 ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | Via L<Convert::Color>: | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | use Convert::Color; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | my $cyan = Convert::Color->new( 'mirc:11' ) | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | This subclass of L<Convert::Color::RGB8> provides lookup of the colours that | ||||||||||||||||||||||||||||
| 39 | F<mIRC> uses by default. Note that of course the module is not intelligent | ||||||||||||||||||||||||||||
| 40 | enough to be able to parse mIRC config, or know what palettes users are | ||||||||||||||||||||||||||||
| 41 | actually using, and thus it provides only an approximation of the likely | ||||||||||||||||||||||||||||
| 42 | behaviour of clients. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | The palette implemented consists of 16 colours, described as: | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 1 2 3 4 5 6 7 | ||||||||||||||||||||||||||||
| 47 | white black blue green red brown purple orange | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 8 9 10 11 12 13 14 15 | ||||||||||||||||||||||||||||
| 50 | yellow light-green teal cyan light-blue pink grey silver | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | my @color; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub _init_colors | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_init_colors: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 58 | 1 | my $idx = 0; | |||||||||||||||||||||||||||
| 59 | 1 | ▶ | while( <DATA> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 16 | chomp; | |||||||||||||||||||||||||||
| 61 | 16 | my $c = __PACKAGE__->SUPER::new( $_ ); | |||||||||||||||||||||||||||
| 62 | 16 | $c->[3] = $idx++; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 16 | push @color, $c; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __PACKAGE__->register_palette( | ||||||||||||||||||||||||||||
| 69 | 1 | ▶ | enumerate_once => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | @color or _init_colors; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | @color | ||||||||||||||||||||||||||||
| 72 | 1 | }, | |||||||||||||||||||||||||||
| 73 | 2 | ); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head2 $color = Convert::Color::mIRC->new( $index ) | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Returns a new object to represent the color at that index. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # TODO: Surely we can move this logic into Convert::Color base somehow... | ||||||||||||||||||||||||||||
| 86 | sub new | ||||||||||||||||||||||||||||
| 87 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 89 | 2 | ▶ | croak "usage: Convert::Color::mIRC->new( INDEX )" unless @_ == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 2 | my ( $index ) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | ▶ | @color or _init_colors; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 2 | ▶ | $index >= 0 and $index < @color or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index >= 0 and $index < @color
MC/DC0%0/2
$index >= 0 and $index < @color
$index >= 0
$index < @color
Truth table33%1/3
A and B
A= $index >= 0B= $index < @color
| |||||||||||||||||||||||||||||
| 95 | croak "No such mIRC color at index '$index'"; | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | return $color[$index]; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 METHODS | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head2 $index = $color->index | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | The index of the mIRC color. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub index | ||||||||||||||||||||||||||||
| 111 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 113 | 3 | return $self->[3]; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 TODO | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =over 4 | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item * | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Find out if the embedded colour palette really is the default mIRC one, or | ||||||||||||||||||||||||||||
| 123 | update it if not. Patches welcome ;) | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =back | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =cut | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 2 | 0x55AA; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # This palette taken from | ||||||||||||||||||||||||||||
| 136 | # http://www.mish-script.de/help/mircini/colors.htm | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | __DATA__ | ||||||||||||||||||||||||||||