| 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<Getopt::EX::termcolor> module for iTerm. | ||||||||||
| 12 | |||||||||||
| 13 | =head1 SEE ALSO | ||||||||||
| 14 | |||||||||||
| 15 | L<Getopt::EX::termcolor> | ||||||||||
| 16 | |||||||||||
| 17 | =cut | ||||||||||
| 18 | |||||||||||
| 19 | package Getopt::EX::termcolor::iTerm; | ||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | { | ||||||||||
| 26 | 1 | ▶ | no warnings 'once'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | $Getopt::EX::Colormap::RGB24 = 1; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 1 | our $debug = 0; | |||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub get_colors { | ||||||||
|
Subroutine
get_colors: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 33 | map { | ||||||||||
| 34 | 0 | my @rgb = get_color($_); | |||||||||
| 35 | 0 | ▶ | @rgb ? undef : [ @rgb ]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | } @_; | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub get_color { | ||||||||
|
Subroutine
get_color: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 40 | 0 | my $cat = lc shift; | |||||||||
| 41 | 0 | ▶ | if ($cat eq 'background') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | return background_rgb(); | |||||||||
| 43 | } | ||||||||||
| 44 | 0 | (); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | my %script = ( | |||||||||
| 48 | |||||||||||
| 49 | 'background' => <<END, | ||||||||||
| 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 | ▶ | use Capture::Tiny ':all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub background_rgb { | ||||||||
|
Subroutine
background_rgb: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 62 | 0 | my $script = $script{background}; | |||||||||
| 63 | 0 | ▶ | my($stdout, $stderr, $exit) = capture { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 64 | 0 | system 'osascript', '-e', $script; | |||||||||
| 65 | 0 | }; | |||||||||
| 66 | 0 | ▶ | $exit == 0 or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | my @rgb = $stdout =~ /(\d+)/g; | |||||||||
| 68 | 0 | ▶ | @rgb == 3 ? ( { max => 65535 }, @rgb) : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 1 | 1; | |||||||||
| 72 | |||||||||||
| 73 | __DATA__ | ||||||||||