1 # Pod::Text::Termcap -- Convert POD data to ASCII text with format escapes.
2 # $Id: Termcap.pm,v 0.1 1999/06/13 02:41:06 eagle Exp $
4 # Copyright 1999 by Russ Allbery <rra@stanford.edu>
6 # This program is free software; you can redistribute it and/or modify it
7 # under the same terms as Perl itself.
9 # This is a simple subclass of Pod::Text that overrides a few key
10 # methods to output the right termcap escape sequences for formatted text
11 # on the current terminal type.
13 ############################################################################
14 # Modules and declarations
15 ############################################################################
17 package Pod::Text::Termcap;
25 use vars qw(@ISA $VERSION);
29 # Use the CVS revision of this file as its version number.
30 ($VERSION = (split (' ', q$Revision: 0.1 $ ))[1]) =~ s/\.(\d)$/.0$1/;
33 ############################################################################
35 ############################################################################
37 # In the initialization method, grab our terminal characteristics as well as
38 # do all the stuff we normally do.
42 # The default Term::Cap path won't work on Solaris.
43 $ENV{TERMPATH} = "$ENV{HOME}/.termcap:/etc/termcap"
44 . ":/usr/share/misc/termcap:/usr/share/lib/termcap";
46 my $termios = POSIX::Termios->new;
48 my $ospeed = $termios->getospeed;
49 my $term = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
50 $$self{BOLD} = $$term{_md} or die 'BOLD';
51 $$self{UNDL} = $$term{_us} or die 'UNDL';
52 $$self{NORM} = $$term{_me} or die 'NORM';
54 unless (defined $$self{width}) {
55 $$self{width} = $ENV{COLUMNS} || $$term{_co} || 78;
59 $self->SUPER::initialize;
62 # Make level one headings bold.
67 $self->SUPER::cmd_head1 ("$$self{BOLD}$_$$self{NORM}");
70 # Make level two headings bold.
75 $self->SUPER::cmd_head2 ("$$self{BOLD}$_$$self{NORM}");
78 # Fix up B<> and I<>. Note that we intentionally don't do F<>.
79 sub seq_b { my $self = shift; return "$$self{BOLD}$_[0]$$self{NORM}" }
80 sub seq_i { my $self = shift; return "$$self{UNDL}$_[0]$$self{NORM}" }
82 # Override the wrapping code to igore the special sequences.
87 my $spaces = ' ' x $$self{MARGIN};
88 my $width = $$self{width} - $$self{MARGIN};
89 my $code = "(?:\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E)";
90 while (length > $width) {
91 if (s/^((?:$code?[^\n]){0,$width})\s+//
92 || s/^((?:$code?[^\n]){$width})//) {
93 $output .= $spaces . $1 . "\n";
98 $output .= $spaces . $_;
99 $output =~ s/\s+$/\n\n/;
104 ############################################################################
105 # Module return value and documentation
106 ############################################################################
113 Pod::Text::Color - Convert POD data to ASCII text with format escapes
117 use Pod::Text::Termcap;
118 my $parser = Pod::Text::Termcap->new (sentence => 0, width => 78);
120 # Read POD from STDIN and write to STDOUT.
121 $parser->parse_from_filehandle;
123 # Read POD from file.pod and write to file.txt.
124 $parser->parse_from_file ('file.pod', 'file.txt');
128 Pod::Text::Termcap is a simple subclass of Pod::Text that highlights
129 output text using the correct termcap escape sequences for the current
130 terminal. Apart from the format codes, it in all ways functions like
131 Pod::Text. See L<Pod::Text> for details and available options.
135 L<Pod::Text|Pod::Text>, L<Pod::Parser|Pod::Parser>
139 Russ Allbery E<lt>rra@stanford.eduE<gt>.