File Coverage

blib/lib/Getopt/EX/termcolor/iTerm.pm
Criterion Covered Total %
statement 14 27 51.8
branch 0 8 0.0
condition n/a
subroutine 5 9 55.5
pod 0 3 0.0
total 19 47 40.4


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Getopt::EX::termcolor::iTerm
4              
5             =head1 SYNOPSIS
6              
7             command -Mtermcolor::iTerm
8              
9             =head1 DESCRIPTION
10              
11             This is a L module for iTerm.
12              
13             =head1 SEE ALSO
14              
15             L
16              
17             =cut
18              
19             package Getopt::EX::termcolor::iTerm;
20              
21 1     1   1416 use v5.14;
  1         5  
22 1     1   7 use warnings;
  1         2  
  1         65  
23 1     1   6 use Data::Dumper;
  1         2  
  1         65  
24              
25             {
26 1     1   18 no warnings 'once';
  1         2  
  1         248  
27             $Getopt::EX::Colormap::RGB24 = 1;
28             }
29              
30             our $debug = 0;
31              
32             sub get_colors {
33             map {
34 0     0 0   my @rgb = get_color($_);
  0            
35 0 0         @rgb ? undef : [ @rgb ];
36             } @_;
37             }
38              
39             sub get_color {
40 0     0 0   my $cat = lc shift;
41 0 0         if ($cat eq 'background') {
42 0           return background_rgb();
43             }
44 0           ();
45             }
46              
47             my %script = (
48              
49             'background' => <
50             tell application "iTerm"
51             tell current session of current window
52             background color
53             end tell
54             end tell
55             END
56              
57             );
58              
59 1     1   845 use Capture::Tiny ':all';
  1         32283  
  1         387  
60              
61             sub background_rgb {
62 0     0 0   my $script = $script{background};
63             my($stdout, $stderr, $exit) = capture {
64 0     0     system 'osascript', '-e', $script;
65 0           };
66 0 0         $exit == 0 or return;
67 0           my @rgb = $stdout =~ /(\d+)/g;
68 0 0         @rgb == 3 ? ( { max => 65535 }, @rgb) : ();
69             }
70              
71             1;
72              
73             __DATA__