String::Tagged::Terminal - format terminal output using String::Tagged
String::Tagged::Terminal
String::Tagged
use String::Tagged::Terminal; my $st = String::Tagged::Terminal->new ->append( "Hello my name is " ) ->append_tagged( $name, bold => 1, fgindex => 4 ); print $st->build_terminal . "\n";
This subclass of String::Tagged provides a method, build_terminal, for outputting the formatting tags embedded in the string as terminal escape sequences, to render the the output in the appropriate style.
build_terminal
The following tag names are recognised:
These tags take a boolean value. If the value is true then the corresponding terminal rendering attribute is enabled.
This tag takes an integer value. If defined it uses the "alternate font selection" sequence.
These tags take an integer value in the range 0 to 255. These select the foreground or background colour by using VGA, high-brightness extended 16 colour, or xterm 256 palette mode attributes, depending on the value.
The ECMA-48-corrected string encoding form of CSI 38:5:nnn m is used to set the 256 palette values.
CSI 38:5:nnn m
$st = String::Tagged::Terminal->new_from_formatting( $fmt )
Returns a new instance by converting String::Tagged::Formatting standard tags.
Foreground and background colours are converted to their nearest index in the xterm 256 colour palette. The monospace Formatting attribute is rendered by selecting the first alternate font using altfont.
monospace
altfont
The following methods are provided in addition to those provided by String::Tagged.
$str = $st->build_terminal
Returns a string containing terminal escape sequences mixed with string content to render the string to a terminal.
As this string will contain literal terminal control escape sequences, care should be taken when passing it around, printing it for debugging purposes, or similar.
$fmt = $st->as_formatting
Returns a new String::Tagged instance tagged with String::Tagged::Formatting standard tags.
Consider a ->parse_terminal constructor method, which would attempt to parse SGR sequences from a given source string.
->parse_terminal
Paul Evans <leonerd@leonerd.org.uk>
To install String::Tagged::Terminal, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Tagged::Terminal
CPAN shell
perl -MCPAN -e shell install String::Tagged::Terminal
For more information on module installation, please visit the detailed CPAN module installation guide.