File Coverage

blib/lib/HTML/FromANSI.pm
Criterion Covered Total %
statement 92 100 92.0
branch 22 36 61.1
condition 19 35 54.2
subroutine 19 19 100.0
pod 5 9 55.5
total 157 199 78.8


, or simply truncate them. Defaults to C<1>.
line stmt bran cond sub pod time code
1             package HTML::FromANSI;
2             $HTML::FromANSI::VERSION = '2.03';
3              
4 3     3   68144 use strict;
  3         6  
  3         93  
5 3     3   14 use base qw/Exporter/;
  3         6  
  3         325  
6 3     3   43 use vars qw/@EXPORT @EXPORT_OK @Color %Options/;
  3         15  
  3         256  
7 3     3   2080 use Term::VT102::Boundless;
  3         44031  
  3         190  
8 3     3   3037 use HTML::Entities;
  3         19057  
  3         358  
9 3     3   31 use Scalar::Util qw(blessed reftype);
  3         5  
  3         369  
10 3     3   17 use Carp qw(croak);
  3         5  
  3         4827  
11              
12             =head1 NAME
13              
14             HTML::FromANSI - Mark up ANSI sequences as HTML
15              
16             =head1 SYNOPSIS
17              
18             use HTML::FromANSI (); # avoid exports if using OO
19             use Term::ANSIColor;
20              
21             my $h = HTML::FromANSI->new(
22             fill_cols => 1,
23             );
24              
25              
26             $h->add_text(color('bold blue'), "This text is bold blue.");
27              
28             print $h->html;
29              
30              
31             # you can append text in the new api:
32              
33             $h->add_text(color('bold blue'), " still blue.");
34              
35             print $h->html
36              
37              
38              
39             # The old API still works:
40              
41             $HTML::FromANSI::Options{fill_cols} = 1; # fill all 80 cols
42             print ansi2html(color('bold blue'), "This text is bold blue.");
43              
44             =head1 DESCRIPTION
45              
46             This small module converts ANSI text sequences to corresponding HTML
47             codes, using stylesheets to control color and blinking properties.
48              
49             It exports C by default, which takes an array, joins it
50             it into a single scalar, and returns its HTML rendering.
51              
52             From version 2.00 an object oriented api which is safer for multiple uses (no
53             more manipulation of shared C<%Options>) is available. It is reccomended that
54             you no longer import any functions by doing:
55              
56             use HTML::FromANSI ();
57              
58             and use the new documented API instead of the functional one.
59              
60             The underlying ANSI code processing is done by L, a DEC VT102
61             terminal emulator. To generate ANSI codes for color changes, cursor movements
62             etc, take a look at L and L.
63              
64             =head1 METHODS
65              
66             =over 4
67              
68             =item new
69              
70             The constructor. See L for the options it takes.
71              
72             =item add_text @text
73              
74             Adds text input to the terminal emulator.
75              
76             =item html
77              
78             Renders the screen as computed by C into HTML.
79              
80             =item ansi_to_html @text
81              
82             A convenience method.
83              
84             Calls C and then C.
85              
86             =item terminal_object
87              
88             The underlying terminal emulator object.
89              
90             =back
91              
92             =head1 OPTIONS
93              
94             These are parameters you can pass to C.
95              
96             =over 4
97              
98             =item linewrap
99              
100             A boolean value to specify whether to wrap lines that exceeds
101             width specified by C
102              
103             Only takes effect if you override C or C with
104             a L (instead of L).
105              
106             =item lf_to_crlf
107              
108             A boolean value to specify whether to translate all incoming
109             \n into C<\r\n> or not; you generally wants to use this if your
110             data is from a file using unix line endings. The default is C<0>
111             on MSWin32 and MacOS, and C<1> on other platforms.
112              
113             =item fill_cols
114              
115             A boolean value to specify whether to fill empty columns with
116             space; use this if you want to maintain a I appearance
117             in the resulting HTML, so that each row will be aligned properly.
118             Defaults to C<0>.
119              
120             =item html_entity
121              
122             A boolean value to specify whether to escape all high-bit characters
123             to HTML entities or not; defaults to C<0>, which means only C>,
124             C>, C<"> and C<&> will be escaped. (Handy when processing most
125             ANSI art entries.)
126              
127             =item cols
128              
129             A number specifying the width of the virtual terminal; defaults to 80.
130              
131             When C is in use (the default) this specifies the
132             minimum number of rows to draw.
133              
134             When using C (by overriding C or
135             C) then the number of columns is fixed.
136              
137             =item rows
138              
139             When C is in use (the default) this specifies the
140             minimum number of rows to draw.
141              
142             When L is in use (by overriding C or
143             L) then it sets the height of the virtual terminal; rows that
144             exceeds this number will be truncated.
145              
146             =item font_face
147              
148             A string used as the C attribute to the C tag enclosing the
149             HTML text; defaults to C.
150              
151             If this option and the C