| 1 | package UI::Dialog::Backend::CDialog; | ||
| 2 | ############################################################################### | ||
| 3 | # Copyright (C) 2004-2016 Kevin C. Krinke <kevin@krinke.ca> | ||
| 4 | # | ||
| 5 | # This library is free software; you can redistribute it and/or | ||
| 6 | # modify it under the terms of the GNU Lesser General Public | ||
| 7 | # License as published by the Free Software Foundation; either | ||
| 8 | # version 2.1 of the License, or (at your option) any later version. | ||
| 9 | # | ||
| 10 | # This library is distributed in the hope that it will be useful, | ||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 13 | # Lesser General Public License for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU Lesser General Public | ||
| 16 | # License along with this library; if not, write to the Free Software | ||
| 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 18 | ############################################################################### | ||
| 19 | 2 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 2 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | 2 | ▶ | use Config; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 2 | ▶ | use FileHandle; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 2 | ▶ | use Cwd qw( abs_path ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | 2 | ▶ | use Time::HiRes qw( sleep ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 27 | 2 | ▶ | use UI::Dialog::Backend; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 28 | |||
| 29 | BEGIN { | ||
| 30 | use vars qw( $VERSION @ISA ); | ||
| 31 | @ISA = qw( UI::Dialog::Backend ); | ||
| 32 | $VERSION = '1.14'; | ||
| 33 | } | ||
| 34 | |||
| 35 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 36 | #: Constructor Method | ||
| 37 | #: | ||
| 38 | |||
| 39 | sub new { | ||
| 40 | my $proto = shift(); | ||
| 41 | my $class = ref($proto) || $proto; | ||
| 42 | my $cfg = ((ref($_[0]) eq "HASH") ? $_[0] : (@_) ? { @_ } : {}); | ||
| 43 | my $self = {}; | ||
| 44 | bless($self, $class); | ||
| 45 | $self->{'_state'} = {}; | ||
| 46 | $self->{'_opts'} = {}; | ||
| 47 | |||
| 48 | #: Dynamic path discovery... | ||
| 49 | my $path_sep = $Config::Config{path_sep}; | ||
| 50 | my $CFG_PATH = $cfg->{'PATH'}; | ||
| 51 | if ($CFG_PATH) { | ||
| 52 | if (ref($CFG_PATH) eq "ARRAY") { | ||
| 53 | $self->{'PATHS'} = $CFG_PATH; | ||
| 54 | } | ||
| 55 | elsif ($CFG_PATH =~ m!$path_sep!) { | ||
| 56 | $self->{'PATHS'} = [ split(/$path_sep/,$CFG_PATH) ]; | ||
| 57 | } | ||
| 58 | elsif (-d $CFG_PATH) { | ||
| 59 | $self->{'PATHS'} = [ $CFG_PATH ]; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | elsif ($ENV{'PATH'}) { | ||
| 63 | $self->{'PATHS'} = [ split(/$path_sep/,$ENV{'PATH'}) ]; | ||
| 64 | } | ||
| 65 | else { | ||
| 66 | $self->{'PATHS'} = ''; | ||
| 67 | } | ||
| 68 | |||
| 69 | $self->{'_opts'}->{'literal'} = $cfg->{'literal'} || 0; | ||
| 70 | $self->{'_opts'}->{'callbacks'} = $cfg->{'callbacks'} || undef(); | ||
| 71 | $self->{'_opts'}->{'timeout'} = $cfg->{'timeout'} || 0; | ||
| 72 | $self->{'_opts'}->{'wait'} = $cfg->{'wait'} || 0; | ||
| 73 | $self->{'_opts'}->{'debug'} = $cfg->{'debug'} || undef(); | ||
| 74 | $self->{'_opts'}->{'title'} = $cfg->{'title'} || undef(); | ||
| 75 | $self->{'_opts'}->{'backtitle'} = $cfg->{'backtitle'} || undef(); | ||
| 76 | $self->{'_opts'}->{'width'} = $cfg->{'width'} || 65; | ||
| 77 | $self->{'_opts'}->{'height'} = $cfg->{'height'} || 10; | ||
| 78 | $self->{'_opts'}->{'percentage'} = $cfg->{'percentage'} || 1; | ||
| 79 | $self->{'_opts'}->{'colours'} = ($cfg->{'colours'} || $cfg->{'colors'}) ? 1 : 0; | ||
| 80 | $self->{'_opts'}->{'bin'} ||= $self->_find_bin('dialog'); | ||
| 81 | $self->{'_opts'}->{'bin'} ||= $self->_find_bin('dialog.exe') if $^O =~ /win32/i; | ||
| 82 | $self->{'_opts'}->{'autoclear'} = $cfg->{'autoclear'} || 0; | ||
| 83 | $self->{'_opts'}->{'clearbefore'} = $cfg->{'clearbefore'} || 0; | ||
| 84 | $self->{'_opts'}->{'clearafter'} = $cfg->{'clearafter'} || 0; | ||
| 85 | $self->{'_opts'}->{'beepbin'} = $cfg->{'beepbin'} || $self->_find_bin('beep') || '/usr/bin/beep'; | ||
| 86 | $self->{'_opts'}->{'beepbefore'} = $cfg->{'beepbefore'} || 0; | ||
| 87 | $self->{'_opts'}->{'beepafter'} = $cfg->{'beepafter'} || 0; | ||
| 88 | unless (-x $self->{'_opts'}->{'bin'}) { | ||
| 89 | croak("the dialog binary could not be found at: ".$self->{'_opts'}->{'bin'}); | ||
| 90 | } | ||
| 91 | $self->{'_opts'}->{'DIALOGRC'} = $cfg->{'DIALOGRC'} || undef(); | ||
| 92 | my $beginref = $cfg->{'begin'}; | ||
| 93 | $self->{'_opts'}->{'begin'} = (ref($beginref) eq "ARRAY") ? $beginref : undef(); | ||
| 94 | $self->{'_opts'}->{'cancel-label'} = $cfg->{'cancel-label'} || undef(); | ||
| 95 | $self->{'_opts'}->{'defaultno'} = $cfg->{'defaultno'} || 0; | ||
| 96 | $self->{'_opts'}->{'default-item'} = $cfg->{'default-item'} || undef(); | ||
| 97 | $self->{'_opts'}->{'exit-label'} = $cfg->{'exit-label'} || undef(); | ||
| 98 | $self->{'_opts'}->{'extra-button'} = $cfg->{'extra-button'} || 0; | ||
| 99 | $self->{'_opts'}->{'extra-label'} = $cfg->{'extra-label'} || undef(); | ||
| 100 | $self->{'_opts'}->{'help-button'} = $cfg->{'help-button'} || 0; | ||
| 101 | $self->{'_opts'}->{'help-label'} = $cfg->{'help-label'} || undef(); | ||
| 102 | $self->{'_opts'}->{'max-input'} = $cfg->{'max-input'} || 0; | ||
| 103 | $self->{'_opts'}->{'no-cancel'} = $cfg->{'no-cancel'} || $cfg->{'nocancel'} || 0; | ||
| 104 | $self->{'_opts'}->{'no-collapse'} = $cfg->{'no-collapse'} || 0; | ||
| 105 | $self->{'_opts'}->{'no-shadow'} = $cfg->{'no-shadow'} || 0; | ||
| 106 | $self->{'_opts'}->{'ok-label'} = $cfg->{'ok-label'} || undef(); | ||
| 107 | $self->{'_opts'}->{'shadow'} = $cfg->{'shadow'} || 0; | ||
| 108 | $self->{'_opts'}->{'tab-correct'} = $cfg->{'tab-correct'} || 0; | ||
| 109 | $self->{'_opts'}->{'tab-len'} = $cfg->{'tab-len'} || 0; | ||
| 110 | $self->{'_opts'}->{'listheight'} = $cfg->{'listheight'} || $cfg->{'menuheight'} || 5; | ||
| 111 | $self->{'_opts'}->{'formheight'} = $cfg->{'formheight'} || $cfg->{'listheight'} || 5; | ||
| 112 | $self->{'_opts'}->{'yes-label'} = $cfg->{'yes-label'} || undef(); | ||
| 113 | $self->{'_opts'}->{'no-label'} = $cfg->{'no-label'} || undef(); | ||
| 114 | |||
| 115 | $self->{'_opts'}->{'trust-input'} = $cfg->{'trust-input'} || 0; | ||
| 116 | |||
| 117 | $self->_determine_dialog_variant(); | ||
| 118 | |||
| 119 | $self->{'test_mode'} = $cfg->{'test_mode'} if exists $cfg->{'test_mode'}; | ||
| 120 | $self->{'test_mode_result'} = ''; | ||
| 121 | |||
| 122 | return($self); | ||
| 123 | } | ||
| 124 | |||
| 125 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 126 | #: Private Methods | ||
| 127 | #: | ||
| 128 | sub _determine_dialog_variant { | ||
| 129 | my $self = $_[0]; | ||
| 130 | my $str = `$self->{'_opts'}->{'bin'} --help 2>&1`; | ||
| 131 | if ($str =~ /version\s0\.[34]/m) { | ||
| 132 | # this version does not support colours, so far just FreeBSD 4.8 has this | ||
| 133 | # ancient binary. Bugreport from Jeroen Bulten indicates that he's | ||
| 134 | # got a version 0.3 (patched to 0.4) installed. ugh... | ||
| 135 | $self->{'_variant'} = "dialog"; | ||
| 136 | # the separate-output option seems to be the culprit of FreeBSD failure. | ||
| 137 | $self->{'_opts'}->{'force-no-separate-output'} = 1; | ||
| 138 | } | ||
| 139 | elsif ($str =~ /cdialog\s\(ComeOn\sDialog\!\)\sversion\s(\d+\.\d+.+)/) { | ||
| 140 | # We consider cdialog to be a colour supporting dialog variant all others | ||
| 141 | # are non-colourized and support only the base functionality :( | ||
| 142 | my $ver = $1; | ||
| 143 | if ($ver =~ /-20(?:0[3-9]|\d\d)/) { | ||
| 144 | $self->{'_variant'} = "cdialog"; | ||
| 145 | # these versions support colours :) | ||
| 146 | $self->{'_opts'}->{'colours'} = 1; | ||
| 147 | } | ||
| 148 | else { | ||
| 149 | $self->{'_variant'} = "dialog"; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | else { | ||
| 153 | $self->{'_variant'} = "dialog"; | ||
| 154 | } | ||
| 155 | undef($str); | ||
| 156 | } | ||
| 157 | |||
| 158 | my $SIG_CODE = {}; | ||
| 159 | sub _del_gauge { | ||
| 160 | my $CODE = $SIG_CODE->{$$}; | ||
| 161 | unless (not ref($CODE)) { | ||
| 162 | delete($CODE->{'_GAUGE'}); | ||
| 163 | $CODE->rv('1'); | ||
| 164 | $CODE->rs('null'); | ||
| 165 | $CODE->ra('null'); | ||
| 166 | $SIG_CODE->{$$} = ""; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | sub append_format_base { | ||
| 171 | my ($self,$args,$fmt) = @_; | ||
| 172 | $ENV{'DIALOGRC'} ||= ($args->{'DIALOGRC'} && -r $args->{'DIALOGRC'}) ? $args->{'DIALOGRC'} : ""; | ||
| 173 | $ENV{'DIALOG_CANCEL'} = '1'; | ||
| 174 | $ENV{'DIALOG_ERROR'} = '254'; | ||
| 175 | $ENV{'DIALOG_ESC'} = '255'; | ||
| 176 | $ENV{'DIALOG_EXTRA'} = '3'; | ||
| 177 | $ENV{'DIALOG_HELP'} = '2'; | ||
| 178 | $ENV{'DIALOG_OK'} = '0'; | ||
| 179 | $fmt = $self->append_format_check($args,$fmt,'backtitle','--backtitle {{backtitle}}'); | ||
| 180 | $fmt = $self->append_format_check($args,$fmt,"defaultno","--defaultno"); | ||
| 181 | $fmt = $self->append_format_check($args,$fmt,"extra-button","--extra-button"); | ||
| 182 | $fmt = $self->append_format_check($args,$fmt,"help-button","--help-button"); | ||
| 183 | $fmt = $self->append_format_check($args,$fmt,"no-cancel","--no-cancel"); | ||
| 184 | $fmt = $self->append_format_check($args,$fmt,"no-collapse","--no-collapse"); | ||
| 185 | $fmt = $self->append_format_check($args,$fmt,"no-shadow","--no-shadow"); | ||
| 186 | $fmt = $self->append_format_check($args,$fmt,"shadow","--shadow"); | ||
| 187 | $fmt = $self->append_format_check($args,$fmt,"tab-correct","--tab-correct"); | ||
| 188 | $fmt = $self->append_format_check($args,$fmt,"cancel-label","--cancel-label {{cancel-label}}"); | ||
| 189 | $fmt = $self->append_format_check($args,$fmt,"default-item","--default-item {{default-item}}"); | ||
| 190 | $fmt = $self->append_format_check($args,$fmt,"exit-label","--exit-label {{exit-label}}"); | ||
| 191 | $fmt = $self->append_format_check($args,$fmt,"extra-label","--extra-label {{extra-label}}"); | ||
| 192 | $fmt = $self->append_format_check($args,$fmt,"help-label","--help-label {{help-label}}"); | ||
| 193 | $fmt = $self->append_format_check($args,$fmt,"max-input","--max-input {{max-input}}"); | ||
| 194 | $fmt = $self->append_format_check($args,$fmt,"ok-label","--ok-label {{ok-label}}"); | ||
| 195 | $fmt = $self->append_format_check($args,$fmt,"tab-len","--tab-len {{tab-len}}"); | ||
| 196 | $fmt = $self->append_format_check($args,$fmt,"yes-label","--yes-label {{yes-label}}"); | ||
| 197 | $fmt = $self->append_format_check($args,$fmt,"no-label","--no-label {{no-label}}"); | ||
| 198 | |||
| 199 | if ($self->{'_opts'}->{'force-no-separate-output'}) { | ||
| 200 | delete $args->{'separate-output'}; | ||
| 201 | } else { | ||
| 202 | $fmt = $self->append_format_check($args,$fmt,"separate-output","--separate-output"); | ||
| 203 | } | ||
| 204 | if ($self->is_cdialog()) { | ||
| 205 | $fmt = $self->append_format($fmt,'--colors'); | ||
| 206 | $fmt = $self->append_format($fmt,'--cr-wrap'); | ||
| 207 | if (exists $args->{'begin'}) { | ||
| 208 | my $begin = $args->{'begin'}; | ||
| 209 | if (ref($begin) eq "ARRAY") { | ||
| 210 | $fmt = $self->append_format($fmt,'--begin '.$begin->[0].' '.$begin->[1]); | ||
| 211 | } | ||
| 212 | } | ||
| 213 | } | ||
| 214 | return $fmt; | ||
| 215 | } | ||
| 216 | |||
| 217 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 218 | #: Override Inherited Methods | ||
| 219 | #: | ||
| 220 | sub _organize_text { | ||
| 221 | my $self = $_[0]; | ||
| 222 | my $text = $_[1] || return(); | ||
| 223 | my $width = $_[2] || 65; | ||
| 224 | my $trust = (exists $_[3] && defined $_[3]) ? $_[3] : '0'; | ||
| 225 | my @array; | ||
| 226 | |||
| 227 | if (ref($text) eq "ARRAY") { | ||
| 228 | push(@array,@{$text}); | ||
| 229 | } | ||
| 230 | elsif ($text =~ /\\n/) { | ||
| 231 | @array = split(/\\n/,$text); | ||
| 232 | } | ||
| 233 | else { | ||
| 234 | @array = split(/\n/,$text); | ||
| 235 | } | ||
| 236 | $text = undef(); | ||
| 237 | |||
| 238 | @array = $self->word_wrap($width,"","",@array); | ||
| 239 | my $max = @array; | ||
| 240 | for (my $i = 0; $i < $max; $i++) { | ||
| 241 | $self->clean_format($trust,\$array[$i]); | ||
| 242 | } | ||
| 243 | |||
| 244 | if ($self->{'scale'}) { | ||
| 245 | foreach my $line (@array) { | ||
| 246 | my $s_line = $line; #$self->__TRANSLATE_CLEAN($line); | ||
| 247 | $s_line =~ s!\[A\=\w+\]!!gi; | ||
| 248 | $self->{'width'} = length($s_line) + 5 | ||
| 249 | if ($self->{'width'} - 5) < length($s_line) | ||
| 250 | && (length($s_line) <= $self->{'max-scale'}); | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | my $new_line = $^O =~ /win32/i ? '\n' : "\n"; | ||
| 255 | foreach my $line (@array) { | ||
| 256 | my $pad; | ||
| 257 | my $s_line = $self->_strip_text($line); | ||
| 258 | if ($line =~ /\[A\=(\w+)\]/i) { | ||
| 259 | my $align = $1; | ||
| 260 | $line =~ s!\[A\=\w+\]!!gi; | ||
| 261 | if (uc($align) eq "CENTER" || uc($align) eq "C") { | ||
| 262 | $pad = ((($self->{'_opts'}->{'width'} - 5) - length($s_line)) / 2); | ||
| 263 | } | ||
| 264 | elsif (uc($align) eq "LEFT" || uc($align) eq "L") { | ||
| 265 | $pad = 0; | ||
| 266 | } | ||
| 267 | elsif (uc($align) eq "RIGHT" || uc($align) eq "R") { | ||
| 268 | $pad = (($self->{'_opts'}->{'width'} - 5) - length($s_line)); | ||
| 269 | } | ||
| 270 | } | ||
| 271 | if ($pad) { | ||
| 272 | $text .= (" " x $pad).$new_line; | ||
| 273 | } | ||
| 274 | else { | ||
| 275 | $text .= $line . $new_line; | ||
| 276 | } | ||
| 277 | } | ||
| 278 | chomp($text); | ||
| 279 | return($self->_filter_text($text)); | ||
| 280 | } | ||
| 281 | sub _strip_text { | ||
| 282 | my $self = shift(); | ||
| 283 | my $text = shift(); | ||
| 284 | $text =~ s!\\Z0!!gmi; | ||
| 285 | $text =~ s!\\Z1!!gmi; | ||
| 286 | $text =~ s!\\Z2!!gmi; | ||
| 287 | $text =~ s!\\Z3!!gmi; | ||
| 288 | $text =~ s!\\Z4!!gmi; | ||
| 289 | $text =~ s!\\Z5!!gmi; | ||
| 290 | $text =~ s!\\Z6!!gmi; | ||
| 291 | $text =~ s!\\Z7!!gmi; | ||
| 292 | $text =~ s!\\Zb!!gmi; | ||
| 293 | $text =~ s!\\ZB!!gmi; | ||
| 294 | $text =~ s!\\Zu!!gmi; | ||
| 295 | $text =~ s!\\ZU!!gmi; | ||
| 296 | $text =~ s!\\Zr!!gmi; | ||
| 297 | $text =~ s!\\ZR!!gmi; | ||
| 298 | $text =~ s!\\Zn!!gmi; | ||
| 299 | $text =~ s!\[C=black\]!!gmi; | ||
| 300 | $text =~ s!\[C=red\]!!gmi; | ||
| 301 | $text =~ s!\[C=green\]!!gmi; | ||
| 302 | $text =~ s!\[C=yellow\]!!gmi; | ||
| 303 | $text =~ s!\[C=blue\]!!gmi; | ||
| 304 | $text =~ s!\[C=magenta\]!!gmi; | ||
| 305 | $text =~ s!\[C=cyan\]!!gmi; | ||
| 306 | $text =~ s!\[C=white\]!!gmi; | ||
| 307 | $text =~ s!\[B\]!!gmi; | ||
| 308 | $text =~ s!\[/B\]!!gmi; | ||
| 309 | $text =~ s!\[U\]!!gmi; | ||
| 310 | $text =~ s!\[/U\]!!gmi; | ||
| 311 | $text =~ s!\[R\]!!gmi; | ||
| 312 | $text =~ s!\[/R\]!!gmi; | ||
| 313 | $text =~ s!\[N\]!!gmi; | ||
| 314 | $text =~ s!\[A=\w+\]!!gmi; | ||
| 315 | return($text); | ||
| 316 | } | ||
| 317 | sub _filter_text { | ||
| 318 | my $self = shift(); | ||
| 319 | my $text = shift() || return(); | ||
| 320 | if ($self->is_cdialog() && $self->{'_opts'}->{'colours'}) { | ||
| 321 | $text =~ s!\[C=black\]!\\Z0!gmi; | ||
| 322 | $text =~ s!\[C=red\]!\\Z1!gmi; | ||
| 323 | $text =~ s!\[C=green\]!\\Z2!gmi; | ||
| 324 | $text =~ s!\[C=yellow\]!\\Z3!gmi; | ||
| 325 | $text =~ s!\[C=blue\]!\\Z4!gmi; | ||
| 326 | $text =~ s!\[C=magenta\]!\\Z5!gmi; | ||
| 327 | $text =~ s!\[C=cyan\]!\\Z6!gmi; | ||
| 328 | $text =~ s!\[C=white\]!\\Z7!gmi; | ||
| 329 | $text =~ s!\[B\]!\\Zb!gmi; | ||
| 330 | $text =~ s!\[/B\]!\\ZB!gmi; | ||
| 331 | $text =~ s!\[U\]!\\Zu!gmi; | ||
| 332 | $text =~ s!\[/U\]!\\ZU!gmi; | ||
| 333 | $text =~ s!\[R\]!\\Zr!gmi; | ||
| 334 | $text =~ s!\[/R\]!\\ZR!gmi; | ||
| 335 | $text =~ s!\[N\]!\\Zn!gmi; | ||
| 336 | $text =~ s!\[A=\w+\]!!gmi; | ||
| 337 | return($text); | ||
| 338 | } | ||
| 339 | else { | ||
| 340 | return($self->_strip_text($text)); | ||
| 341 | } | ||
| 342 | } | ||
| 343 | |||
| 344 | |||
| 345 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | ||
| 346 | #: Public Methods | ||
| 347 | #: | ||
| 348 | |||
| 349 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 350 | #: test for the good stuff | ||
| 351 | sub is_cdialog { | ||
| 352 | my $self = $_[0]; | ||
| 353 | return(1) if $self->{'_variant'} && $self->{'_variant'} eq "cdialog"; | ||
| 354 | return(0); | ||
| 355 | } | ||
| 356 | |||
| 357 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 358 | #: Ask a binary question (Yes/No) | ||
| 359 | sub yesno { | ||
| 360 | my $self = shift(); | ||
| 361 | my $caller = (caller(1))[3] || 'main'; | ||
| 362 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 363 | if ($_[0] && $_[0] eq 'caller') { | ||
| 364 | shift(); $caller = shift(); | ||
| 365 | } | ||
| 366 | my $args = $self->_pre($caller,@_); | ||
| 367 | |||
| 368 | my $fmt = $self->prepare_format($args); | ||
| 369 | $fmt = $self->append_format_base($args,$fmt); | ||
| 370 | $fmt = $self->append_format($fmt,'--yesno {{text}} {{height}} {{width}}'); | ||
| 371 | my $command = $self->prepare_command | ||
| 372 | ( $args, $fmt, | ||
| 373 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 374 | ); | ||
| 375 | |||
| 376 | my $rv = $self->command_state($command); | ||
| 377 | if ($rv && $rv >= 1) { | ||
| 378 | $self->ra("NO"); | ||
| 379 | $self->rs("NO"); | ||
| 380 | $self->rv($rv); | ||
| 381 | } | ||
| 382 | else { | ||
| 383 | $self->ra("YES"); | ||
| 384 | $self->rs("YES"); | ||
| 385 | $self->rv('null'); | ||
| 386 | } | ||
| 387 | $self->_post($args); | ||
| 388 | return($rv == 0 ? 1 : 0); | ||
| 389 | } | ||
| 390 | |||
| 391 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 392 | #: Text entry | ||
| 393 | sub inputbox { | ||
| 394 | my $self = shift(); | ||
| 395 | my $caller = (caller(1))[3] || 'main'; | ||
| 396 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 397 | if ($_[0] && $_[0] eq 'caller') { | ||
| 398 | shift(); $caller = shift(); | ||
| 399 | } | ||
| 400 | my $args = $self->_pre($caller,@_); | ||
| 401 | |||
| 402 | my $fmt = $self->prepare_format($args); | ||
| 403 | $fmt = $self->append_format_base($args,$fmt); | ||
| 404 | if ($args->{'password'}) { | ||
| 405 | if ($args->{'entry'}) { | ||
| 406 | $fmt = $self->append_format($fmt,'--insecure'); | ||
| 407 | } else { | ||
| 408 | $fmt = $self->append_format_check($args,$fmt,'insecure','--insecure'); | ||
| 409 | } | ||
| 410 | $fmt = $self->append_format($fmt,'--passwordbox'); | ||
| 411 | } | ||
| 412 | else { | ||
| 413 | $fmt = $self->append_format($fmt,'--inputbox'); | ||
| 414 | } | ||
| 415 | $fmt = $self->append_format($fmt,'{{text}} {{height}} {{width}} {{entry}}'); | ||
| 416 | my $command = $self->prepare_command | ||
| 417 | ( $args, $fmt, | ||
| 418 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 419 | entry => $self->make_kvl($args,($args->{'init'}||$args->{'entry'})), | ||
| 420 | ); | ||
| 421 | |||
| 422 | my ($rv,$text) = $self->command_string($command); | ||
| 423 | $self->_post($args); | ||
| 424 | return($rv == 0 ? $text : 0); | ||
| 425 | } | ||
| 426 | #: password boxes aren't supported by gdialog | ||
| 427 | sub password { | ||
| 428 | my $self = shift(); | ||
| 429 | return($self->inputbox('caller',((caller(1))[3]||'main'),@_,'password',1)); | ||
| 430 | } | ||
| 431 | |||
| 432 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 433 | #: Text box | ||
| 434 | sub msgbox { | ||
| 435 | my $self = shift(); | ||
| 436 | my $caller = (caller(1))[3] || 'main'; | ||
| 437 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 438 | if ($_[0] && $_[0] eq 'caller') { | ||
| 439 | shift(); $caller = shift(); | ||
| 440 | } | ||
| 441 | my $args = $self->_pre($caller,@_); | ||
| 442 | |||
| 443 | $args->{'msgbox'} ||= 'msgbox'; | ||
| 444 | |||
| 445 | my $fmt = $self->prepare_format($args); | ||
| 446 | $fmt = $self->append_format_base($args,$fmt); | ||
| 447 | if ($args->{'infobox'}) { | ||
| 448 | $fmt = $self->append_format($fmt,'--infobox'); | ||
| 449 | } | ||
| 450 | else { | ||
| 451 | $fmt = $self->append_format($fmt,'--msgbox'); | ||
| 452 | } | ||
| 453 | $fmt = $self->append_format($fmt,'{{text}} {{height}} {{width}}'); | ||
| 454 | my $command = $self->prepare_command | ||
| 455 | ( $args, $fmt, | ||
| 456 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 457 | ); | ||
| 458 | |||
| 459 | my $rv = $self->command_state($command); | ||
| 460 | if ($args->{'infobox'}) { | ||
| 461 | my $sec = 0; | ||
| 462 | if ($args->{'timeout'}) { | ||
| 463 | $sec = int($args->{'timeout'} ? ($args->{'timeout'} / 1000.0) : 1.0); | ||
| 464 | $self->_debug("Will sleep for timeout=".$sec); | ||
| 465 | } elsif ($args->{'wait'}) { | ||
| 466 | $sec = int($args->{'wait'} ? $args->{'wait'} : 1); | ||
| 467 | $self->_debug("Will sleep for wait=".$sec); | ||
| 468 | } | ||
| 469 | sleep($sec) if $sec; | ||
| 470 | } | ||
| 471 | $self->_post($args); | ||
| 472 | return($rv == 0 ? 1 : 0); | ||
| 473 | } | ||
| 474 | sub infobox { | ||
| 475 | my $self = shift(); | ||
| 476 | return($self->msgbox('caller',((caller(1))[3]||'main'),@_,'infobox',1)); | ||
| 477 | } | ||
| 478 | |||
| 479 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 480 | #: File box | ||
| 481 | sub textbox { | ||
| 482 | my $self = shift(); | ||
| 483 | my $caller = (caller(1))[3] || 'main'; | ||
| 484 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 485 | if ($_[0] && $_[0] eq 'caller') { | ||
| 486 | shift(); $caller = shift(); | ||
| 487 | } | ||
| 488 | my $args = $self->_pre($caller,@_); | ||
| 489 | |||
| 490 | my $fmt = $self->prepare_format($args); | ||
| 491 | $fmt = $self->append_format_base($args,$fmt); | ||
| 492 | $fmt = $self->append_format($fmt,'--scrolltext'); | ||
| 493 | $fmt = $self->append_format($fmt,'--textbox'); | ||
| 494 | $fmt = $self->append_format($fmt,'{{path}} {{height}} {{width}}'); | ||
| 495 | my $command = $self->prepare_command | ||
| 496 | ( $args, $fmt, | ||
| 497 | path => $self->make_kvl($args,($args->{'path'}||'.')), | ||
| 498 | ); | ||
| 499 | |||
| 500 | my ($rv,$text) = $self->command_string($command); | ||
| 501 | $self->_post($args); | ||
| 502 | return($rv == 0 ? 1 : 0); | ||
| 503 | } | ||
| 504 | |||
| 505 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 506 | #: a simple menu | ||
| 507 | sub menu { | ||
| 508 | my $self = shift(); | ||
| 509 | my $caller = (caller(1))[3] || 'main'; | ||
| 510 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 511 | if ($_[0] && $_[0] eq 'caller') { | ||
| 512 | shift(); $caller = shift(); | ||
| 513 | } | ||
| 514 | my $args = $self->_pre($caller,@_); | ||
| 515 | |||
| 516 | $args->{'listheight'} = $args->{'menuheight'} | ||
| 517 | if exists $args->{'menuheight'}; | ||
| 518 | |||
| 519 | my $fmt = $self->prepare_format($args); | ||
| 520 | $fmt = $self->append_format_base($args,$fmt); | ||
| 521 | $fmt = $self->append_format($fmt,'--menu'); | ||
| 522 | $fmt = $self->append_format($fmt,'{{text}} {{height}} {{width}} {{listheight}} {{list}}'); | ||
| 523 | my $command = $self->prepare_command | ||
| 524 | ( $args, $fmt, | ||
| 525 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 526 | ); | ||
| 527 | |||
| 528 | my ($rv,$selected) = $self->command_string($command); | ||
| 529 | $self->_post($args); | ||
| 530 | return($rv == 0 ? $selected : 0); | ||
| 531 | } | ||
| 532 | |||
| 533 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 534 | #: a check list | ||
| 535 | sub checklist { | ||
| 536 | my $self = shift(); | ||
| 537 | my $caller = (caller(1))[3] || 'main'; | ||
| 538 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 539 | if ($_[0] && $_[0] eq 'caller') { | ||
| 540 | shift(); $caller = shift(); | ||
| 541 | } | ||
| 542 | my $args = $self->_pre($caller,@_); | ||
| 543 | |||
| 544 | $args->{'listheight'} = $args->{'menuheight'} | ||
| 545 | if exists $args->{'menuheight'}; | ||
| 546 | |||
| 547 | my $fmt = $self->prepare_format($args); | ||
| 548 | $fmt = $self->append_format_base($args,$fmt); | ||
| 549 | if (exists $args->{radiolist} && $args->{radiolist} == 1) { | ||
| 550 | $fmt = $self->append_format($fmt,'--radiolist'); | ||
| 551 | } | ||
| 552 | else { | ||
| 553 | $fmt = $self->append_format($fmt,'--separate-output'); | ||
| 554 | $fmt = $self->append_format($fmt,'--checklist'); | ||
| 555 | } | ||
| 556 | $fmt = $self->append_format($fmt,'{{text}} {{height}} {{width}} {{listheight}} {{list}}'); | ||
| 557 | my $command = $self->prepare_command | ||
| 558 | ( $args, $fmt, | ||
| 559 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 560 | ); | ||
| 561 | |||
| 562 | if (exists $args->{radiolist} && $args->{radiolist} == 1) { | ||
| 563 | my ($rv,$selected) = $self->command_string($command); | ||
| 564 | return($rv == 0 ? $selected : 0); | ||
| 565 | } | ||
| 566 | my ($rv,$selected) = $self->command_array($command); | ||
| 567 | return($rv == 0 ? @{$selected} : 0); | ||
| 568 | } | ||
| 569 | #: a radio button list | ||
| 570 | sub radiolist { | ||
| 571 | my $self = shift(); | ||
| 572 | return($self->checklist('caller',((caller(1))[3]||'main'),@_,'radiolist',1)); | ||
| 573 | } | ||
| 574 | |||
| 575 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 576 | #: file select | ||
| 577 | sub fselect { | ||
| 578 | my $self = shift(); | ||
| 579 | unless ($self->is_cdialog()) { | ||
| 580 | return($self->SUPER::fselect(@_)); | ||
| 581 | } | ||
| 582 | my $caller = (caller(1))[3] || 'main'; | ||
| 583 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 584 | if ($_[0] && $_[0] eq 'caller') { | ||
| 585 | shift(); $caller = shift(); | ||
| 586 | } | ||
| 587 | my $args = $self->_pre($caller,@_); | ||
| 588 | |||
| 589 | my $fmt = $self->prepare_format($args); | ||
| 590 | $fmt = $self->append_format_base($args,$fmt); | ||
| 591 | $fmt = $self->append_format($fmt,'--fselect'); | ||
| 592 | $fmt = $self->append_format($fmt,'{{path}} {{height}} {{width}}'); | ||
| 593 | |||
| 594 | my $command = $self->prepare_command | ||
| 595 | ( $args, $fmt, | ||
| 596 | path => $self->make_kvl($args,($args->{'path'}||'.')), | ||
| 597 | ); | ||
| 598 | |||
| 599 | my ($rv,$file) = $self->command_string($command); | ||
| 600 | $self->_post($args); | ||
| 601 | return($rv == 0 ? $file : 0); | ||
| 602 | } | ||
| 603 | |||
| 604 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 605 | #: calendar | ||
| 606 | |||
| 607 | sub calendar { | ||
| 608 | my $self = shift(); | ||
| 609 | my $caller = (caller(1))[3] || 'main'; | ||
| 610 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 611 | if ($_[0] && $_[0] eq 'caller') { | ||
| 612 | shift(); $caller = shift(); | ||
| 613 | } | ||
| 614 | my $args = $self->_pre($caller,@_); | ||
| 615 | $args->{'day'} ||= '1'; | ||
| 616 | $args->{'month'} ||= '1'; | ||
| 617 | $args->{'year'} ||= '1970'; | ||
| 618 | |||
| 619 | my $fmt = $self->prepare_format($args); | ||
| 620 | $fmt = $self->append_format_base($args,$fmt); | ||
| 621 | $fmt = $self->append_format($fmt,'--calendar {{text}} {{listheight}} {{width}} {{day}} {{month}} {{year}}'); | ||
| 622 | my $command = $self->prepare_command | ||
| 623 | ( $args, $fmt, | ||
| 624 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 625 | ); | ||
| 626 | |||
| 627 | my ($rv,$date) = $self->command_string($command); | ||
| 628 | if ($rv == 0) { | ||
| 629 | $self->ra(split(m!/!,$date)); | ||
| 630 | } | ||
| 631 | $self->_post($args); | ||
| 632 | return($rv == 0 ? $date : 0) unless defined wantarray and wantarray; | ||
| 633 | return($rv == 0 ? $self->ra() : (0,0,0)); | ||
| 634 | } | ||
| 635 | |||
| 636 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 637 | #: timebox | ||
| 638 | |||
| 639 | sub timebox { | ||
| 640 | my $self = shift(); | ||
| 641 | my $caller = (caller(1))[3] || 'main'; | ||
| 642 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 643 | if ($_[0] && $_[0] eq 'caller') { | ||
| 644 | shift(); $caller = shift(); | ||
| 645 | } | ||
| 646 | my $args = $self->_pre($caller,@_); | ||
| 647 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); | ||
| 648 | $args->{'hour'} ||= $hour; | ||
| 649 | $args->{'minute'} ||= $min; | ||
| 650 | $args->{'second'} ||= $sec; | ||
| 651 | |||
| 652 | my $fmt = $self->prepare_format($args); | ||
| 653 | $fmt = $self->append_format_base($args,$fmt); | ||
| 654 | $fmt = $self->append_format($fmt,'--timebox {{text}} {{height}} {{width}} {{hour}} {{minute}} {{second}}'); | ||
| 655 | my $command = $self->prepare_command | ||
| 656 | ( $args, $fmt, | ||
| 657 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 658 | ); | ||
| 659 | |||
| 660 | my ($rv,$time) = $self->command_string($command); | ||
| 661 | if ($rv == 0) { | ||
| 662 | $self->ra(split(m!\:!,$time)); | ||
| 663 | } | ||
| 664 | $self->_post($args); | ||
| 665 | return($rv == 0 ? $time : 0) unless defined wantarray and wantarray; | ||
| 666 | return($rv == 0 ? $self->ra() : (0,0,0)); | ||
| 667 | } | ||
| 668 | |||
| 669 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 670 | #: tailbox | ||
| 671 | |||
| 672 | sub tailbox { | ||
| 673 | my $self = shift(); | ||
| 674 | my $caller = (caller(1))[3] || 'main'; | ||
| 675 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 676 | if ($_[0] && $_[0] eq 'caller') { | ||
| 677 | shift(); $caller = shift(); | ||
| 678 | } | ||
| 679 | my $args = $self->_pre($caller,@_); | ||
| 680 | |||
| 681 | my $fmt = $self->prepare_format($args); | ||
| 682 | $fmt = $self->append_format_base($args,$fmt); | ||
| 683 | $fmt = $self->append_format($fmt,'--tailbox'); | ||
| 684 | $fmt = $self->append_format($fmt,'{{path}} {{height}} {{width}}'); | ||
| 685 | my $command = $self->prepare_command | ||
| 686 | ( $args, $fmt, | ||
| 687 | path => $self->make_kvl($args,($args->{'path'}||'.')), | ||
| 688 | ); | ||
| 689 | |||
| 690 | my ($rv) = $self->command_state($command); | ||
| 691 | $self->_post($args); | ||
| 692 | return($rv == 0 ? 1 : 0); | ||
| 693 | } | ||
| 694 | |||
| 695 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 696 | #: tailboxbg | ||
| 697 | |||
| 698 | sub tailboxbg { | ||
| 699 | my $self = shift(); | ||
| 700 | my $caller = (caller(1))[3] || 'main'; | ||
| 701 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 702 | if ($_[0] && $_[0] eq 'caller') { | ||
| 703 | shift(); $caller = shift(); | ||
| 704 | } | ||
| 705 | my $args = $self->_pre($caller,@_); | ||
| 706 | |||
| 707 | my $fmt = $self->prepare_format($args); | ||
| 708 | $fmt = $self->append_format_base($args,$fmt); | ||
| 709 | $fmt = $self->append_format($fmt,'--tailboxbg'); | ||
| 710 | $fmt = $self->append_format($fmt,'{{path}} {{height}} {{width}}'); | ||
| 711 | my $command = $self->prepare_command | ||
| 712 | ( $args, $fmt, | ||
| 713 | path => $self->make_kvl($args,($args->{'path'}||'.')), | ||
| 714 | ); | ||
| 715 | |||
| 716 | my ($rv) = $self->command_state($command); | ||
| 717 | $self->_post($args); | ||
| 718 | return($rv == 0 ? 1 : 0); | ||
| 719 | } | ||
| 720 | |||
| 721 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 722 | #: an editable form (wow is this useful! holy cripes!) | ||
| 723 | sub form { | ||
| 724 | my $self = shift(); | ||
| 725 | my $caller = (caller(1))[3] || 'main'; | ||
| 726 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 727 | if ($_[0] && $_[0] eq 'caller') { | ||
| 728 | shift(); $caller = shift(); | ||
| 729 | } | ||
| 730 | my $args = $self->_pre($caller,@_); | ||
| 731 | |||
| 732 | $args->{'listheight'} = $args->{'menuheight'} | ||
| 733 | if exists $args->{'menuheight'}; | ||
| 734 | $args->{'listheight'} = $args->{'formheight'} | ||
| 735 | if exists $args->{'formheight'}; | ||
| 736 | |||
| 737 | my $fmt = $self->prepare_format($args); | ||
| 738 | $fmt = $self->append_format_base($args,$fmt); | ||
| 739 | $fmt = $self->append_format($fmt,'--form'); | ||
| 740 | $fmt = $self->append_format($fmt,'{{text}} {{height}} {{width}} {{listheight}} {{list}}'); | ||
| 741 | |||
| 742 | my $list = ''; | ||
| 743 | while (@{$args->{'list'}}) { | ||
| 744 | my $item = shift(@{$args->{'list'}}); | ||
| 745 | my $info = shift(@{$args->{'list'}}); | ||
| 746 | $self->clean_format($args->{'trust-input'},\$item->[0]); | ||
| 747 | $self->clean_format($args->{'trust-input'},\$item->[1]); | ||
| 748 | $self->clean_format($args->{'trust-input'},\$item->[2]); | ||
| 749 | $self->clean_format($args->{'trust-input'},\$info->[0]); | ||
| 750 | $self->clean_format($args->{'trust-input'},\$info->[1]); | ||
| 751 | $self->clean_format($args->{'trust-input'},\$info->[2]); | ||
| 752 | $self->clean_format($args->{'trust-input'},\$info->[3]); | ||
| 753 | $self->clean_format($args->{'trust-input'},\$info->[4]); | ||
| 754 | $list .= ' "'.($item->[0]||' ').'" "'.$item->[1].'" "'.$item->[2].'" "'.($info->[0]||' ').'" "'.$info->[1].'" "'.$info->[2].'" "'.$info->[3].'" "'.$info->[4].'"'; | ||
| 755 | } | ||
| 756 | delete $args->{'list'}; | ||
| 757 | $args->{'list'} = $list; | ||
| 758 | |||
| 759 | my $command = $self->prepare_command | ||
| 760 | ( $args, $fmt, | ||
| 761 | list => $self->make_kvl($args,$args->{'list'}), | ||
| 762 | ); | ||
| 763 | |||
| 764 | my ($rv,$selected) = $self->command_array($command); | ||
| 765 | $self->_post($args); | ||
| 766 | return($rv == 0 ? $selected : 0) unless defined wantarray and wantarray; | ||
| 767 | return($rv == 0 ? $self->ra() : (0)); | ||
| 768 | } | ||
| 769 | |||
| 770 | #:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 771 | #: progress meter | ||
| 772 | sub gauge_start { | ||
| 773 | my $self = shift(); | ||
| 774 | my $caller = (caller(1))[3] || 'main'; | ||
| 775 | $caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller; | ||
| 776 | if ($_[0] && $_[0] eq 'caller') { | ||
| 777 | shift(); $caller = shift(); | ||
| 778 | } | ||
| 779 | my $args = $self->_pre($caller,@_); | ||
| 780 | |||
| 781 | $self->{'_GAUGE'} ||= {}; | ||
| 782 | $self->{'_GAUGE'}->{'ARGS'} = $args; | ||
| 783 | |||
| 784 | if (defined $self->{'_GAUGE'}->{'FH'}) { | ||
| 785 | $self->rv(129); | ||
| 786 | $self->_post($args); | ||
| 787 | return(0); | ||
| 788 | } | ||
| 789 | |||
| 790 | my $fmt = $self->prepare_format($args); | ||
| 791 | $fmt = $self->append_format_base($args,$fmt); | ||
| 792 | $fmt = $self->append_format($fmt,'--gauge'); | ||
| 793 | $fmt = $self->append_format($fmt,'{{text}} {{height}} {{width}} {{percentage}}'); | ||
| 794 | my $command = $self->prepare_command | ||
| 795 | ( $args, $fmt, | ||
| 796 | text => $self->make_kvt($args,$args->{'text'}), | ||
| 797 | percentage => $self->make_kvl($args,$args->{'percentage'}||'0'), | ||
| 798 | ); | ||
| 799 | |||
| 800 | $self->{'_GAUGE'}->{'PERCENT'} = ($args->{'percentage'} || '0'); | ||
| 801 | $self->{'_GAUGE'}->{'FH'} = new FileHandle; | ||
| 802 | $self->{'_GAUGE'}->{'FH'}->open("| $command"); | ||
| 803 | my $rv = $? >> 8; | ||
| 804 | $self->{'_GAUGE'}->{'FH'}->autoflush(1); | ||
| 805 | $self->rv($rv||'null'); | ||
| 806 | $self->ra('null'); | ||
| 807 | $self->rs('null'); | ||
| 808 | return($rv && $rv >= 1); | ||
| 809 | } | ||
| 810 | sub gauge_inc { | ||
| 811 | my $self = $_[0]; | ||
| 812 | my $incr = $_[1] || 1; | ||
| 813 | |||
| 814 | return(0) unless defined $self->{'_GAUGE'}->{'FH'}; | ||
| 815 | |||
| 816 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 817 | $self->{'_GAUGE'}->{'PERCENT'} += $incr; | ||
| 818 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 819 | print $fh $self->{'_GAUGE'}->{'PERCENT'}."\n"; | ||
| 820 | return(((defined $self->{'_GAUGE'}->{'FH'}) ? 1 : 0)); | ||
| 821 | } | ||
| 822 | sub gauge_dec { | ||
| 823 | my $self = $_[0]; | ||
| 824 | my $decr = $_[1] || 1; | ||
| 825 | |||
| 826 | return(0) unless defined $self->{'_GAUGE'}->{'FH'}; | ||
| 827 | |||
| 828 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 829 | $self->{'_GAUGE'}->{'PERCENT'} -= $decr; | ||
| 830 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 831 | print $fh $self->{'_GAUGE'}->{'PERCENT'}."\n"; | ||
| 832 | return(((defined $self->{'_GAUGE'}->{'FH'}) ? 1 : 0)); | ||
| 833 | } | ||
| 834 | sub gauge_set { | ||
| 835 | my $self = $_[0]; | ||
| 836 | my $perc = $_[1] || $self->{'_GAUGE'}->{'PERCENT'} || 1; | ||
| 837 | |||
| 838 | return(0) unless $self->{'_GAUGE'}->{'FH'}; | ||
| 839 | |||
| 840 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 841 | $self->{'_GAUGE'}->{'PERCENT'} = $perc; | ||
| 842 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 843 | print $fh $self->{'_GAUGE'}->{'PERCENT'}."\n"; | ||
| 844 | return(((defined $self->{'_GAUGE'}->{'FH'}) ? 1 : 0)); | ||
| 845 | } | ||
| 846 | # funky flicker... grr | ||
| 847 | sub gauge_text { | ||
| 848 | my $self = $_[0]; | ||
| 849 | my $mesg = $_[1] || return(0); | ||
| 850 | |||
| 851 | return(0) unless $self->{'_GAUGE'}->{'FH'}; | ||
| 852 | |||
| 853 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 854 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 855 | print $fh "\nXXX\n\n".$mesg."\n\nXXX\n\n".$self->{'_GAUGE'}->{'PERCENT'}."\n"; | ||
| 856 | return(((defined $self->{'_GAUGE'}->{'FH'}) ? 1 : 0)); | ||
| 857 | } | ||
| 858 | sub gauge_stop { | ||
| 859 | my $self = $_[0]; | ||
| 860 | |||
| 861 | return(0) unless $self->{'_GAUGE'}->{'FH'}; | ||
| 862 | |||
| 863 | my $args = $self->{'_GAUGE'}->{'ARGS'}; | ||
| 864 | my $fh = $self->{'_GAUGE'}->{'FH'}; | ||
| 865 | $SIG_CODE->{$$} = $self; local $SIG{'PIPE'} = \&_del_gauge; | ||
| 866 | $self->{'_GAUGE'}->{'FH'}->close(); | ||
| 867 | delete($self->{'_GAUGE'}->{'FH'}); | ||
| 868 | delete($self->{'_GAUGE'}->{'ARGS'}); | ||
| 869 | delete($self->{'_GAUGE'}->{'PERCENT'}); | ||
| 870 | delete($self->{'_GAUGE'}); | ||
| 871 | $self->rv('null'); | ||
| 872 | $self->rs('null'); | ||
| 873 | $self->ra('null'); | ||
| 874 | $self->_post($args); | ||
| 875 | return(1); | ||
| 876 | } | ||
| 877 | |||
| 878 | |||
| 879 | 1; | ||
| 880 | |||