blib/lib/App/Asciio/Text/Asciio/Dialogs.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 104 CC 6 SCAR 16.4
CC
6
Cov
0%
display_quit_dialog
12.0
get_color_from_user
6.0
display_edit_dialog
6.0
CRAP 5.2
1  
2 package App::Asciio::Text ;
3 $|++ ;
4  
5 use strict;
6 use warnings;
7  
8 use Data::TreeDumper ;
9 use IO::Prompter ;
10 use Term::ANSIColor qw(colorvalid) ;
11  
12 #-----------------------------------------------------------------------------
13  
14 sub get_color_from_user
15 {
16 my ($self, $previous_color) = @_ ;
17  
18 print "\e[2J\e[H\e[?25h" ;
19  
20 my $color = prompt "ANSI color name:", -complete => [qw(on bold black red green yellow blue magenta cyan white rgb ansi grey)], -default => '' ;
21 $color //= '' ;
22  
23 $color = '' unless colorvalid($color) ;
24  
25 return $color ;
26 }
27  
28 #-----------------------------------------------------------------------------
29  
30 sub show_dump_window
31 {
32 my ($self, $data, $title, @dumper_setup) = @_ ;
33  
34 print "\e[2J\e[H\e[?25h" ;
35  
36 print DumpTree $data, @dumper_setup ;
37 $a = prompt -1, 'press key to continue ...' ;
38 $self->update_display() ;
39 }
40  
41  
42 #-----------------------------------------------------------------------------
43  
44 sub display_message_modal
45 {
46 my ($self, $message) = @_ ;
47  
48 print "\e[2J\e[H\e[?25h" ;
49  
50 print "$message\n" ;
51 $a = prompt -1, 'press key to continue ...' ;
52 $self->update_display() ;
53 }
54  
55 #-----------------------------------------------------------------------------
56  
57 sub display_yes_no_cancel_dialog
58 {
59 my ($self, $title, $text) = @_ ;
60  
61 print "\e[2J\e[H\e[?25h" ;
62  
63 my $result = prompt "$title [yes, no, cancel]:", -complete => ['yes', 'no', 'cancel'] ;
64  
65 $self->update_display() ;
66  
67 return $result ;
68 }
69  
70 #-----------------------------------------------------------------------------
71  
72 sub display_quit_dialog
73 {
74 my ($self, $title, $text) = @_ ;
75  
76 print "\e[2J\e[H\e[?25h" ;
77  
78 my @choices = ('continue editing', 'save and quit', 'quit and lose changes') ;
79  
80 my $result = prompt $text, -number, -menu => \@choices, -1, -default => 'a', '>' ;
81  
82 $result = 'save_and_quit' if $result eq 'save and quit' ;
83 $result = 'ok' if $result eq 'quit and lose changes' ;
84  
85 $self->update_display() ;
86  
87 return $result ;
88 }
89  
90 #-----------------------------------------------------------------------------
91  
92 sub display_edit_dialog
93 {
94 my ($self, $title, $text) = @_ ;
95  
96 print "\e[2J\e[H\e[?25h" ;
97  
98 my $result ;
99  
100 my $input = prompt "$title:" ;
101 if($input)
102 {
103 $input =~ s/\r$// ;
104 $input =~ s/\\n/\n/g ;
105 $result = "$input" ;
106 }
107 else
108 {
109 $result = $text ;
110 }
111  
112 $self->update_display() ;
113  
114 return $result // '' ;
115 }
116  
117 #-----------------------------------------------------------------------------
118  
119 sub get_file_name
120 {
121 my ($self, $type) = @_ ; # type: save|open
122  
123 print "\e[2J\e[H\e[?25h" ;
124  
125 my $result = '' ;
126  
127 my $input = prompt 'file name:', -complete => 'filenames' ;
128  
129 if($input)
130 {
131 $input =~ s/\r$// ;
132 $input =~ s/\\n/\n/g ;
133 $result = "$input" ;
134 }
135 else
136 {
137 $result = '' ;
138 }
139  
140 $self->update_display() ;
141  
142 return $result ;
143 }
144  
145  
146 #-----------------------------------------------------------------------------
147  
148 1 ;