| 1 | package Term::ExtendedColor::TTY; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | BEGIN { | ||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use vars qw($VERSION @ISA @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | $VERSION = '0.030'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 12 | set_tty_color | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | my %color_indexes = ( | |||||||||||||||||||||||||||
| 19 | 0 => 'P0', #black | ||||||||||||||||||||||||||||
| 20 | 1 => 'P8', # dark grey | ||||||||||||||||||||||||||||
| 21 | 2 => 'P1', # dark red | ||||||||||||||||||||||||||||
| 22 | 3 => 'P9', # red | ||||||||||||||||||||||||||||
| 23 | 4 => 'P2', # dark green | ||||||||||||||||||||||||||||
| 24 | 5 => 'PA', # green | ||||||||||||||||||||||||||||
| 25 | 6 => 'P3', # brown | ||||||||||||||||||||||||||||
| 26 | 7 => 'PB', # yellow | ||||||||||||||||||||||||||||
| 27 | 8 => 'P4', # darkblue | ||||||||||||||||||||||||||||
| 28 | 9 => 'PC', # blue | ||||||||||||||||||||||||||||
| 29 | 10 => 'P5', # dark magenta | ||||||||||||||||||||||||||||
| 30 | 11 => 'PD', # magenta | ||||||||||||||||||||||||||||
| 31 | 12 => 'P6', # dark cyan | ||||||||||||||||||||||||||||
| 32 | 13 => 'PE', # cyan | ||||||||||||||||||||||||||||
| 33 | 14 => 'P7', # dark white | ||||||||||||||||||||||||||||
| 34 | 15 => 'PF', # white | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub set_tty_color { | ||||||||||||||||||||||||||||
| 39 | 1 | ▶ | my $map = shift; | ||||||||||||||||||||||||||
|
Subroutine
set_tty_color: called CC=6 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | ref($map) eq 'HASH' or croak("set_tty_color() expects an hashref"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | my %results; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | for my $index(sort{ $a <=> $b } keys(%{$map})) { | |||||||||||||||||||||||||||
| 46 | 1 | ▶ | if( ($index < 0) or ($index > 15) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index < 0 or $index > 15
MC/DC0%0/2
$index < 0 or $index > 15
$index < 0
$index > 15
Truth table33%1/3
A or B
A= $index < 0B= $index > 15
| |||||||||||||||||||||||||||||
| 47 | 0 | croak("'$index': color index must be between 0 and 15, inclusive\n"); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 1 | ▶ | if($map->{$index} !~ m/^(?:[A-Za-z0-9]{6}$)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | croak( | |||||||||||||||||||||||||||
| 51 | "'$map->{$index}' is not a valid hexadecimal color representation\n" | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | $results{$index} = sprintf("\e]%s", | ||||||||||||||||||||||||||||
| 56 | $color_indexes{$index} | ||||||||||||||||||||||||||||
| 57 | 1 | . $map->{$index}, #P0ffffff | |||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | return \%results; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | 1; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||