FQStat/Colors.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 118 CC 7 SCAR 18.3
CC
7
Cov
0%
get_color
12.0
load_color_scheme
12.0
save_color_scheme
6.0
CRAP 6.2
1  
2 package App::FQStat::Colors;
3 # App::FQStat is (c) 2007-2009 Steffen Mueller
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7  
8 use strict;
9 use warnings;
10 use Term::ANSIScreen ();
11 use App::FQStat::Debug;
12 use App::FQStat::Config qw/get_config/;
13  
14 use base 'Exporter';
15 our %EXPORT_TAGS = (
16 'all' => [qw(
17 get_color
18 load_color_scheme
19 save_color_scheme
20 delete_color_scheme
21 )],
22 );
23 our @EXPORT_OK = @{$EXPORT_TAGS{'all'}};
24  
25 our $DefaultColors = {
26 initializing => 'black on green',
27 reverse_indicator => 'blue on white',
28  
29 header_highlight => 'bold white on red',
30 header_warning => 'bold red on black',
31 header_normal => 'bold white on black',
32  
33 status_running => 'black on green',
34 status_error => 'black on red',
35 status_hold => 'black on yellow',
36 status_queued => 'blue on white',
37 status_fallback => 'black on yellow',
38  
39 scrollbar_fg => 'black on white',
40 scrollbar_bg => 'white on black',
41  
42 user_highlight => 'bold white on blue',
43
44 menu_normal => 'bold white on blue',
45 menu_selected => 'bold white on red',
46  
47 user_input => "bold red on black",
48 user_instructions => "bold red on white",
49  
50 selected_job => "blue on white",
51 selected_cursor => "black on red",
52  
53 summary => "bold white on blue",
54  
55 warning => "red",
56 };
57 our $DefaultColorSchemes = {
58 default => {%$DefaultColors},
59 contrast => {
60 header_highlight => 'bold white on red',
61 header_normal => 'bold white on black',
62 header_warning => 'bold red on black',
63 initializing => 'black on green',
64 menu_normal => 'black on cyan',
65 menu_selected => 'bold white on red',
66 reverse_indicator => 'blue on white',
67 scrollbar_bg => 'red on black',
68 scrollbar_fg => 'black on red',
69 selected_cursor => 'black on red',
70 selected_job => 'black on cyan',
71 status_error => 'black on red',
72 status_fallback => 'black on yellow',
73 status_hold => 'black on yellow',
74 status_queued => 'bold white on blue',
75 status_running => 'black on green',
76 summary => 'bold red on blue',
77 user_highlight => 'bold red on blue',
78 user_input => 'bold red on black',
79 user_instructions => 'bold white on red',
80 warning => 'red',
81 },
82 };
83  
84 sub get_color {
85 warnenter if ::DEBUG > 1;
86 my $color = shift;
87 my $colors = get_config('colors') || {};
88 if (not defined $colors->{$color}) {
89 die "Could not determine color scheme for use '$color'.";
90 }
91 return Term::ANSIScreen::color( $colors->{$color} );
92 }
93  
94 sub load_color_scheme {
95 warnenter if ::DEBUG;
96 my $schemeName = shift;
97 my $schemes = get_config('color_schemes') || {};
98 if (!exists $schemes->{$schemeName}) {
99 die "Trying to load invalid color scheme!";
100 }
101 my $colors = get_config('colors') || {};
102 %$colors = %{$schemes->{$schemeName}};
103 App::FQStat::Config::save_configuration();
104 return 1;
105 }
106  
107 sub save_color_scheme {
108 warnenter if ::DEBUG;
109 my $schemeName = shift;
110 my $schemes = get_config('color_schemes') || {};
111 my $colors = get_config('colors') || {};
112 $schemes->{$schemeName} = {%$colors};
113 App::FQStat::Config::save_configuration();
114 return 1;
115 }
116  
117 sub delete_color_scheme {
118 warnenter if ::DEBUG;
119 my $schemeName = shift;
120 my $schemes = get_config('color_schemes') || {};
121 delete $schemes->{$schemeName};
122 App::FQStat::Config::save_configuration();
123 return 1;
124 }
125  
126  
127 # transform the color scheme list into a list of menu entries
128 sub get_color_scheme_menu_entries {
129 my $schemes = get_config('color_schemes');
130 my @entries;
131 foreach my $name (sort keys %$schemes) {
132 my $display_name = $name;
133 $display_name =~ s/^(.{0,8}).*$/$1/;
134 push @entries, { name => $display_name, action => sub { load_color_scheme($name) }, },
135 }
136 push @entries, { name => 'Delete', action => \&App::FQStat::Actions::delete_color_scheme, };
137 push @entries, { name => 'Save', action => \&App::FQStat::Actions::save_color_scheme, };
138 return \@entries;
139 }
140  
141 sub get_n_color_scheme_entries {
142 2 + keys( %{ get_config('color_schemes')||{} } );
143 }
144  
145 1;
146  
147