line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=encoding utf-8 |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Getopt::EX::autocolor - Getopt::EX autocolor module |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Getopt::EX::Loader; |
10
|
|
|
|
|
|
|
my $rcloader = new Getopt::EX::Loader |
11
|
|
|
|
|
|
|
BASECLASS => [ 'App::command', 'Getopt::EX' ]; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$ command -Mautocolor |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.01 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This is a common module for command using L to set system |
22
|
|
|
|
|
|
|
dependent autocolor option. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Each module is expected to set B<--light-terminal> or |
25
|
|
|
|
|
|
|
B<--dark-terminal> option according to the brightness of a terminal |
26
|
|
|
|
|
|
|
program. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
If the environment variable C is defined, its value is |
29
|
|
|
|
|
|
|
used as a brightness without calling submodules. The value of |
30
|
|
|
|
|
|
|
C is expected in range of 0 to 100. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SEE ALSO |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
L |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
L |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
L |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 AUTHOR |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Kazumasa Utashiro |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 LICENSE |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Copyright (C) 2020 Kazumasa Utashiro. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
You can redistribute it and/or modify it under the same terms |
49
|
|
|
|
|
|
|
as Perl itself. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package Getopt::EX::autocolor; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
1
|
|
792
|
use v5.14; |
|
1
|
|
|
|
|
4
|
|
56
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
57
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
58
|
1
|
|
|
1
|
|
644
|
use Data::Dumper; |
|
1
|
|
|
|
|
6894
|
|
|
1
|
|
|
|
|
73
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
1
|
|
7
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
270
|
|
63
|
|
|
|
|
|
|
our @EXPORT = qw(); |
64
|
|
|
|
|
|
|
our %EXPORT_TAGS = (); |
65
|
|
|
|
|
|
|
our @EXPORT_OK = qw(rgb_to_brightness); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
our %opt = ( |
68
|
|
|
|
|
|
|
light => "--light-terminal", |
69
|
|
|
|
|
|
|
dark => "--dark-terminal", |
70
|
|
|
|
|
|
|
threshold => 50, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub rgb_to_brightness { |
74
|
0
|
|
|
0
|
0
|
|
my($r, $g, $b) = @_; |
75
|
0
|
|
|
|
|
|
int(($r * 30 + $g * 59 + $b * 11) / 65535); # 0 .. 100 |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my %TERM_PROGRAM = qw( |
79
|
|
|
|
|
|
|
Apple_Terminal Apple_Terminal |
80
|
|
|
|
|
|
|
iTerm.app iTerm |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub initialize { |
84
|
0
|
|
|
0
|
0
|
|
my $mod = shift; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# default to do nothing. |
87
|
0
|
|
|
|
|
|
$mod->setopt($opt{light} => '$'); |
88
|
0
|
|
|
|
|
|
$mod->setopt($opt{dark} => '$'); |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
0
|
|
|
|
if ((my $brightness = $ENV{BRIGHTNESS} // '') =~ /^\d+$/) { |
|
|
0
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$mod->setopt(default => |
92
|
|
|
|
|
|
|
$brightness > $opt{threshold} |
93
|
|
|
|
|
|
|
? $opt{light} |
94
|
0
|
0
|
|
|
|
|
: $opt{dark}); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
elsif (my $term_program = $ENV{TERM_PROGRAM}) { |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if (defined (my $module = $TERM_PROGRAM{$term_program})) { |
99
|
0
|
|
|
|
|
|
$mod->setopt(default => "-Mautocolor::${module}"); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__DATA__ |