| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Image::Caa::DriverCurses; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 41 |  | 
| 4 | 1 |  |  | 1 |  | 7 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 5 | 1 |  |  | 1 |  | 471 | use Curses; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | sub new { | 
| 8 |  |  |  |  |  |  | my ($class, $args) = @_; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | my $self = bless {}, $class; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | $self->{window} = $args->{window}; | 
| 13 |  |  |  |  |  |  | $self->{has_color} = 0; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | $self->{color_pair_next} = 1; | 
| 16 |  |  |  |  |  |  | $self->{color_pairs} = {}; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | return $self; | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub init { | 
| 22 |  |  |  |  |  |  | my ($self) = @_; | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | $self->{has_color} = has_colors(); | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | start_color() if $self->{has_color}; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub set_color{ | 
| 30 |  |  |  |  |  |  | my ($self, $fg, $bg) = @_; | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | return unless $self->{has_color}; | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | my $bright = $fg > 7; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | $fg -= 8 if $fg > 7; | 
| 37 |  |  |  |  |  |  | $bg -= 8 if $bg > 7; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | my $key = "$fg:$bg"; | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | if (!defined $self->{color_pairs}->{$key}){ | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | my $pr = $self->{color_pair_next}; | 
| 44 |  |  |  |  |  |  | $self->{color_pair_next}++; | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | init_pair($pr, $fg, $bg); | 
| 47 |  |  |  |  |  |  | $self->{color_pairs}->{$key} = $pr; | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | print "new pair: $key\n"; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | $self->{window}->attron( $bright ? A_BOLD : A_DIM ); | 
| 53 |  |  |  |  |  |  | $self->{window}->attron(COLOR_PAIR($self->{color_pairs}->{$key})); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | sub putchar{ | 
| 57 |  |  |  |  |  |  | my ($self, $x, $y, $outch) = @_; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | $self->{window}->addch($y, $x, $outch); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub fini { | 
| 63 |  |  |  |  |  |  | my ($self) = @_; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | 1; |