1 # Pod::Text::Termcap -- Convert POD data to ASCII text with format escapes.
2 # $Id: Termcap.pm,v 1.1 2001/07/10 11:04:36 eagle Exp $
4 # Copyright 1999 by Russ Allbery <rra@stanford.edu>
6 # This program is free software; you may 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 methods to
10 # output the right termcap escape sequences for formatted text on the current
13 ##############################################################################
14 # Modules and declarations
15 ##############################################################################
17 package Pod::Text::Termcap;
26 use vars qw(@ISA $VERSION);
30 # Don't use the CVS revision as the version, since this module is also in Perl
31 # core and too many things could munge CVS magic revision strings. This
32 # number should ideally be the same as the CVS revision in podlators, however.
36 ##############################################################################
38 ##############################################################################
40 # In the initialization method, grab our terminal characteristics as well as
41 # do all the stuff we normally do.
45 # The default Term::Cap path won't work on Solaris.
46 $ENV{TERMPATH} = "$ENV{HOME}/.termcap:/etc/termcap"
47 . ":/usr/share/misc/termcap:/usr/share/lib/termcap";
49 my $termios = POSIX::Termios->new;
51 my $ospeed = $termios->getospeed;
52 my $term = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
53 $$self{BOLD} = $$term{_md} or die 'BOLD';
54 $$self{UNDL} = $$term{_us} or die 'UNDL';
55 $$self{NORM} = $$term{_me} or die 'NORM';
57 unless (defined $$self{width}) {
58 $$self{width} = $ENV{COLUMNS} || $$term{_co} || 78;
62 $self->SUPER::initialize;
65 # Make level one headings bold.
70 $self->SUPER::cmd_head1 ("$$self{BOLD}$_$$self{NORM}");
73 # Make level two headings bold.
78 $self->SUPER::cmd_head2 ("$$self{BOLD}$_$$self{NORM}");
81 # Fix up B<> and I<>. Note that we intentionally don't do F<>.
82 sub seq_b { my $self = shift; return "$$self{BOLD}$_[0]$$self{NORM}" }
83 sub seq_i { my $self = shift; return "$$self{UNDL}$_[0]$$self{NORM}" }
85 # Override the wrapping code to igore the special sequences.
90 my $spaces = ' ' x $$self{MARGIN};
91 my $width = $$self{width} - $$self{MARGIN};
92 my $code = "(?:\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E)";
93 while (length > $width) {
94 if (s/^((?:$code?[^\n]){0,$width})\s+//
95 || s/^((?:$code?[^\n]){$width})//) {
96 $output .= $spaces . $1 . "\n";
101 $output .= $spaces . $_;
102 $output =~ s/\s+$/\n\n/;
107 ##############################################################################
108 # Module return value and documentation
109 ##############################################################################
116 Pod::Text::Color - Convert POD data to ASCII text with format escapes
120 use Pod::Text::Termcap;
121 my $parser = Pod::Text::Termcap->new (sentence => 0, width => 78);
123 # Read POD from STDIN and write to STDOUT.
124 $parser->parse_from_filehandle;
126 # Read POD from file.pod and write to file.txt.
127 $parser->parse_from_file ('file.pod', 'file.txt');
131 Pod::Text::Termcap is a simple subclass of Pod::Text that highlights output
132 text using the correct termcap escape sequences for the current terminal.
133 Apart from the format codes, it in all ways functions like Pod::Text. See
134 L<Pod::Text> for details and available options.
138 L<Pod::Text|Pod::Text>, L<Pod::Parser|Pod::Parser>
142 Russ Allbery <rra@stanford.edu>.
144 =head1 COPYRIGHT AND LICENSE
146 Copyright 1999 by Russ Allbery <rra@stanford.edu>.
148 This program is free software; you may redistribute it and/or modify it
149 under the same terms as Perl itself.