summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Pod/Text
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Pod/Text')
-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
3 files changed, 193 insertions, 86 deletions
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: