Archlinux::Term - Print messages to the terminal in Archlinux style
use Archlinux::Term; status( 'This is a status message' ); substatus( 'This is a substatus message' ); warning( 'This is a warning message' ); error( 'This is a fatal error message' ); # Also exits the program msg( 'This is just an indented message' );
Outputs:
==> This is a status message -> This is a substatus message ==> WARNING: This is a warning message ==> ERROR: This is a fatal error message This is just an indented message
Archlinux has a distinctive and simple style for displaying messages on the terminal. This style is used in the init scripts and pacman to give a cohesive look to Archlinux's terminal. This module makes it easy to use that style in your perl scripts.
No functions are exported by default. This is different from the first incarnation of this module. In order to import all functions from this module you can use the :all export tag like so:
:all
use Archlinux::Term qw(:all);
Every function takes a list of multiple arguments which are joined together, word-wrapped and printed to the screen. If a message goes past the screen limit it is wordwrapped and indented past the prefix.
join
Prints a simple message. There is no coloring it is merely wordwrapped and indented by four spaces.
Prints a status message. These are basically like major headings in a document. The message is prefixed with a green arrow:
Prints a sub-status message. These are like minor headings in a document. The message is prefixed with a little blue arrow.
Prints a warning message. These are non-fatal warning messages; the program will keep running. Warnings are printed to STDERR by using warn. The message is prefixed with a yellow arrow and capital WARNING.
warn
Prints a fatal error message AND DIES, EXITING. There is no line number appended to the die message. $@ or $EVAL_ERROR is the colorized output. Errors are printed to STDERR by using die. The message is prefixed with a red arrow and capital ERROR.
die
$@
$EVAL_ERROR
The error can be caught with an enclosing eval block. If the error isn't caught it is displayed on the screen and the program exits.
eval
eval { if ( $stuff eq 'bad' ) { error( q{Stuff went bad!} ); } }; if ( $@ =~ /Stuff went bad!/ ) { warning( q{Stuff went bad, but it's okay now!} ); }
You can change the default settings of Archlinux::Term by changing some package variables:
$Archlinux::Term::Columns Determines at which column word-wrapping occurs. However, if it is set to a false or negative value, it will turn off word-wrapping all-together.
$Archlinux::Term::Columns
If $Archlinux::Term::Mono is set to a true value then ANSI terminal colors are disabled.
$Archlinux::Term::Mono
use Archlinux::Term; sub mysub { # It's usually a good idea to use local for this stuff... local $Archlinux::Term::Columns = 144; local $Archlinux::Term::Mono = 1; status( 'Here is an uncolorful really long status message ... ' . 'no it's not over with yet! We wrap at 144 characters ' . 'so I have to keep typing.' ); }
Archlinux
http://www.archlinux.org
Git Repository
http://github.com/juster/perl-archlinux-term
Justin Davis <juster at cpan dot org>
<juster at cpan dot org>
Copyright 2011 Justin Davis, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Archlinux::Term, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Archlinux::Term
CPAN shell
perl -MCPAN -e shell install Archlinux::Term
For more information on module installation, please visit the detailed CPAN module installation guide.