|
NAMEHTML::FromANSI::Tiny - Easily convert colored command line output to HTMLVERSIONversion 0.105SYNOPSISuse HTML::FromANSI::Tiny; my $h = HTML::FromANSI::Tiny->new( auto_reverse => 1, background => 'white', foreground => 'black', ); # output from some command my $output = "\e[31mfoo\033[1;32mbar\033[0m"; # include the default styles if you don't want to define your own: print $h->style_tag(); # or just $h->css() to insert into your own stylesheet print $h->html($output); # prints '<span class="red">foo</span><span class="bold green">bar</span>' DESCRIPTIONConvert the output from a terminal command that is decorated with ANSI escape sequences into customizable HTML (with a small amount of code).This module complements Parse::ANSIColor::Tiny by providing a simple HTML markup around its output. Parse::ANSIColor::Tiny returns a data structure that's easy to reformat into any desired output. Reformatting to HTML seemed simple and common enough to warrant this module as well. METHODSnewConstructor.Takes a hash or hash ref of options:
For convenience and consistency options to "new" in Parse::ANSIColor::Tiny can be specified directly including "auto_reverse", "background", "foreground", and "remove_escapes". ansi_parserReturns the Parse::ANSIColor::Tiny instance in use. Creates one if necessary.cssmy $css = $hfat->css(); Returns basic CSS code for inclusion into a "<style>" tag. You can use this if you don't want to style everything yourself or if you want something to start with. It produces code like this: .bold { font-weight: bold; } .red { color: #f33; } It will include the "class_prefix" and/or "selector_prefix" if you've set either: # with {class_prefix => 'term-'} .term-bold { font-weight: bold; } # with {selector_prefix => '#output '} #output .bold { font-weight: bold; } # with {selector_prefix => '#output ', class_prefix => 'term-'} #output .term-bold { font-weight: bold; } Returns a list of styles or a concatenated string depending on context. I tried to choose default colors that are close to traditional terminal colors but also fairly legible on black or white. Overwrite style to taste. Note: There is no default style for "reverse" as CSS does not provide a simple mechanism for this. I suggest you use "auto_reverse" and set "background" and "foreground" to appropriate colors if you expect to process "reverse" sequences. See "process_reverse" in Parse::ANSIColor::Tiny for more information. htmlmy $html = $hfat->html($text); my @html_tags = $hfat->html($text); Wraps the provided $text in HTML using "tag" for the HTML tag name and prefixing each attribute with "class_prefix". For example: # defaults: qq[<span class="red bold">foo</span>] # {tag => 'bar', class_prefix => 'baz-'} qq[<bar class="baz-red baz-bold">foo</bar>] $text may be a string marked with ANSI escape sequences or the array ref output of Parse::ANSIColor::Tiny if you already have that. In list context returns a list of HTML tags. In scalar context returns a single string of concatenated HTML. html_encodemy $html = $hfat->html_encode($text); Encodes the text with HTML character entities. so it can be inserted into HTML tags. This is used internally by "html" to encode the contents of each tag. By default the "encode_entities" function of HTML::Entities is used. You may provide an alternate subroutine (code ref) to the constructor as the "html_encode" parameter in which case that sub will be used instead. This allows you to set different options or use the HTML entity encoder provided by your framework: my $hfat = HTML::FromANSI::Tiny->new(html_encode => sub { $app->h(shift) }); The code ref provided should take the first argument as the text to process and return the encoded result. style_tagReturns the output of "css" wrapped in a "<style>" tag.Returns a list or a concatenated string depending on context. FUNCTIONShtml_from_ansiFunction wrapped around "html".EXPORTSEverything listed in "FUNCTIONS" is also available for export upon request.CUSTOM STYLESTo override the styles output in the "style_tag" or "css" methods (or the attributes when "inline_style" is used) pass to the constructor a tree of hashrefs as the "styles" attribute:styles => { underline => { 'text-decoration' => 'underline', 'text-shadow' => '0 2px 2px black', }, red => { 'color' => '#f00' }, on_bright_green => { 'background-color' => '#060', } } Any styles that are not overridden will get the defaults. COMPARISON TO HTML::FromANSIHTML::FromANSI is a bit antiquated (as of v2.03 released in 2007). It uses "font" tags and the "style" attribute and isn't very customizable.It uses Term::VT102 which is probably more robust than Parse::ANSIColor::Tiny but may be overkill for simple situations. I've also had trouble installing it in the past. For many simple situations this module combined with Parse::ANSIColor::Tiny is likely sufficient and is considerably smaller. SEE ALSO
SUPPORTPerldocYou can find documentation for this module with the perldoc command.perldoc HTML::FromANSI::Tiny WebsitesThe following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.
Bugs / Feature RequestsPlease report any bugs or feature requests by email to "bug-html-fromansi-tiny at rt.cpan.org", or through the web interface at <https://rt.cpan.org/Public/Bug/Report.html?Queue=HTML-FromANSI-Tiny>. You will be automatically notified of any progress on the request by the system.Source Code<https://github.com/rwstauner/HTML-FromANSI-Tiny>git clone https://github.com/rwstauner/HTML-FromANSI-Tiny.git AUTHORRandy Stauner <rwstauner@cpan.org>CONTRIBUTORStephen Thirlwall <sdt@cpan.org>COPYRIGHT AND LICENSEThis software is copyright (c) 2011 by Randy Stauner.This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Visit the GSP FreeBSD Man Page Interface. |