/usr/share/perl5/UI/Dialog/Backend.pm is in libui-dialog-perl 1.08-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | package UI::Dialog::Backend;
###############################################################################
# Copyright (C) 2004 Kevin C. Krinke <kckrinke@opendoorsoftware.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
###############################################################################
use 5.006;
use strict;
use Carp;
use Cwd qw( abs_path );
use File::Basename;
use Text::Wrap qw( wrap );
BEGIN {
use vars qw($VERSION);
$VERSION = '1.08';
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: Constructor Method
#:
#: not even really necessary as this class is inherited, and the constructor is
#: more often than not overridden by the backend inheriting it.
sub new {
my $proto = shift();
my $class = ref($proto) || $proto;
my $cfg = ((ref($_[0]) eq "HASH") ? $_[0] : (@_) ? { @_ } : {});
my $self = { '_opts' => $cfg };
bless($self, $class);
return($self);
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: Accessory Methods
#:
#: Provide the API interface to nautilus
sub nautilus {
my $self = $_[0];
my $nautilus = $self->{'_nautilus'} || {};
unless (ref($nautilus) eq "UI::Dialog::Backend::Nautilus") {
if ($self->_find_bin('nautilus')) {
if (eval "require UI::Dialog::Backend::Nautilus; 1") {
require UI::Dialog::Backend::Nautilus;
$self->{'_nautilus'} = new UI::Dialog::Backend::Nautilus;
}
}
}
return($self->{'_nautilus'});
}
#: Provide the API interface to osd_cat (aka: xosd)
sub xosd {
my $self = shift();
my @args = (@_ %2 == 0) ? (@_) : ();
my $xosd = $self->{'_xosd'} || {};
unless (ref($xosd) eq "UI::Dialog::Backend::XOSD") {
if ($self->_find_bin('osd_cat')) {
if (eval "require UI::Dialog::Backend::XOSD; 1") {
require UI::Dialog::Backend::XOSD;
$self->{'_xosd'} = new UI::Dialog::Backend::XOSD (@args);
}
}
}
return($self->{'_xosd'});
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: State Methods
#:
#: enable altering of attributes
sub attr {
my $self = $_[0];
my $name = $_[1];
unless ($_[2]) {
return($self->{'_opts'}->{$name}) unless not $self->{'_opts'}->{$name};
return(undef());
}
if ($_[2] == 0 || $_[2] =~ /^NULL$/i) {
$self->{'_opts'}->{$name} = 0;
} else {
$self->{'_opts'}->{$name} = $_[2];
}
return($self->{'_opts'}->{$name});
}
#: return the last response data as an ARRAY
sub ra {
my $self = shift();
$self->_debug((join(" | ",(caller())))." > ra() > rset: ".((@_) ? "@_" : 'NULL'),3);
$self->{'_state'}->{'ra'} = ($_[0] =~ /^null$/i) ? [ 0 ] : [ @_ ] unless not @_;
my $aref = $self->{'_state'}->{'ra'};
ref($aref) eq "ARRAY" or $aref = [];
return(@{$aref});
}
#: return the last response data as a SCALAR
sub rs {
my $self = shift();
my $rset = $_[0];
$self->_debug((join(" | ",(caller())))." > rs() > rset: ".(($rset) ? $rset : 'NULL'),3);
$self->{'_state'}->{'rs'} = ($rset =~ /^null$/i) ? 0 : $rset unless not $rset;
return($self->{'_state'}->{'rs'});
}
#: return the last exit code as a SCALAR
sub rv {
my $self = shift();
my $rset = $_[0];
$self->_debug((join(" | ",(caller())))." > rv() > rset: ".(($rset) ? $rset : 'NULL'),3);
$self->{'_state'}->{'rv'} = ($rset =~ /^null$/i) ? '0' : $rset unless not $rset;
return($self->{'_state'}->{'rv'});
}
#: report on the state of the last dialog variant execution.
sub state {
my $self = shift();
my $rv = $self->rv() || 0;
$self->_debug((join(" | ",(caller())))." > state() > is: ".($rv||'NULL'),2);
if ($rv == 1 or $rv == 129) {
return("CANCEL");
} elsif ($rv == 2) {
return("HELP");
} elsif ($rv == 3) {
return("EXTRA");
} elsif ($rv == 254) {
return("ERROR");
} elsif ($rv == 255) {
return("ESC");
} elsif (not $rv or $rv =~ /^null$/i) {
return("OK");
} else {
return("UNKNOWN(".$rv.")");
}
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: Execution Methods
#:
#: execute a simple command (return the exit code only);
sub command_state {
my $self = $_[0];
my $cmnd = $_[1];
$self->_debug("command: ".$cmnd,1);
system($cmnd . " 2>&1 > /dev/null");
my $rv = $? >> 8;
$self->_debug("command rv: ".$rv,2);
return($rv);
}
#: execute a command and return the exit code and one-line SCALAR
sub command_string {
my $self = $_[0];
my $cmnd = $_[1];
$self->_debug("command: ".$cmnd,1);
chomp(my $text = `$cmnd 2>&1`);
my $rv = $? >> 8;
$self->_debug("command rs: ".$rv." '".$text."'",2);
return($text) unless defined wantarray;
return (wantarray) ? ($rv,$text) : $text;
}
#: execute a command and return the exit code and ARRAY of data
sub command_array {
my $self = $_[0];
my $cmnd = $_[1];
$self->_debug("command: ".$cmnd,1);
chomp(my $text = `$cmnd 2>&1`);
my $rv = $? >> 8;
$self->_debug("command ra: ".$rv." '".$text."'",2);
return([split(/\n/,$text)]) unless defined wantarray;
return (wantarray) ? ($rv,[split(/\n/,$text)]) : [split(/\n/,$text)];
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: Utility Methods
#:
#: make some noise
sub beep {
my $self = $_[0];
return($self->_beep(1));
}
#: Clear terminal screen.
sub clear {
my $self = $_[0];
return($self->_clear(1));
}
# word-wrap a line
sub word_wrap {
my $self = shift();
my $width = shift() || 65;
my $indent = shift() || "";
my $sub_indent = shift() || "";
$Text::Wrap::columns = $width;
my @strings = wrap($indent, $sub_indent, @_);
return(@strings);
}
# generate a temporary file name
sub gen_tempfile_name {
my $self = $_[0];
my $template = $self->{'_opts'}->{'tempfiletemplate'} || "UI_Dialog_tempfile_XXXXX";
if (eval("require File::Temp; 1")) {
use File::Temp qw( tempfile );
my ($fh,$filename) = tempfile( UNLINK => 1 ) or croak( "Can't create tempfile: $!" );
return($filename) unless wantarray;
return($fh,$filename);
} else {
my $mktemp = $self->_find_bin('mktemp');
if ($mktemp && -x $mktemp) {
chomp(my $tempfile = `$mktemp "$template"`);
return($tempfile);
} else {
#pseudo-random filename coming up!
my $tempdir = "/tmp";
unless (-d $tempdir) {
if (-d "/var/tmp") {
$tempdir = "/var/tmp";
} else {
$tempdir = ".";
}
}
$self->gen_random_string(5);
my $tempfile = "UI_Dialog_tempfile_".$self->gen_random_string(5);
while (-e $tempdir."/".$tempfile) {
$self->gen_random_string(5);
$tempfile = "UI_Dialog_tempfile_".$self->gen_random_string(5);
}
return($tempdir."/".$tempfile);
}
}
}
# generate a random string as a (possibly) suitable failover option in the
# event that File::Temp is not installed and the 'mktemp' program does not
# exist in the path.
sub gen_random_string {
my $self = $_[0];
my $length = $_[1] || 5;
my $string = "";
my $counter = 0;
while ($counter < $length) {
# 33 - 127
my $num = rand(128);
while ($num < 33 or $num > 127) { $num = rand(128); }
$string .= chr($num);
$counter++;
}
return($string);
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: Widget Wrapping Methods
#:
#:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#: file select
sub fselect {
my $self = shift();
my $caller = (caller(1))[3] || 'main';
$caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller;
if ($_[0] && $_[0] eq 'caller') { shift(); $caller = shift(); }
my $args = $self->_pre($caller,@_);
$self->rv('NULL');
$self->rs('NULL');
$self->ra('NULL');
$self->_beep($args->{'beepbefore'});
my $cwd = abs_path();
$args->{'path'} ||= abs_path();
my $path = $args->{'path'};
if (!$path || $path =~ /^(\.|\.\/)$/) { $path = $cwd; }
my $file;
my ($menu,$list) = ([],[]);
FSEL: while ($self->state() ne "ESC" && $self->state() ne "CANCEL") {
my $entries = ($args->{'dselect'}) ? ['[new directory]'] : ['[new file]'];
($menu, $list) = $self->_list_dir($path,$entries);
$file = $self->menu(height=>$args->{'height'},width=>$args->{'width'},listheight=>($args->{'listheight'}||$args->{'menuheight'}),
title=>$args->{'title'},text=>$path,list=>$menu);
if ($self->state() eq "CANCEL") {
$self->rv(1);
$self->rs('NULL');
$self->ra('NULL');
last FSEL;
} elsif ($file ne "") {
if ($list->[($file - 1 || 0)] =~ /^\[(new\sdirectory|new\sfile)\]$/) {
my $nfn;
while (!$nfn || -e $path."/".$nfn) {
$nfn = $self->inputbox(height=>$args->{'height'},width=>$args->{'width'},title=>$args->{'title'},
text=>'Enter a name (will have a base directory of: '.$path.')');
next FSEL if $self->state() eq "ESC" or $self->state() eq "CANCEL";
if (-e $path."/".$nfn) { $self->msgbox(title=>'error',text=>$path."/".$nfn.' already exists! Choose another name please.'); }
}
$file = $path."/".$nfn;
$file =~ s!/$!! unless $file =~ m!^/$!;
$file =~ s!/\./!/!g; $file =~ s!/+!/!g;
last FSEL;
} elsif ($list->[($file - 1 || 0)] eq "../") {
$path = dirname($path);
} elsif ($list->[($file - 1 || 0)] eq "./") {
$file = $path;
$file =~ s!/$!! unless $file =~ m!^/$!;
$file =~ s!/\./!/!g; $file =~ s!/+!/!g;
last FSEL;
} elsif (-d $path."/".$list->[($file - 1 || 0)]) {
$path = $path."/".$list->[($file - 1 || 0)];
} elsif (-e $path."/".$list->[($file - 1 || 0)]) {
$file = $path."/".$list->[($file - 1 || 0)];
$file =~ s!/$!! unless $file =~ m!^/$!;
$file =~ s!/\./!/!g; $file =~ s!/+!/!g;
last FSEL;
}
}
$file = undef();
$path =~ s!(/*)!/!; $path =~ s!/\./!/!g;
}
$self->_beep($args->{'beepafter'});
my $rv = $self->rv();
$self->ra('NULL');
if ($rv && $rv >= 1) {
$self->rs('NULL');
return(0);
} else {
$self->rs($file);
return($file);
}
}
#:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#: directory selection
sub dselect {
my $self = shift();
my $caller = (caller(1))[3] || 'main';
$caller = ($caller =~ /^UI\:\:Dialog\:\:Backend\:\:/) ? ((caller(2))[3]||'main') : $caller;
if ($_[0] && $_[0] eq 'caller') { shift(); $caller = shift(); }
my $args = $self->_pre($caller,@_);
my $dirname;
$self->rv('NULL');
$self->rs('NULL');
$self->ra('NULL');
while (not $dirname && $self->state() !~ /^(CANCEL|ESC|ERROR)$/) {
$dirname = $self->fselect(@_,'dselect',1);
if ($self->state() =~ /^(CANCEL|ESC|ERROR)$/) {
return(0);
}
unless (not $dirname) {
# if it's a directory or not exist (assume new dir)
unless (-d $dirname || not -e $dirname) {
$self->msgbox( text => $dirname . " is not a directory.\nPlease select a directory." );
$dirname = undef();
}
}
}
return($dirname||'');
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#: Backend Methods
#:
sub _pre {
my $self = shift();
my $caller = shift();
my $args = $self->_merge_attrs(@_);
$args->{'caller'} = $caller;
my $class = ref($self);
my $CODEREFS = $args->{'callbacks'};
if (ref($CODEREFS) eq "HASH") {
my $PRECODE = $CODEREFS->{'PRE'};
if (ref($PRECODE) eq "CODE") {
&$PRECODE($args,$self->state());
}
}
$self->_beep($args->{'beepbefore'});
$self->_clear($args->{'clearbefore'});
return($args);
}
sub _post {
my $self = shift();
my $args = shift() || {};
my $class = ref($self);
$self->_beep($args->{'beepafter'});
$self->_clear($args->{'clearafter'});
my $CODEREFS = $args->{'callbacks'};
if (ref($CODEREFS) eq "HASH") {
my $state = $self->state();
if ($state eq "OK") {
my $OKCODE = $CODEREFS->{'OK'};
if (ref($OKCODE) eq "CODE") {
&$OKCODE($args);
}
} elsif ($state eq "ESC") {
my $ESCCODE = $CODEREFS->{'ESC'};
if (ref($ESCCODE) eq "CODE") {
&$ESCCODE($args);
}
} elsif ($state eq "CANCEL") {
my $CANCELCODE = $CODEREFS->{'CANCEL'};
if (ref($CANCELCODE) eq "CODE") {
&$CANCELCODE($args);
}
}
my $POSTCODE = $CODEREFS->{'POST'};
if (ref($POSTCODE) eq "CODE") {
&$POSTCODE($args,$state);
}
}
return(1);
}
#: merge the arguments with the default attributes, and arguments override defaults.
sub _merge_attrs {
my $self = shift();
my $args = (@_ % 2) ? { @_, '_odd' } : { @_ };
my $defs = $self->{'_opts'};
foreach my $def (keys(%$defs)) {
$args->{$def} = $defs->{$def} unless $args->{$def};
}
# alias 'filename' and 'file' to path
$args->{'path'} = (($args->{'filename'}) ? $args->{'filename'} :
($args->{'file'}) ? $args->{'file'} :
($args->{'path'}) ? $args->{'path'} : "");
if ($args->{'title'} && length($args->{'title'})) {
$args->{'title'} = $self->_esc_text($args->{'title'});
}
if ($args->{'backtitle'} && length($args->{'backtitle'})) {
$args->{'backtitle'} = $self->_esc_text($args->{'backtitle'});
}
# if ($args->{'text'} && length($args->{'text'})) {
# my $text = $args->{'text'};
# if (ref($text) eq "ARRAY") {
# $args->{'text'} = $self->_esc_text_array($args->{'text'});
# } else {
# $args->{'text'} = $self->_esc_text($args->{'text'});
# }
# }
if ($args->{'list'} && length($args->{'list'})) {
my $list = $args->{'list'};
if (ref($list) eq "ARRAY") {
my $total = @{$list};
for (my $i = 0; $i < $total; $i++) {
my $elem = $list->[$i];
if (ref($elem) eq "ARRAY") {
my $elem_total = @{$elem};
for (my $j = 0; $j < $elem_total; $j++) {
$elem->[$j] = $self->_esc_text($elem->[$j]);
}
} else {
$list->[$i] = $self->_esc_text($list->[$i]);
}
}
} else {
$args->{'list'} = $self->_esc_text($args->{'list'});
}
}
$args->{'clear'} = $args->{'clearbefore'} || $args->{'clearafter'} || $args->{'autoclear'} || 0;
$args->{'beep'} = $args->{'beepbefore'} || $args->{'beepafter'} || $args->{'autobeep'} || 0;
return($args);
}
#: search through the given paths for a specific variant
sub _find_bin {
my $self = $_[0];
my $variant = $_[1];
$self->{'PATHS'} = ((ref($self->{'PATHS'}) eq "ARRAY") ? $self->{'PATHS'} :
($self->{'PATHS'}) ? [ $self->{'PATHS'} ] :
[ '/bin', '/usr/bin', '/usr/local/bin', '/opt/bin' ]);
foreach my $PATH (@{$self->{'PATHS'}}) {
return($PATH . '/' . $variant)
unless not -x $PATH . '/' . $variant;
}
return(0);
}
#: clean the text arguments of all colour codes, alignments and attributes.
sub _strip_text {
my $self = $_[0];
my $text = $_[1];
$text =~ s!\\Z[0-7bBuUrRn]!!gmi;
$text =~ s!\[[AC]=\w+\]!!gmi;
$text =~ s!\[/?[BURN]\]!!gmi;
return($text);
}
sub _esc_text {
my $self = $_[0];
my $text = $_[1];
unless (ref($text)) {
$text =~ s!\"!\\"!gm;
$text =~ s!\`!\\`!gm;
$text =~ s!\(!\(!gm;
$text =~ s!\)!\)!gm;
$text =~ s!\[!\[!gm;
$text =~ s!\]!\]!gm;
$text =~ s!\{!\{!gm;
$text =~ s!\}!\}!gm;
$text =~ s!\$!\\\$!gm;
$text =~ s!\>!\>!gm;
$text =~ s!\<!\<!gm;
}
return($text);
}
#: indent and organize the text argument
sub _organize_text {
my $self = $_[0];
my $text = $_[1] || return();
my $width = $_[2] || 65;
my @array;
if (ref($text) eq "ARRAY") { push(@array,@{$text}); }
elsif ($text =~ /\\n/) { @array = split(/\\n/,$text); }
else { @array = split(/\n/,$text); }
$text = undef();
@array = $self->word_wrap($width,"","",@array);
my $max = @array;
for (my $i = 0; $i < $max; $i++) { $array[$i] = $self->_esc_text($array[$i]); }
if ($self->{'scale'}) {
foreach my $line (@array) {
my $s_line = $self->__TRANSLATE_CLEAN($line);
$s_line =~ s!\[A\=\w+\]!!gi;
$self->{'width'} = length($s_line) + 5
if ($self->{'width'} - 5) < length($s_line)
&& (length($s_line) <= $self->{'max-scale'});
}
}
foreach my $line (@array) {
my $pad;
my $s_line = $self->_strip_text($line);
if ($line =~ /\[A\=(\w+)\]/i) {
my $align = $1;
$line =~ s!\[A\=\w+\]!!gi;
if (uc($align) eq "CENTER" || uc($align) eq "C") {
# $pad = ((($self->{'_opts'}->{'width'} - 5) - length($s_line)) / 2);
$pad = (($self->{'_opts'}->{'width'} - length($s_line)) / 2);
} elsif (uc($align) eq "LEFT" || uc($align) eq "L") {
$pad = 0;
} elsif (uc($align) eq "RIGHT" || uc($align) eq "R") {
# $pad = (($self->{'_opts'}->{'width'} - 5) - length($s_line));
$pad = (($self->{'_opts'}->{'width'}) - length($s_line));
}
}
if ($pad) { $text .= (" " x $pad).$line."\n"; }
else { $text .= $line."\n"; }
}
$text = $self->_strip_text($text);
chomp($text);
return($text);
}
#: is this a BSD system?
sub _is_bsd {
my $self = shift();
return(1) if $^O =~ /bsd/i;
return(0);
}
#: gather a list of the contents of a directory and return it in
#: two forms, one is the "simple" list of all the filenames and the
#: other is a 'menu' list corresponding to the simple list.
sub _list_dir {
my $self = shift();
my $path = shift() || return();
my $pref = shift();
my (@listing,@list);
if (opendir(GETDIR,$path)) {
my @dir_data = readdir(GETDIR);
closedir(GETDIR);
if ($pref) { push(@listing,@{$pref}); }
foreach my $dir (sort(grep { -d $path."/".$_ } @dir_data)) { push(@listing,$dir."/"); }
foreach my $item (sort(grep { !-d $path."/".$_ } @dir_data)) { push(@listing,$item); }
my $c = 1;
foreach my $item (@listing) { push(@list,"$c",$item); $c++; }
return(\@list,\@listing);
} else {
return("failed to read directory: ".$path);
}
}
sub _debug {
my $self = $_[0];
my $mesg = $_[1] || 'null debug message given!';
my $rate = $_[2] || 1;
return() unless $self->{'_opts'}->{'debug'} and $self->{'_opts'}->{'debug'} >= $rate;
chomp($mesg);
print STDERR "Debug: ".$mesg."\n";
}
sub _error {
my $self = $_[0];
my $mesg = $_[1] || 'null error message given!';
chomp($mesg);
print STDERR "Error: ".$mesg."\n";
}
#: really make some noise
sub _beep {
my $self = $_[0];
my $beep = $_[1];
unless (not $beep) {
if (-x $self->{'_opts'}->{'beepbin'}) {
return(eval { system($self->{'_opts'}->{'beepbin'}); 1; });
} else {
return (1) unless $ENV{'TERM'} && $ENV{'TERM'} ne "dumb";
print STDERR "\a";
}
}
return(1);
}
#: The actual clear action.
sub _clear {
my $self = $_[0];
my $clear = $_[1] || 0;
# Useless with GUI based variants so we return here.
# Is the use of the "dumb" TERM appropriate? need feedback.
return (1) unless $ENV{'TERM'} && $ENV{'TERM'} ne "dumb";
unless (not $clear and not $self->{'_opts'}->{'autoclear'}) {
$self->{'_clear'} ||= `clear`;
print STDOUT $self->{'_clear'};
}
return(1);
}
1;
|