line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Curses::UI::Number; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
42356
|
use base qw(Curses::UI::Label); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
3535
|
|
5
|
|
|
|
|
|
|
use strict; |
6
|
|
|
|
|
|
|
use warnings; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
|
|
|
|
|
|
use Curses::UI::Common qw(keys_to_lowercase); |
10
|
|
|
|
|
|
|
use Curses::UI::Label; |
11
|
|
|
|
|
|
|
use Encode qw(decode_utf8); |
12
|
|
|
|
|
|
|
use Readonly; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constants. |
15
|
|
|
|
|
|
|
Readonly::Scalar our $BLANK_PIXEL => q{ }; |
16
|
|
|
|
|
|
|
Readonly::Scalar our $EMPTY_STR => q{}; |
17
|
|
|
|
|
|
|
Readonly::Scalar our $PIXELS => 14; |
18
|
|
|
|
|
|
|
Readonly::Scalar our $PIXELS_ON_LINE => 3; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Version. |
21
|
|
|
|
|
|
|
our $VERSION = 0.05; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Constructor. |
24
|
|
|
|
|
|
|
sub new { |
25
|
|
|
|
|
|
|
my ($class, %userargs) = @_; |
26
|
|
|
|
|
|
|
keys_to_lowercase(\%userargs); |
27
|
|
|
|
|
|
|
my %args = ( |
28
|
|
|
|
|
|
|
'-num' => undef, |
29
|
|
|
|
|
|
|
'-char' => decode_utf8('█'), |
30
|
|
|
|
|
|
|
%userargs, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Text. |
34
|
|
|
|
|
|
|
$args{'-text'} = _text($args{'-char'}, $args{'-num'}); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Create the widget. |
37
|
|
|
|
|
|
|
my $self = $class->SUPER::new(%args); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Layout. |
40
|
|
|
|
|
|
|
$self->layout; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Return object. |
43
|
|
|
|
|
|
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Get or set number. |
47
|
|
|
|
|
|
|
sub num { |
48
|
|
|
|
|
|
|
my ($self, $number) = @_; |
49
|
|
|
|
|
|
|
if (defined $number) { |
50
|
|
|
|
|
|
|
$self->{'-num'} = $number; |
51
|
|
|
|
|
|
|
$self->{'-text'} = _text($self->{'-char'}, $number); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
return $self->{'-num'}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Return structure of pixels. |
57
|
|
|
|
|
|
|
sub _num { |
58
|
|
|
|
|
|
|
my $number = shift; |
59
|
|
|
|
|
|
|
return [ |
60
|
|
|
|
|
|
|
[1,1,1,1,0,1,1,0,1,1,0,1,1,1,1], # 0 |
61
|
|
|
|
|
|
|
[0,0,1,0,0,1,0,0,1,0,0,1,0,0,1], # 1 |
62
|
|
|
|
|
|
|
[1,1,1,0,0,1,1,1,1,1,0,0,1,1,1], # 2 |
63
|
|
|
|
|
|
|
[1,1,1,0,0,1,1,1,1,0,0,1,1,1,1], # 3 |
64
|
|
|
|
|
|
|
[1,0,1,1,0,1,1,1,1,0,0,1,0,0,1], # 4 |
65
|
|
|
|
|
|
|
[1,1,1,1,0,0,1,1,1,0,0,1,1,1,1], # 5 |
66
|
|
|
|
|
|
|
[1,1,1,1,0,0,1,1,1,1,0,1,1,1,1], # 6 |
67
|
|
|
|
|
|
|
[1,1,1,0,0,1,0,0,1,0,0,1,0,0,1], # 7 |
68
|
|
|
|
|
|
|
[1,1,1,1,0,1,1,1,1,1,0,1,1,1,1], # 8 |
69
|
|
|
|
|
|
|
[1,1,1,1,0,1,1,1,1,0,0,1,1,1,1], # 9 |
70
|
|
|
|
|
|
|
]->[$number]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Convert number to text. |
74
|
|
|
|
|
|
|
sub _text { |
75
|
|
|
|
|
|
|
my ($char, $number) = @_; |
76
|
|
|
|
|
|
|
my $text = $EMPTY_STR; |
77
|
|
|
|
|
|
|
my $num_ar = _num($number); |
78
|
|
|
|
|
|
|
foreach my $i (0 .. $PIXELS) { |
79
|
|
|
|
|
|
|
if ($num_ar->[$i]) { |
80
|
|
|
|
|
|
|
$text .= $char x 2; |
81
|
|
|
|
|
|
|
} else { |
82
|
|
|
|
|
|
|
$text .= $BLANK_PIXEL; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
if ($i != $PIXELS && ($i + 1) % $PIXELS_ON_LINE == 0) { |
85
|
|
|
|
|
|
|
$text .= "\n"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
return $text; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |