Файловый менеджер - Редактировать - /home/lakoyani/lakoyani.com.fj/ANSIColor.pm.tar
Назад
usr/share/perl5/Term/ANSIColor.pm 0000644 00000071460 14711216313 0012513 0 ustar 00 # Term::ANSIColor -- Color screen output using ANSI escape sequences. # # Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006, 2008, 2009, 2010, # 2011 Russ Allbery <rra@stanford.edu> and Zenin # PUSH/POP support submitted 2007 by openmethods.com voice solutions # # This program is free software; you may redistribute it and/or modify it # under the same terms as Perl itself. # # Ah, September, when the sysadmins turn colors and fall off the trees.... # -- Dave Van Domelen ############################################################################## # Modules and declarations ############################################################################## package Term::ANSIColor; require 5.001; $VERSION = '3.01'; use strict; use vars qw($AUTOLOAD $AUTOLOCAL $AUTORESET @COLORLIST @COLORSTACK $EACHLINE @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION %ATTRIBUTES %ATTRIBUTES_R); 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 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); %EXPORT_TAGS = (constants => \@COLORLIST, pushpop => [ @COLORLIST, qw(PUSHCOLOR POPCOLOR LOCALCOLOR) ]); Exporter::export_ok_tags ('pushpop'); } ############################################################################## # 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, '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) { $ATTRIBUTES_R{$ATTRIBUTES{$_}} = $_; } ############################################################################## # Implementation (constant form) ############################################################################## # Time to have fun! We now want to define the constant subs, which are named # the same as the attributes above but in all caps. Each constant sub needs # to act differently depending on whether $AUTORESET is set. Without # autoreset: # # BLUE "text\n" ==> "\e[34mtext\n" # # If $AUTORESET is set, we should instead get: # # BLUE "text\n" ==> "\e[34mtext\n\e[0m" # # The sub also needs to handle the case where it has no arguments correctly. # Maintaining all of this as separate subs would be a major nightmare, as well # as duplicate the %ATTRIBUTES hash, so instead we define an AUTOLOAD sub to # define the constant subs on demand. To do that, we check the name of the # called sub against the list of attributes, and if it's an all-caps version # of one of them, we define the sub on the fly and then run it. # # If the environment variable ANSI_COLORS_DISABLED is set, just return the # arguments without adding any escape sequences. This is to make it easier to # write scripts that also work on systems without any ANSI support, like # Windows consoles. sub AUTOLOAD { if (defined $ENV{ANSI_COLORS_DISABLED}) { return join ('', @_); } if ($AUTOLOAD =~ /^([\w:]*::([A-Z_]+))$/ and defined $ATTRIBUTES{lc $2}) { $AUTOLOAD = $1; my $attr = "\e[" . $ATTRIBUTES{lc $2} . 'm'; eval qq { sub $AUTOLOAD { if (\$AUTORESET && \@_) { return '$attr' . join ('', \@_) . "\e[0m"; } elsif (\$AUTOLOCAL && \@_) { return PUSHCOLOR ('$attr') . join ('', \@_) . POPCOLOR; } else { return '$attr' . join ('', \@_); } } }; goto &$AUTOLOAD; } else { require Carp; Carp::croak ("undefined subroutine &$AUTOLOAD called"); } } # Append a new color to the top of the color stack and return the top of # the stack. sub PUSHCOLOR { my ($text) = @_; my ($color) = ($text =~ m/^((?:\e\[[\d;]+m)+)/); if (@COLORSTACK) { $color = $COLORSTACK[-1] . $color; } push (@COLORSTACK, $color); return $text; } # Pop the color stack and return the new top of the stack (or reset, if # the stack is empty). sub POPCOLOR { pop @COLORSTACK; if (@COLORSTACK) { return $COLORSTACK[-1] . join ('', @_); } else { return RESET (@_); } } # Surround arguments with a push and a pop. sub LOCALCOLOR { return PUSHCOLOR (join ('', @_)) . POPCOLOR (); } ############################################################################## # Implementation (attribute string form) ############################################################################## # Return the escape code for a given set of color attributes. sub color { return '' if defined $ENV{ANSI_COLORS_DISABLED}; my @codes = map { split } @_; my $attribute = ''; foreach (@codes) { $_ = lc $_; unless (defined $ATTRIBUTES{$_}) { require Carp; Carp::croak ("Invalid attribute name $_"); } $attribute .= $ATTRIBUTES{$_} . ';'; } chop $attribute; return ($attribute ne '') ? "\e[${attribute}m" : undef; } # Return a list of named color attributes for a given set of escape codes. # Escape sequences can be given with or without enclosing "\e[" and "m". The # empty escape sequence '' or "\e[m" gives an empty list of attrs. sub uncolor { my (@nums, @result); for (@_) { my $escape = $_; $escape =~ s/^\e\[//; $escape =~ s/m$//;
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка