trick/bin/pm/trick_print.pm
Alex Lin 14a75508a3 Cleaning up once include variables and copyright cleanup.
Changed all header file once include variables to follow the same naming
convention and not start with any underscores.  Also deleted old
incorrect copyright notices.  Also removed $Id: tags from all files.

Fixes #14.  Fixes #22.
2015-03-23 16:03:14 -05:00

54 lines
2.2 KiB
Perl
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package trick_print ;
use Exporter ();
@ISA = qw(Exporter);
@EXPORT = qw(trick_print);
use strict ;
my %message_type = (
"title_white" , { "color" , 00 , "level" , 1 } ,
"title_red" , { "color" , 31 , "level" , 1 } ,
"title_green" , { "color" , 32 , "level" , 1 } ,
"title_yellow" , { "color" , 33 , "level" , 1 } ,
"title_blue" , { "color" , 34 , "level" , 1 } ,
"title_magenta" , { "color" , 35 , "level" , 1 } ,
"title_cyan" , { "color" , 36 , "level" , 1 } ,
"normal_white" , { "color" , 00 , "level" , 2 } ,
"normal_red" , { "color" , 31 , "level" , 2 } ,
"normal_green" , { "color" , 32 , "level" , 2 } ,
"normal_yellow" , { "color" , 33 , "level" , 2 } ,
"normal_blue" , { "color" , 34 , "level" , 2 } ,
"normal_magenta" , { "color" , 35 , "level" , 2 } ,
"normal_cyan" , { "color" , 36 , "level" , 2 } ,
"debug_white" , { "color" , 00 , "level" , 3 } ,
"debug_red" , { "color" , 31 , "level" , 3 } ,
"debug_green" , { "color" , 32 , "level" , 3 } ,
"debug_yellow" , { "color" , 33 , "level" , 3 } ,
"debug_blue" , { "color" , 34 , "level" , 3 } ,
"debug_magenta" , { "color" , 35 , "level" , 3 } ,
"debug_cyan" , { "color" , 36 , "level" , 3 }
) ;
sub trick_print($$$$) {
my ($fh, $message, $mt , $verbose) = @_ ;
# print at least lvl 2 messages to the file
if ( defined $fh ) {
my ($temp_verbose) = $verbose ;
$temp_verbose = 2 if ($temp_verbose < 2) ;
if ( $temp_verbose >= $message_type{$mt}{level} ) {
print $fh "$message" ;
}
}
# print the message to the screen
if ( $verbose >= $message_type{$mt}{level} ) {
$message =~ s/(\n)?$/$1/s ;
print "[$message_type{$mt}{color}m$message" ;
}
}
1;