1 # Like the Debug class the user_interface (ui) class is a little bit
2 # special in that it should never be instanciated. An instance (named
3 # ui) is kept globally which can be accessed by the members of the
4 # ui class if they are called statically. Calling a member staticaly
5 # means that you adress them using the perl module name, for example:
7 # ui -> print( 'print this on the screen' );
9 # Notice that there is no $ in front of 'ui'. Here print is called
10 # "statically". In other words, it means "call a member without an
15 start include statements
20 # These variables are used for mapping level names to numbers.
22 my $the_instance = ui
::new
();
24 end include statements
38 # ui -> category( 'bootstrap' )
40 # If you give a value to category as a single argument, you will
41 # set the global category of user interface messages.
43 # my $current_category = ui -> category
45 # If you don't give any argument the current category is returned.
48 $the_instance -> {'category'} = $parm;
50 return $the_instance -> {'category'};
64 # ui -> package( 'output' )
66 # If you give a value to package as a single argument, you will
67 # set the global package of ui messages.
69 # my $current_package = ui -> package
71 # If you don't give any argument the current package is returned.
74 $the_instance -> {'package'} = $parm;
76 return $the_instance -> {'package'};
90 # ui -> subroutine( 'output' )
92 # If you give a value to subroutine as a single argument, you will
93 # set the global subroutine of ui messages.
95 # my $current_subroutine = ui -> subroutine
97 # If you don't give any argument the current subroutine is returned.
100 $the_instance -> {'subroutine'} = $parm;
102 return $the_instance -> {'subroutine'};
116 # ui -> print( category => 'bootstrap',
117 # message => 'This is a message' );
119 # ui::print will print out messages corresponding to the category specified as
120 # argument. ui::print will look at the category given and the
121 # global category to see whether anything should be printed.
124 # NOTICE the lack of "\n" at the end of the message, ui::print
125 # will append one "\n". In case there ever is a GUI for PsN
126 # ui::print could be used to create a message in the GUI. And
127 # in that case, an extra "\n" might be annoying.
128 return if( $the_instance -> {'silent'} );
129 if( $the_instance -> {'category'} eq $category or $category eq 'all' ){
130 my ( $package_junk, $filename, $line, $subroutine, $junk ) = caller(1);
131 my @names = split('::', $subroutine );
132 $subroutine = $names[$#names];
133 my $package = join( '::', @names[0..$#names-1] );
135 if ( ( not defined $the_instance -> {'package'} or
136 $the_instance -> {'package'} eq $package ) and
137 ( not defined $the_instance -> {'subroutine'} or
138 $the_instance -> {'subroutine'} eq $subroutine ) ) {
143 my $nl = $newline ?
"\n" : '';
146 $text = wrap
('', '', $message . $nl );
148 $text = $message . $nl;
151 print STDERR
( $text );
162 my $part = int(($sofar/$goal)*$width);
163 $bar = "\r".'|'.'.' x
$part . ' ' x
($width-$part) . '|';
172 if( defined($parm) ){
173 $the_instance -> {'silent'} = $parm;
175 return $the_instance -> {'silent'};