summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Term
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Term')
-rw-r--r--Master/tlpkg/tlperl/lib/Term/ANSIColor.pm262
-rw-r--r--Master/tlpkg/tlperl/lib/Term/ReadLine.pm27
-rw-r--r--Master/tlpkg/tlperl/lib/Term/UI.pm12
3 files changed, 201 insertions, 100 deletions
diff --git a/Master/tlpkg/tlperl/lib/Term/ANSIColor.pm b/Master/tlpkg/tlperl/lib/Term/ANSIColor.pm
index 1ee7a1ef7ad..72b941f6211 100644
--- a/Master/tlpkg/tlperl/lib/Term/ANSIColor.pm
+++ b/Master/tlpkg/tlperl/lib/Term/ANSIColor.pm
@@ -1,6 +1,6 @@
# Term::ANSIColor -- Color screen output using ANSI escape sequences.
#
-# Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006, 2008, 2009
+# Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006, 2008, 2009, 2010
# Russ Allbery <rra@stanford.edu> and Zenin
# PUSH/POP support submitted 2007 by openmethods.com voice solutions
#
@@ -17,7 +17,7 @@
package Term::ANSIColor;
require 5.001;
-$VERSION = '2.02';
+$VERSION = '3.00';
use strict;
use vars qw($AUTOLOAD $AUTOLOCAL $AUTORESET @COLORLIST @COLORSTACK $EACHLINE
@@ -26,10 +26,21 @@ use vars qw($AUTOLOAD $AUTOLOCAL $AUTORESET @COLORLIST @COLORSTACK $EACHLINE
use Exporter ();
BEGIN {
- @COLORLIST = qw(CLEAR RESET BOLD DARK FAINT UNDERLINE UNDERSCORE BLINK
- REVERSE CONCEALED BLACK RED GREEN YELLOW BLUE MAGENTA
- CYAN WHITE ON_BLACK ON_RED ON_GREEN ON_YELLOW ON_BLUE
- ON_MAGENTA ON_CYAN ON_WHITE);
+ @COLORLIST = qw(
+ CLEAR RESET BOLD DARK
+ FAINT UNDERLINE UNDERSCORE BLINK
+ REVERSE CONCEALED
+
+ BLACK RED GREEN YELLOW
+ BLUE MAGENTA CYAN WHITE
+ ON_BLACK ON_RED ON_GREEN ON_YELLOW
+ ON_BLUE ON_MAGENTA ON_CYAN ON_WHITE
+
+ BRIGHT_BLACK BRIGHT_RED BRIGHT_GREEN BRIGHT_YELLOW
+ BRIGHT_BLUE BRIGHT_MAGENTA BRIGHT_CYAN BRIGHT_WHITE
+ ON_BRIGHT_BLACK ON_BRIGHT_RED ON_BRIGHT_GREEN ON_BRIGHT_YELLOW
+ ON_BRIGHT_BLUE ON_BRIGHT_MAGENTA ON_BRIGHT_CYAN ON_BRIGHT_WHITE
+ );
@ISA = qw(Exporter);
@EXPORT = qw(color colored);
@EXPORT_OK = qw(uncolor colorstrip colorvalid);
@@ -43,25 +54,35 @@ BEGIN {
# Internal data structures
##############################################################################
-%ATTRIBUTES = ('clear' => 0,
- 'reset' => 0,
- 'bold' => 1,
- 'dark' => 2,
- 'faint' => 2,
- 'underline' => 4,
- 'underscore' => 4,
- 'blink' => 5,
- 'reverse' => 7,
- 'concealed' => 8,
-
- 'black' => 30, 'on_black' => 40,
- 'red' => 31, 'on_red' => 41,
- 'green' => 32, 'on_green' => 42,
- 'yellow' => 33, 'on_yellow' => 43,
- 'blue' => 34, 'on_blue' => 44,
- 'magenta' => 35, 'on_magenta' => 45,
- 'cyan' => 36, 'on_cyan' => 46,
- 'white' => 37, 'on_white' => 47);
+%ATTRIBUTES = ('clear' => 0,
+ 'reset' => 0,
+ 'bold' => 1,
+ 'dark' => 2,
+ 'faint' => 2,
+ 'underline' => 4,
+ 'underscore' => 4,
+ 'blink' => 5,
+ 'reverse' => 7,
+ 'concealed' => 8,
+
+ 'black' => 30, 'on_black' => 40,
+ 'red' => 31, 'on_red' => 41,
+ 'green' => 32, 'on_green' => 42,
+ 'yellow' => 33, 'on_yellow' => 43,
+ 'blue' => 34, 'on_blue' => 44,
+ 'magenta' => 35, 'on_magenta' => 45,
+ 'cyan' => 36, 'on_cyan' => 46,
+ 'white' => 37, 'on_white' => 47,
+
+ 'bright_black' => 90, 'on_bright_black' => 100,
+ 'bright_red' => 91, 'on_bright_red' => 101,
+ 'bright_green' => 92, 'on_bright_green' => 102,
+ 'bright_yellow' => 93, 'on_bright_yellow' => 103,
+ 'bright_blue' => 94, 'on_bright_blue' => 104,
+ 'bright_magenta' => 95, 'on_bright_magenta' => 105,
+ 'bright_cyan' => 96, 'on_bright_cyan' => 106,
+ 'bright_white' => 97, 'on_bright_white' => 107,
+ );
# Reverse lookup. Alphabetically first name for a sequence is preferred.
for (reverse sort keys %ATTRIBUTES) {
@@ -184,13 +205,13 @@ sub uncolor {
push (@nums, split (/;/, $1));
}
for (@nums) {
- $_ += 0; # Strip leading zeroes
- my $name = $ATTRIBUTES_R{$_};
- if (!defined $name) {
- require Carp;
- Carp::croak ("No name for escape sequence $_" );
- }
- push (@result, $name);
+ $_ += 0; # Strip leading zeroes
+ my $name = $ATTRIBUTES_R{$_};
+ if (!defined $name) {
+ require Carp;
+ Carp::croak ("No name for escape sequence $_" );
+ }
+ push (@result, $name);
}
return @result;
}
@@ -263,6 +284,7 @@ Term::ANSIColor - Color screen output using ANSI escape sequences
cyan colorize namespace runtime TMTOWTDI cmd.exe 4nt.exe command.com NT
ESC Delvare SSH OpenSSH aixterm ECMA-048 Fraktur overlining Zenin
reimplemented Allbery PUSHCOLOR POPCOLOR LOCALCOLOR openmethods.com
+grey ATTR
=head1 SYNOPSIS
@@ -273,7 +295,9 @@ reimplemented Allbery PUSHCOLOR POPCOLOR LOCALCOLOR openmethods.com
print "This text is normal.\n";
print colored ("Yellow on magenta.", 'yellow on_magenta'), "\n";
print "This text is normal.\n";
- print colored ['yellow on_magenta'], 'Yellow on magenta.';
+ print colored ['yellow on_magenta'], 'Yellow on magenta.', "\n";
+ print colored ['red on_bright_yellow'] 'Red on bright yellow.', "\n";
+ print colored ['bright_red on_black], 'Bright red on black.', "\n";
print "\n";
use Term::ANSIColor qw(uncolor);
@@ -298,8 +322,8 @@ reimplemented Allbery PUSHCOLOR POPCOLOR LOCALCOLOR openmethods.com
use Term::ANSIColor qw(:pushpop);
print PUSHCOLOR RED ON_GREEN "This text is red on green.\n";
- print PUSHCOLOR BLUE "This text is blue on green.\n";
- print RESET BLUE "This text is just blue.\n";
+ print PUSHCOLOR BRIGHT_BLUE "This text is bright blue on green.\n";
+ print RESET BRIGHT_BLUE "This text is just bright blue.\n";
print POPCOLOR "Back to red on green.\n";
print LOCALCOLOR GREEN ON_BLUE "This text is green on blue.\n";
print "This text is red on green.\n";
@@ -317,46 +341,105 @@ other through constants. It also offers the utility functions uncolor(),
colorstrip(), and colorvalid(), which have to be explicitly imported to be
used (see L</SYNOPSIS>).
+=head2 Supported Colors
+
+Terminal emulators that support color divide into two types: ones that
+support only eight colors, and ones that support sixteen. This module
+provides both the ANSI escape codes for the "normal" colors, supported by
+both types, as well as the additional colors supported by sixteen-color
+emulators. These colors are referred to as ANSI colors 0 through 7
+(normal) and 8 through 15.
+
+Unfortunately, interpretation of colors 0 through 7 often depends on
+whether the emulator supports eight colors or sixteen colors. Emulators
+that only support eight colors (such as the Linux console) will display
+colors 0 through 7 with normal brightness and ignore colors 8 through 15,
+treating them the same as white. Emulators that support 16 colors, such
+as gnome-terminal, normally display colors 0 through 7 as dim or darker
+versions and colors 8 through 15 as normal brightness. On such emulators,
+the "normal" white (color 7) usually is shown as pale grey, requiring
+bright white (15) to be used to get a real white color. Bright black
+usually is a dark grey color, although some terminals display it as pure
+black. Some sixteen-color terminal emulators also treat normal yellow
+(color 3) as orange or brown, and bright yellow (color 11) as yellow.
+
+Following the normal convention of sixteen-color emulators, this module
+provides a pair of attributes for each color. For every normal color (0
+through 7), the corresponding bright color (8 through 15) is obtained by
+prepending the string C<bright_> to the normal color name. For example,
+C<red> is color 1 and C<bright_red> is color 9. The same applies for
+background colors: C<on_red> is the normal color and C<on_bright_red> is
+the bright color. Capitalize these strings for the constant interface.
+
+There is unfortunately no way to know whether the current emulator
+supports sixteen colors or not, which makes the choice of colors
+difficult. The most conservative choice is to use only the regular
+colors, which are at least displayed on all emulators. However, they will
+appear dark in sixteen-color terminal emulators, including most common
+emulators in UNIX X environments. If you know the display is one of those
+emulators, you may wish to use the bright variants instead. Even better,
+offer the user a way to configure the colors for a given application to
+fit their terminal emulator.
+
+Support for colors 8 through 15 (the C<bright_> variants) was added in
+Term::ANSIColor 3.0.
+
=head2 Function Interface
-color() takes any number of strings as arguments and considers them to be
-space-separated lists of attributes. It then forms and returns the escape
-sequence to set those attributes. It doesn't print it out, just returns
-it, so you'll have to print it yourself if you want to (this is so that
-you can save it as a string, pass it to something else, send it to a file
-handle, or do anything else with it that you might care to). color()
-throws an exception if given an invalid attribute, so you can also use it
-to check attribute names for validity (see L</EXAMPLES>).
+The function interface uses attribute strings to describe the colors and
+text attributes to assign to text. The recognized non-color attributes
+are clear, reset, bold, dark, faint, underline, underscore, blink,
+reverse, and concealed. Clear and reset (reset to default attributes),
+dark and faint (dim and saturated), and underline and underscore are
+equivalent, so use whichever is the most intuitive to you.
-uncolor() performs the opposite translation, turning escape sequences
-into a list of strings.
+Note that not all attributes are supported by all terminal types, and some
+terminals may not support any of these sequences. Dark and faint, blink,
+and concealed in particular are frequently not implemented.
-colorstrip() removes all color escape sequences from the provided strings,
-returning the modified strings separately in array context or joined
-together in scalar context. Its arguments are not modified.
+The recognized normal foreground color attributes (colors 0 to 7) are:
-colorvalid() takes attribute strings the same as color() and returns true
-if all attributes are known and false otherwise.
+ black red green yellow blue magenta cyan white
-The recognized non-color attributes are clear, reset, bold, dark, faint,
-underline, underscore, blink, reverse, and concealed. Clear and reset
-(reset to default attributes), dark and faint (dim and saturated), and
-underline and underscore are equivalent, so use whichever is the most
-intuitive to you. The recognized foreground color attributes are black,
-red, green, yellow, blue, magenta, cyan, and white. The recognized
-background color attributes are on_black, on_red, on_green, on_yellow,
-on_blue, on_magenta, on_cyan, and on_white. Case is not significant.
+The corresponding bright foreground color attributes (colors 8 to 15) are:
-Note that not all attributes are supported by all terminal types, and some
-terminals may not support any of these sequences. Dark and faint, blink,
-and concealed in particular are frequently not implemented.
+ bright_black bright_red bright_green bright_yellow
+ bright_blue bright_magenta bright_cyan bright_white
+
+The recognized normal background color attributes (colors 0 to 7) are:
-Attributes, once set, last until they are unset (by sending the attribute
+ on_black on_red on_green on yellow
+ on_blue on_magenta on_cyan on_white
+
+The recognized bright background color attributes (colors 8 to 15) are:
+
+ on_bright_black on_bright_red on_bright_green on_bright_yellow
+ on_bright_blue on_bright_magenta on_bright_cyan on_bright_white
+
+For any of the above listed attributes, case is not significant.
+
+Attributes, once set, last until they are unset (by printing the attribute
C<clear> or C<reset>). Be careful to do this, or otherwise your attribute
will last after your script is done running, and people get very annoyed
at having their prompt and typing changed to weird colors.
-As an aid to help with this, colored() takes a scalar as the first
+=over 4
+
+=item color(ATTR[, ATTR ...])
+
+color() takes any number of strings as arguments and considers them to be
+space-separated lists of attributes. It then forms and returns the escape
+sequence to set those attributes. It doesn't print it out, just returns
+it, so you'll have to print it yourself if you want to. This is so that
+you can save it as a string, pass it to something else, send it to a file
+handle, or do anything else with it that you might care to. color()
+throws an exception if given an invalid attribute.
+
+=item colored(STRING, ATTRIBUTES)
+
+=item colored(ATTR-REF, STRING[, STRING...])
+
+As an aid in resetting colors, colored() takes a scalar as the first
argument and any number of attribute strings as the second argument and
returns the scalar wrapped in escape codes so that the attributes will be
set as requested before the string and reset to normal after the string.
@@ -375,14 +458,46 @@ default background color for the next line. Programs like pagers can also
be confused by attributes that span lines. Normally you'll want to set
$Term::ANSIColor::EACHLINE to C<"\n"> to use this feature.
+=item uncolor(ESCAPE)
+
+uncolor() performs the opposite translation as color(), turning escape
+sequences into a list of strings corresponding to the attributes being set
+by those sequences.
+
+=item colorstrip(STRING[, STRING ...])
+
+colorstrip() removes all color escape sequences from the provided strings,
+returning the modified strings separately in array context or joined
+together in scalar context. Its arguments are not modified.
+
+=item colorvalid(ATTR[, ATTR ...])
+
+colorvalid() takes attribute strings the same as color() and returns true
+if all attributes are known and false otherwise.
+
+=back
+
=head2 Constant Interface
-Alternately, if you import C<:constants>, you can use the constants CLEAR,
-RESET, BOLD, DARK, FAINT, UNDERLINE, UNDERSCORE, BLINK, REVERSE,
-CONCEALED, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE,
-ON_BLACK, ON_RED, ON_GREEN, ON_YELLOW, ON_BLUE, ON_MAGENTA, ON_CYAN, and
-ON_WHITE directly. These are the same as color('attribute') and can be
-used if you prefer typing:
+Alternately, if you import C<:constants>, you can use the following
+constants directly:
+
+ CLEAR RESET BOLD DARK
+ FAINT UNDERLINE UNDERSCORE BLINK
+ REVERSE CONCEALED
+
+ BLACK RED GREEN YELLOW
+ BLUE MAGENTA CYAN WHITE
+ BRIGHT_BLACK BRIGHT_RED BRIGHT_GREEN BRIGHT_YELLOW
+ BRIGHT_BLUE BRIGHT_MAGENTA BRIGHT_CYAN BRIGHT_WHITE
+
+ ON_BLACK ON_RED ON_GREEN ON_YELLOW
+ ON_BLUE ON_MAGENTA ON_CYAN ON_WHITE
+ ON_BRIGHT_BLACK ON_BRIGHT_RED ON_BRIGHT_GREEN ON_BRIGHT_YELLOW
+ ON_BRIGHT_BLUE ON_BRIGHT_MAGENTA ON_BRIGHT_CYAN ON_BRIGHT_WHITE
+
+These are the same as color('attribute') and can be used if you prefer
+typing:
print BOLD BLUE ON_WHITE "Text", RESET, "\n";
@@ -411,7 +526,7 @@ terminal.
The subroutine interface has the advantage over the constants interface in
that only two subroutines are exported into your namespace, versus
-twenty-two in the constants interface. On the flip side, the constants
+thirty-eight in the constants interface. On the flip side, the constants
interface has the advantage of better compile time error checking, since
misspelled names of colors or attributes in calls to color() and colored()
won't be caught until runtime whereas misspelled names of constants will
@@ -599,9 +714,10 @@ Russ with input from Zenin. Russ Allbery now maintains this module.
=head1 COPYRIGHT AND LICENSE
-Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006, 2008, 2009 Russ
-Allbery <rra@stanford.edu> and Zenin. This program is free software; you
-may redistribute it and/or modify it under the same terms as Perl itself.
+Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006, 2008, 2009, 2010
+Russ Allbery <rra@stanford.edu> and Zenin. This program is free software;
+you may redistribute it and/or modify it under the same terms as Perl
+itself.
PUSHCOLOR, POPCOLOR, and LOCALCOLOR were contributed by openmethods.com
voice solutions.
diff --git a/Master/tlpkg/tlperl/lib/Term/ReadLine.pm b/Master/tlpkg/tlperl/lib/Term/ReadLine.pm
index 29acb849015..0121cdfd065 100644
--- a/Master/tlpkg/tlperl/lib/Term/ReadLine.pm
+++ b/Master/tlpkg/tlperl/lib/Term/ReadLine.pm
@@ -156,22 +156,6 @@ empty, the best available package is loaded.
(Note that processing of C<PERL_RL> for ornaments is in the discretion of the
particular used C<Term::ReadLine::*> package).
-=head1 CAVEATS
-
-It seems that using Term::ReadLine from Emacs minibuffer doesn't work
-quite right and one will get an error message like
-
- Cannot open /dev/tty for read at ...
-
-One possible workaround for this is to explicitly open /dev/tty like this
-
- open (FH, "/dev/tty" )
- or eval 'sub Term::ReadLine::findConsole { ("&STDIN", "&STDERR") }';
- die $@ if $@;
- close (FH);
-
-or you can try using the 4-argument form of Term::ReadLine->new().
-
=cut
use strict;
@@ -196,7 +180,6 @@ sub readline {
and defined &Tk::DoOneEvent;
#$str = scalar <$in>;
$str = $self->get_line;
- $str =~ s/^\s*\Q$prompt\E// if ($^O eq 'MacOS');
utf8::upgrade($str)
if (${^UNICODE} & PERL_UNICODE_STDIN || defined ${^ENCODING}) &&
utf8::valid($str);
@@ -211,9 +194,7 @@ sub findConsole {
my $console;
my $consoleOUT;
- if ($^O eq 'MacOS') {
- $console = "Dev:Console";
- } elsif (-e "/dev/tty") {
+ if (-e "/dev/tty") {
$console = "/dev/tty";
} elsif (-e "con" or $^O eq 'MSWin32') {
$console = 'CONIN$';
@@ -235,6 +216,10 @@ sub findConsole {
$consoleOUT = $console unless defined $consoleOUT;
$console = "&STDIN" unless defined $console;
+ if ($console eq "/dev/tty" && !open(my $fh, "<", $console)) {
+ $console = "&STDIN";
+ undef($consoleOUT);
+ }
if (!defined $consoleOUT) {
$consoleOUT = defined fileno(STDERR) && $^O ne 'MSWin32' ? "&STDERR" : "&STDOUT";
}
@@ -303,7 +288,7 @@ sub get_line {
package Term::ReadLine; # So late to allow the above code be defined?
-our $VERSION = '1.05';
+our $VERSION = '1.07';
my ($which) = exists $ENV{PERL_RL} ? split /\s+/, $ENV{PERL_RL} : undef;
if ($which) {
diff --git a/Master/tlpkg/tlperl/lib/Term/UI.pm b/Master/tlpkg/tlperl/lib/Term/UI.pm
index 136f75bb6ad..ba7a30421ba 100644
--- a/Master/tlpkg/tlperl/lib/Term/UI.pm
+++ b/Master/tlpkg/tlperl/lib/Term/UI.pm
@@ -11,7 +11,7 @@ use strict;
BEGIN {
use vars qw[$VERSION $AUTOREPLY $VERBOSE $INVALID];
$VERBOSE = 1;
- $VERSION = '0.20';
+ $VERSION = '0.26';
$INVALID = loc('Invalid selection, please try again: ');
}
@@ -137,7 +137,7 @@ sub get_reply {
my $prompt_add;
### if you supplied several choices to pick from,
- ### we'll print them seperately before the prompt
+ ### we'll print them separately before the prompt
if( @{$args->{choices}} ) {
my $i;
@@ -483,7 +483,7 @@ This defaults to C<*STDOUT>.
### ask a user (with an open question) for their favourite colour
$reply = $term->get_reply( prompt => 'Your favourite colour? );
-
+
which would look like:
Your favourite colour?
@@ -496,7 +496,7 @@ and C<$reply> would hold the text the user typed.
$reply = $term->get_reply(
prompt => 'Your favourite colour?',
choices => [qw|red green blue|] );
-
+
which would look like:
1> red
@@ -504,7 +504,7 @@ which would look like:
3> blue
Your favourite colour?
-
+
C<$reply> will hold one of the choices presented. C<Term::UI> will repose
the question if the user attempts to enter an answer that's not in the
list of choices. The string presented is held in the C<$Term::UI::INVALID>
@@ -559,7 +559,7 @@ An answer of C<3 2 1> would fill C<@reply> with C<blue green red>
$reply = $term->get_reply(
prompt => "What is the magic number?",
allow => 42 );
-
+
Unless the user now enters C<42>, the question will be reposed over
and over again. You can use more sophisticated C<allow> handlers (even
subroutines can be used). The C<allow> handler is implemented using