Commit | Line | Data |
6055f9d4 |
1 | # Pod::Text::Color -- Convert POD data to formatted color ASCII text |
2 | # $Id: Color.pm,v 0.1 1999/06/13 02:41:06 eagle Exp $ |
3 | # |
4 | # Copyright 1999 by Russ Allbery <rra@stanford.edu> |
5 | # |
6 | # This program is free software; you can redistribute it and/or modify it |
7 | # under the same terms as Perl itself. |
8 | # |
9 | # This is just a basic proof of concept. It should later be modified to |
10 | # make better use of color, take options changing what colors are used for |
11 | # what text, and the like. |
12 | |
13 | ############################################################################ |
14 | # Modules and declarations |
15 | ############################################################################ |
16 | |
17 | package Pod::Text::Color; |
18 | |
19 | require 5.004; |
20 | |
21 | use Pod::Text (); |
22 | use Term::ANSIColor qw(colored); |
23 | |
24 | use strict; |
25 | use vars qw(@ISA $VERSION); |
26 | |
27 | @ISA = qw(Pod::Text); |
28 | |
29 | # Use the CVS revision of this file as its version number. |
30 | ($VERSION = (split (' ', q$Revision: 0.1 $ ))[1]) =~ s/\.(\d)$/.0$1/; |
31 | |
32 | |
33 | ############################################################################ |
34 | # Overrides |
35 | ############################################################################ |
36 | |
37 | # Make level one headings bold. |
38 | sub cmd_head1 { |
39 | my $self = shift; |
40 | local $_ = shift; |
41 | s/\s+$//; |
42 | $self->SUPER::cmd_head1 (colored ($_, 'bold')); |
43 | } |
44 | |
45 | # Make level two headings bold. |
46 | sub cmd_head2 { |
47 | my $self = shift; |
48 | local $_ = shift; |
49 | s/\s+$//; |
50 | $self->SUPER::cmd_head2 (colored ($_, 'bold')); |
51 | } |
52 | |
53 | # Fix the various interior sequences. |
54 | sub seq_b { return colored ($_[1], 'bold') } |
55 | sub seq_f { return colored ($_[1], 'cyan') } |
56 | sub seq_i { return colored ($_[1], 'yellow') } |
57 | |
58 | # We unfortunately have to override the wrapping code here, since the normal |
59 | # wrapping code gets really confused by all the escape sequences. |
60 | sub wrap { |
61 | my $self = shift; |
62 | local $_ = shift; |
63 | my $output = ''; |
64 | my $spaces = ' ' x $$self{MARGIN}; |
65 | my $width = $$self{width} - $$self{MARGIN}; |
66 | while (length > $width) { |
67 | if (s/^((?:(?:\e\[[\d;]+m)?[^\n]){0,$width})\s+// |
68 | || s/^((?:(?:\e\[[\d;]+m)?[^\n]){$width})//) { |
69 | $output .= $spaces . $1 . "\n"; |
70 | } else { |
71 | last; |
72 | } |
73 | } |
74 | $output .= $spaces . $_; |
75 | $output =~ s/\s+$/\n\n/; |
76 | $output; |
77 | } |
78 | |
79 | ############################################################################ |
80 | # Module return value and documentation |
81 | ############################################################################ |
82 | |
83 | 1; |
84 | __END__ |
85 | |
86 | =head1 NAME |
87 | |
88 | Pod::Text::Color - Convert POD data to formatted color ASCII text |
89 | |
90 | =head1 SYNOPSIS |
91 | |
92 | use Pod::Text::Color; |
93 | my $parser = Pod::Text::Color->new (sentence => 0, width => 78); |
94 | |
95 | # Read POD from STDIN and write to STDOUT. |
96 | $parser->parse_from_filehandle; |
97 | |
98 | # Read POD from file.pod and write to file.txt. |
99 | $parser->parse_from_file ('file.pod', 'file.txt'); |
100 | |
101 | =head1 DESCRIPTION |
102 | |
103 | Pod::Text::Color is a simple subclass of Pod::Text that highlights |
104 | output text using ANSI color escape sequences. Apart from the color, it in |
105 | all ways functions like Pod::Text. See L<Pod::Text> for details |
106 | and available options. |
107 | |
108 | =head1 SEE ALSO |
109 | |
110 | L<Pod::Text|Pod::Text>, L<Pod::Parser|Pod::Parser> |
111 | |
112 | =head1 AUTHOR |
113 | |
114 | Russ Allbery E<lt>rra@stanford.eduE<gt>. |
115 | |
116 | =cut |