summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Pod
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Pod')
-rw-r--r--Master/tlpkg/tlperl/lib/Pod/Man.pm45
-rw-r--r--Master/tlpkg/tlperl/lib/Pod/ParseLink.pm40
-rw-r--r--Master/tlpkg/tlperl/lib/Pod/Text.pm42
-rw-r--r--Master/tlpkg/tlperl/lib/Pod/Text/Color.pm99
-rw-r--r--Master/tlpkg/tlperl/lib/Pod/Text/Overstrike.pm50
-rw-r--r--Master/tlpkg/tlperl/lib/Pod/Text/Termcap.pm130
6 files changed, 250 insertions, 156 deletions
diff --git a/Master/tlpkg/tlperl/lib/Pod/Man.pm b/Master/tlpkg/tlperl/lib/Pod/Man.pm
index a737e5b3e94..6ebab1e0e5c 100644
--- a/Master/tlpkg/tlperl/lib/Pod/Man.pm
+++ b/Master/tlpkg/tlperl/lib/Pod/Man.pm
@@ -1,4 +1,4 @@
-# Pod::Man -- Convert POD data to formatted *roff input.
+# Convert POD data to formatted *roff input.
#
# This module translates POD documentation into *roff markup using the man
# macro set, and is intended for converting POD documents written as Unix
@@ -6,18 +6,7 @@
# a replacement for the pod2man command distributed with versions of Perl
# prior to 5.6.
#
-# Perl core hackers, please note that this module is also separately
-# maintained outside of the Perl core as part of the podlators. Please send
-# me any patches at the address above in addition to sending them to the
-# standard Perl mailing lists.
-#
-# Written by Russ Allbery <rra@cpan.org>
-# Substantial contributions by Sean Burke <sburke@cpan.org>
-# Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-# 2010, 2012, 2013, 2014, 2015, 2016, 2017 Russ Allbery <rra@cpan.org>
-#
-# This program is free software; you may redistribute it and/or modify it
-# under the same terms as Perl itself.
+# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
##############################################################################
# Modules and declarations
@@ -43,7 +32,7 @@ BEGIN {
@ISA = qw(Pod::Simple);
-$VERSION = '4.10';
+$VERSION = '4.11';
# Set the debugging level. If someone has inserted a debug function into this
# class already, use that. Otherwise, use any Pod::Simple debug function
@@ -140,6 +129,7 @@ sub new {
$self->no_errata_section (0);
$self->complain_stderr (0);
} elsif ($$self{errors} eq 'none') {
+ $self->no_errata_section (1);
$self->no_whining (1);
} else {
croak (qq(Invalid errors setting: "$$self{errors}"));
@@ -1651,9 +1641,9 @@ sub preamble_template {
__END__
=for stopwords
-en em ALLCAPS teeny fixedbold fixeditalic fixedbolditalic stderr utf8
-UTF-8 Allbery Sean Burke Ossanna Solaris formatters troff uppercased
-Christiansen nourls parsers Kernighan lquote rquote
+en em ALLCAPS teeny fixedbold fixeditalic fixedbolditalic stderr utf8 UTF-8
+Allbery Sean Burke Ossanna Solaris formatters troff uppercased Christiansen
+nourls parsers Kernighan lquote rquote
=head1 NAME
@@ -2014,16 +2004,17 @@ only matters for troff output.
=head1 AUTHOR
-Russ Allbery <rra@cpan.org>, based I<very> heavily on the original
-B<pod2man> by Tom Christiansen <tchrist@mox.perl.com>. The modifications to
-work with Pod::Simple instead of Pod::Parser were originally contributed by
-Sean Burke (but I've since hacked them beyond recognition and all bugs are
-mine).
+Russ Allbery <rra@cpan.org>, based I<very> heavily on the original B<pod2man>
+by Tom Christiansen <tchrist@mox.perl.com>. The modifications to work with
+Pod::Simple instead of Pod::Parser were originally contributed by Sean Burke
+<sburke@cpan.org> (but I've since hacked them beyond recognition and all bugs
+are mine).
=head1 COPYRIGHT AND LICENSE
-Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-2009, 2010, 2012, 2013, 2014, 2015, 2016, 2017 Russ Allbery <rra@cpan.org>
+Copyright 1999-2010, 2012-2018 Russ Allbery <rra@cpan.org>
+
+Substantial contributions by Sean Burke <sburke@cpan.org>.
This program is free software; you may redistribute it and/or modify it
under the same terms as Perl itself.
@@ -2044,7 +2035,11 @@ documentation on writing manual pages if you've not done it before and
aren't familiar with the conventions.
The current version of this module is always available from its web site at
-L<http://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
+L<https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
Perl core distribution as of 5.6.0.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/Master/tlpkg/tlperl/lib/Pod/ParseLink.pm b/Master/tlpkg/tlperl/lib/Pod/ParseLink.pm
index 9a1627079b4..0be5323973b 100644
--- a/Master/tlpkg/tlperl/lib/Pod/ParseLink.pm
+++ b/Master/tlpkg/tlperl/lib/Pod/ParseLink.pm
@@ -1,19 +1,11 @@
-# Pod::ParseLink -- Parse an L<> formatting code in POD text.
-#
-# Copyright 2001, 2008, 2009, 2014 by Russ Allbery <rra@cpan.org>
-#
-# This program is free software; you may redistribute it and/or modify it
-# under the same terms as Perl itself.
+# Parse an L<> formatting code in POD text.
#
# This module implements parsing of the text of an L<> formatting code as
# defined in perlpodspec. It should be suitable for any POD formatter. It
# exports only one function, parselink(), which returns the five-item parse
# defined in perlpodspec.
#
-# Perl core hackers, please note that this module is also separately
-# maintained outside of the Perl core as part of the podlators. Please send
-# me any patches at the address above in addition to sending them to the
-# standard Perl mailing lists.
+# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
##############################################################################
# Modules and declarations
@@ -31,7 +23,7 @@ use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(parselink);
-$VERSION = '4.10';
+$VERSION = '4.11';
##############################################################################
# Implementation
@@ -114,13 +106,13 @@ sub parselink {
1;
__END__
+=for stopwords
+markup Allbery URL
+
=head1 NAME
Pod::ParseLink - Parse an LE<lt>E<gt> formatting code in POD text
-=for stopwords
-markup Allbery URL
-
=head1 SYNOPSIS
use Pod::ParseLink;
@@ -173,22 +165,26 @@ the section may be necessary depending on whether the translator wants to
consider markup in sections to be significant when resolving links. See
L<perlpodspec> for more information.
-=head1 SEE ALSO
-
-L<Pod::Parser>
-
-The current version of this module is always available from its web site at
-L<http://www.eyrie.org/~eagle/software/podlators/>.
-
=head1 AUTHOR
Russ Allbery <rra@cpan.org>.
=head1 COPYRIGHT AND LICENSE
-Copyright 2001, 2008, 2009 Russ Allbery <rra@cpan.org>.
+Copyright 2001, 2008, 2009, 2014, 2018 Russ Allbery <rra@cpan.org>
This program is free software; you may redistribute it and/or modify it
under the same terms as Perl itself.
+=head1 SEE ALSO
+
+L<Pod::Parser>
+
+The current version of this module is always available from its web site at
+L<https://www.eyrie.org/~eagle/software/podlators/>.
+
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/Master/tlpkg/tlperl/lib/Pod/Text.pm b/Master/tlpkg/tlperl/lib/Pod/Text.pm
index f73b4af2b92..b05730ef476 100644
--- a/Master/tlpkg/tlperl/lib/Pod/Text.pm
+++ b/Master/tlpkg/tlperl/lib/Pod/Text.pm
@@ -6,16 +6,7 @@
# seemed to produce better output. It uses Pod::Parser and is designed to be
# very easy to subclass.
#
-# Perl core hackers, please note that this module is also separately
-# maintained outside of the Perl core as part of the podlators. Please send
-# me any patches at the address above in addition to sending them to the
-# standard Perl mailing lists.
-#
-# Copyright 1999, 2000, 2001, 2002, 2004, 2006, 2008, 2009, 2012, 2013, 2014,
-# 2015, 2016 Russ Allbery <rra@cpan.org>
-#
-# This program is free software; you may redistribute it and/or modify it
-# under the same terms as Perl itself.
+# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
##############################################################################
# Modules and declarations
@@ -39,7 +30,7 @@ use Pod::Simple ();
# We have to export pod2text for backward compatibility.
@EXPORT = qw(pod2text);
-$VERSION = '4.10';
+$VERSION = '4.11';
# Ensure that $Pod::Simple::nbsp and $Pod::Simple::shy are available. Code
# taken from Pod::Simple 3.32, but was only added in 3.30.
@@ -126,6 +117,7 @@ sub new {
$self->no_errata_section (0);
$self->complain_stderr (0);
} elsif ($$self{opt_errors} eq 'none') {
+ $self->no_errata_section (1);
$self->no_whining (1);
} else {
croak (qq(Invalid errors setting: "$$self{errors}"));
@@ -790,7 +782,7 @@ Pod::Text - Convert POD data to formatted text
=head1 SYNOPSIS
use Pod::Text;
- my $parser = Pod::Text->new (sentence => 0, width => 78);
+ my $parser = Pod::Text->new (sentence => 1, width => 78);
# Read POD from STDIN and write to STDOUT.
$parser->parse_from_filehandle;
@@ -888,7 +880,7 @@ marks are added around CE<lt>> text.
If set to a true value, Pod::Text will assume that each sentence ends in two
spaces, and will try to preserve that spacing. If set to false, all
consecutive whitespace in non-verbatim paragraphs is compressed into a
-single space. Defaults to true.
+single space. Defaults to false.
=item stderr
@@ -1004,14 +996,6 @@ sequences, although it wasn't turned on by default and it was problematic to
get it to work at all. This rewrite doesn't even try to do that, but a
subclass of it does. Look for L<Pod::Text::Termcap>.
-=head1 SEE ALSO
-
-L<Pod::Simple>, L<Pod::Text::Termcap>, L<perlpod(1)>, L<pod2text(1)>
-
-The current version of this module is always available from its web site at
-L<http://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
-Perl core distribution as of 5.6.0.
-
=head1 AUTHOR
Russ Allbery <rra@cpan.org>, based I<very> heavily on the original
@@ -1022,10 +1006,22 @@ how to use Pod::Simple.
=head1 COPYRIGHT AND LICENSE
-Copyright 1999, 2000, 2001, 2002, 2004, 2006, 2008, 2009, 2012, 2013, 2014,
-2015, 2016 Russ Allbery <rra@cpan.org>
+Copyright 1999-2002, 2004, 2006, 2008-2009, 2012-2016, 2018 Russ Allbery
+<rra@cpan.org>
This program is free software; you may redistribute it and/or modify it
under the same terms as Perl itself.
+=head1 SEE ALSO
+
+L<Pod::Simple>, L<Pod::Text::Termcap>, L<perlpod(1)>, L<pod2text(1)>
+
+The current version of this module is always available from its web site at
+L<https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
+Perl core distribution as of 5.6.0.
+
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/Master/tlpkg/tlperl/lib/Pod/Text/Color.pm b/Master/tlpkg/tlperl/lib/Pod/Text/Color.pm
index fa1aadb4633..8d956f2a5dd 100644
--- a/Master/tlpkg/tlperl/lib/Pod/Text/Color.pm
+++ b/Master/tlpkg/tlperl/lib/Pod/Text/Color.pm
@@ -1,14 +1,10 @@
-# Pod::Text::Color -- Convert POD data to formatted color ASCII text
+# Convert POD data to formatted color ASCII text
#
# This is just a basic proof of concept. It should later be modified to make
# better use of color, take options changing what colors are used for what
# text, and the like.
#
-# Copyright 1999, 2001, 2004, 2006, 2008, 2009, 2014
-# Russ Allbery <rra@cpan.org>
-#
-# This program is free software; you may redistribute it and/or modify it
-# under the same terms as Perl itself.
+# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
##############################################################################
# Modules and declarations
@@ -21,13 +17,13 @@ use strict;
use warnings;
use Pod::Text ();
-use Term::ANSIColor qw(colored);
+use Term::ANSIColor qw(color colored);
use vars qw(@ISA $VERSION);
@ISA = qw(Pod::Text);
-$VERSION = '4.10';
+$VERSION = '4.11';
##############################################################################
# Overrides
@@ -37,6 +33,7 @@ $VERSION = '4.10';
sub cmd_head1 {
my ($self, $attrs, $text) = @_;
$text =~ s/\s+$//;
+ local $Term::ANSIColor::EACHLINE = "\n";
$self->SUPER::cmd_head1 ($attrs, colored ($text, 'bold'));
}
@@ -52,9 +49,27 @@ sub cmd_b { return colored ($_[2], 'bold') }
sub cmd_f { return colored ($_[2], 'cyan') }
sub cmd_i { return colored ($_[2], 'yellow') }
+# Analyze a single line and return any formatting codes in effect at the end
+# of that line.
+sub end_format {
+ my ($self, $line) = @_;
+ my $reset = color ('reset');
+ my $current;
+ while ($line =~ /(\e\[[\d;]+m)/g) {
+ my $code = $1;
+ if ($code eq $reset) {
+ undef $current;
+ } else {
+ $current .= $code;
+ }
+ }
+ return $current;
+}
+
# Output any included code in green.
sub output_code {
my ($self, $code) = @_;
+ local $Term::ANSIColor::EACHLINE = "\n";
$code = colored ($code, 'green');
$self->output ($code);
}
@@ -77,19 +92,48 @@ sub wrap {
my $spaces = ' ' x $$self{MARGIN};
my $width = $$self{opt_width} - $$self{MARGIN};
- # We have to do $shortchar and $longchar in variables because the
+ # $codes matches a single special sequence. $char matches any number of
+ # special sequences preceding a single character other than a newline.
+ # $shortchar matches some sequence of $char ending in codes followed by
+ # whitespace or the end of the string. $longchar matches exactly $width
+ # $chars, used when we have to truncate and hard wrap.
+ #
+ # $shortchar and $longchar are created in a slightly odd way because the
# construct ${char}{0,$width} didn't do the right thing until Perl 5.8.x.
- my $char = '(?:(?:\e\[[\d;]+m)*[^\n])';
- my $shortchar = $char . "{0,$width}";
- my $longchar = $char . "{$width}";
+ my $code = '(?:\e\[[\d;]+m)';
+ my $char = "(?>$code*[^\\n])";
+ my $shortchar = '^(' . $char . "{0,$width}(?>$code*)" . ')(?:\s+|\z)';
+ my $longchar = '^(' . $char . "{$width})";
while (length > $width) {
- if (s/^($shortchar)\s+// || s/^($longchar)//) {
+ if (s/$shortchar// || s/$longchar//) {
$output .= $spaces . $1 . "\n";
} else {
last;
}
}
$output .= $spaces . $_;
+
+ # less -R always resets terminal attributes at the end of each line, so we
+ # need to clear attributes at the end of lines and then set them again at
+ # the start of the next line. This requires a second pass through the
+ # wrapped string, accumulating any attributes we see, remembering them,
+ # and then inserting the appropriate sequences at the newline.
+ if ($output =~ /\n/) {
+ my @lines = split (/\n/, $output);
+ my $start_format;
+ for my $line (@lines) {
+ if ($start_format && $line =~ /\S/) {
+ $line =~ s/^(\s*)(\S)/$1$start_format$2/;
+ }
+ $start_format = $self->end_format ($line);
+ if ($start_format) {
+ $line .= color ('reset');
+ }
+ }
+ $output = join ("\n", @lines);
+ }
+
+ # Fix up trailing whitespace and return the results.
$output =~ s/\s+$/\n\n/;
$output;
}
@@ -101,13 +145,13 @@ sub wrap {
1;
__END__
+=for stopwords
+Allbery
+
=head1 NAME
Pod::Text::Color - Convert POD data to formatted color ASCII text
-=for stopwords
-Allbery
-
=head1 SYNOPSIS
use Pod::Text::Color;
@@ -135,23 +179,28 @@ This is just a basic proof of concept. It should be seriously expanded to
support configurable coloration via options passed to the constructor, and
B<pod2text> should be taught about those.
-=head1 SEE ALSO
-
-L<Pod::Text>, L<Pod::Simple>
-
-The current version of this module is always available from its web site at
-L<http://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
-Perl core distribution as of 5.6.0.
-
=head1 AUTHOR
Russ Allbery <rra@cpan.org>.
=head1 COPYRIGHT AND LICENSE
-Copyright 1999, 2001, 2004, 2006, 2008, 2009 Russ Allbery <rra@cpan.org>.
+Copyright 1999, 2001, 2004, 2006, 2008, 2009, 2018 Russ Allbery
+<rra@cpan.org>
This program is free software; you may redistribute it and/or modify it
under the same terms as Perl itself.
+=head1 SEE ALSO
+
+L<Pod::Text>, L<Pod::Simple>
+
+The current version of this module is always available from its web site at
+L<https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
+Perl core distribution as of 5.6.0.
+
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/Master/tlpkg/tlperl/lib/Pod/Text/Overstrike.pm b/Master/tlpkg/tlperl/lib/Pod/Text/Overstrike.pm
index d0ce7680aa1..92a3a9330e0 100644
--- a/Master/tlpkg/tlperl/lib/Pod/Text/Overstrike.pm
+++ b/Master/tlpkg/tlperl/lib/Pod/Text/Overstrike.pm
@@ -1,4 +1,4 @@
-# Pod::Text::Overstrike -- Convert POD data to formatted overstrike text
+# Convert POD data to formatted overstrike text
#
# This was written because the output from:
#
@@ -11,13 +11,7 @@
# and because both Pod::Text::Color and Pod::Text::Termcap are not device
# independent.
#
-# Created by Joe Smith <Joe.Smith@inwap.com> 30-Nov-2000
-# (based on Pod::Text::Color by Russ Allbery <rra@cpan.org>)
-# Copyright 2000 Joe Smith <Joe.Smith@inwap.com>.
-# Copyright 2001, 2004, 2008, 2014 Russ Allbery <rra@cpan.org>.
-#
-# This program is free software; you may redistribute it and/or modify it
-# under the same terms as Perl itself.
+# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
##############################################################################
# Modules and declarations
@@ -35,7 +29,7 @@ use Pod::Text ();
@ISA = qw(Pod::Text);
-$VERSION = '4.10';
+$VERSION = '4.11';
##############################################################################
# Overrides
@@ -141,15 +135,12 @@ sub wrap {
1;
__END__
-=head1 NAME
-
=for stopwords
-overstrike
+overstrike overstruck Overstruck Allbery terminal's
-Pod::Text::Overstrike - Convert POD data to formatted overstrike text
+=head1 NAME
-=for stopwords
-overstruck Overstruck Allbery terminal's
+Pod::Text::Overstrike - Convert POD data to formatted overstrike text
=head1 SYNOPSIS
@@ -185,25 +176,30 @@ Currently, the outermost formatting instruction wins, so for example
underlined text inside a region of bold text is displayed as simply bold.
There may be some better approach possible.
-=head1 SEE ALSO
-
-L<Pod::Text>, L<Pod::Simple>
-
-The current version of this module is always available from its web site at
-L<http://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
-Perl core distribution as of 5.6.0.
-
=head1 AUTHOR
-Joe Smith <Joe.Smith@inwap.com>, using the framework created by Russ Allbery
-<rra@cpan.org>.
+Originally written by Joe Smith <Joe.Smith@inwap.com>, using the framework
+created by Russ Allbery <rra@cpan.org>. Subsequently updated by Russ Allbery.
=head1 COPYRIGHT AND LICENSE
-Copyright 2000 by Joe Smith <Joe.Smith@inwap.com>.
-Copyright 2001, 2004, 2008 by Russ Allbery <rra@cpan.org>.
+Copyright 2000 by Joe Smith <Joe.Smith@inwap.com>
+
+Copyright 2001, 2004, 2008, 2014, 2018 by Russ Allbery <rra@cpan.org>
This program is free software; you may redistribute it and/or modify it
under the same terms as Perl itself.
+=head1 SEE ALSO
+
+L<Pod::Text>, L<Pod::Simple>
+
+The current version of this module is always available from its web site at
+L<https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
+Perl core distribution as of 5.6.0.
+
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
diff --git a/Master/tlpkg/tlperl/lib/Pod/Text/Termcap.pm b/Master/tlpkg/tlperl/lib/Pod/Text/Termcap.pm
index f015cfce597..d36ba4f518a 100644
--- a/Master/tlpkg/tlperl/lib/Pod/Text/Termcap.pm
+++ b/Master/tlpkg/tlperl/lib/Pod/Text/Termcap.pm
@@ -1,14 +1,10 @@
-# Pod::Text::Termcap -- Convert POD data to ASCII text with format escapes.
+# Convert POD data to ASCII text with format escapes.
#
# This is a simple subclass of Pod::Text that overrides a few key methods to
# output the right termcap escape sequences for formatted text on the current
# terminal type.
#
-# Copyright 1999, 2001, 2002, 2004, 2006, 2008, 2009, 2014, 2015
-# Russ Allbery <rra@cpan.org>
-#
-# This program is free software; you may redistribute it and/or modify it
-# under the same terms as Perl itself.
+# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
##############################################################################
# Modules and declarations
@@ -28,7 +24,7 @@ use vars qw(@ISA $VERSION);
@ISA = qw(Pod::Text);
-$VERSION = '4.10';
+$VERSION = '4.11';
##############################################################################
# Overrides
@@ -37,9 +33,8 @@ $VERSION = '4.10';
# In the initialization method, grab our terminal characteristics as well as
# do all the stuff we normally do.
sub new {
- my ($self, @args) = @_;
+ my ($self, %args) = @_;
my ($ospeed, $term, $termios);
- $self = $self->SUPER::new (@args);
# $ENV{HOME} is usually not set on Windows. The default Term::Cap path
# may not work on Solaris.
@@ -59,17 +54,37 @@ sub new {
$ospeed = $termios->getospeed || 9600;
}
- # Fall back on the ANSI escape sequences if Term::Cap doesn't work.
- eval { $term = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed } };
- $$self{BOLD} = $$term{_md} || "\e[1m";
- $$self{UNDL} = $$term{_us} || "\e[4m";
- $$self{NORM} = $$term{_me} || "\e[m";
-
- unless (defined $$self{width}) {
- $$self{opt_width} = $ENV{COLUMNS} || $$term{_co} || 80;
- $$self{opt_width} -= 2;
+ # Get data from Term::Cap if possible.
+ my ($bold, $undl, $norm, $width);
+ eval {
+ my $term = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
+ $bold = $term->Tputs('md');
+ $undl = $term->Tputs('us');
+ $norm = $term->Tputs('me');
+ if (defined $$term{_co}) {
+ $width = $$term{_co};
+ $width =~ s/^\#//;
+ }
+ };
+
+ # Figure out the terminal width before calling the Pod::Text constructor,
+ # since it will otherwise force 76 characters. Pod::Text::Termcap has
+ # historically used 2 characters less than the width of the screen, while
+ # the other Pod::Text classes have used 76. This is weirdly inconsistent,
+ # but there's probably no good reason to change it now.
+ unless (defined $args{width}) {
+ $args{width} = $ENV{COLUMNS} || $width || 80;
+ $args{width} -= 2;
}
+ # Initialize Pod::Text.
+ $self = $self->SUPER::new (%args);
+
+ # Fall back on the ANSI escape sequences if Term::Cap doesn't work.
+ $$self{BOLD} = $bold || "\e[1m";
+ $$self{UNDL} = $undl || "\e[4m";
+ $$self{NORM} = $norm || "\e[m";
+
return $self;
}
@@ -91,6 +106,23 @@ sub cmd_head2 {
sub cmd_b { my $self = shift; return "$$self{BOLD}$_[1]$$self{NORM}" }
sub cmd_i { my $self = shift; return "$$self{UNDL}$_[1]$$self{NORM}" }
+# Analyze a single line and return any formatting codes in effect at the end
+# of that line.
+sub end_format {
+ my ($self, $line) = @_;
+ my $pattern = "(\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E)";
+ my $current;
+ while ($line =~ /$pattern/g) {
+ my $code = $1;
+ if ($code eq $$self{NORM}) {
+ undef $current;
+ } else {
+ $current .= $code;
+ }
+ }
+ return $current;
+}
+
# Output any included code in bold.
sub output_code {
my ($self, $code) = @_;
@@ -115,22 +147,48 @@ sub wrap {
my $spaces = ' ' x $$self{MARGIN};
my $width = $$self{opt_width} - $$self{MARGIN};
- # $codes matches a single special sequence. $char matches any number of
+ # $code matches a single special sequence. $char matches any number of
# special sequences preceding a single character other than a newline.
- # We have to do $shortchar and $longchar in variables because the
+ # $shortchar matches some sequence of $char ending in codes followed by
+ # whitespace or the end of the string. $longchar matches exactly $width
+ # $chars, used when we have to truncate and hard wrap.
+ #
+ # $shortchar and $longchar are created in a slightly odd way because the
# construct ${char}{0,$width} didn't do the right thing until Perl 5.8.x.
- my $codes = "(?:\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E)";
- my $char = "(?:$codes*[^\\n])";
- my $shortchar = $char . "{0,$width}";
- my $longchar = $char . "{$width}";
+ my $code = "(?:\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E)";
+ my $char = "(?>$code*[^\\n])";
+ my $shortchar = '^(' . $char . "{0,$width}(?>$code*)" . ')(?:\s+|\z)';
+ my $longchar = '^(' . $char . "{$width})";
while (length > $width) {
- if (s/^($shortchar)\s+// || s/^($longchar)//) {
+ if (s/$shortchar// || s/$longchar//) {
$output .= $spaces . $1 . "\n";
} else {
last;
}
}
$output .= $spaces . $_;
+
+ # less -R always resets terminal attributes at the end of each line, so we
+ # need to clear attributes at the end of lines and then set them again at
+ # the start of the next line. This requires a second pass through the
+ # wrapped string, accumulating any attributes we see, remembering them,
+ # and then inserting the appropriate sequences at the newline.
+ if ($output =~ /\n/) {
+ my @lines = split (/\n/, $output);
+ my $start_format;
+ for my $line (@lines) {
+ if ($start_format && $line =~ /\S/) {
+ $line =~ s/^(\s*)(\S)/$1$start_format$2/;
+ }
+ $start_format = $self->end_format ($line);
+ if ($start_format) {
+ $line .= $$self{NORM};
+ }
+ }
+ $output = join ("\n", @lines);
+ }
+
+ # Fix up trailing whitespace and return the results.
$output =~ s/\s+$/\n\n/;
return $output;
}
@@ -187,24 +245,28 @@ regard as ANSI X3.64 and ISO 6429, the escape codes also used by DEC VT100
terminals) if the bold, underline, and reset codes aren't set in the
termcap information.
-=head1 SEE ALSO
-
-L<Pod::Text>, L<Pod::Simple>, L<Term::Cap>
-
-The current version of this module is always available from its web site at
-L<http://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
-Perl core distribution as of 5.6.0.
-
=head1 AUTHOR
Russ Allbery <rra@cpan.org>.
=head1 COPYRIGHT AND LICENSE
-Copyright 1999, 2001, 2002, 2004, 2006, 2008, 2009, 2014, 2015 Russ Allbery
+Copyright 1999, 2001-2002, 2004, 2006, 2008-2009, 2014-2015, 2018 Russ Allbery
<rra@cpan.org>
This program is free software; you may redistribute it and/or modify it
under the same terms as Perl itself.
+=head1 SEE ALSO
+
+L<Pod::Text>, L<Pod::Simple>, L<Term::Cap>
+
+The current version of this module is always available from its web site at
+L<https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
+Perl core distribution as of 5.6.0.
+
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End: