App-MechaCPAN
view release on metacpan or search on metacpan
lib/App/MechaCPAN.pm view on Meta::CPAN
sub error
{
my $key = shift;
my $line = shift;
if ( !defined $line )
{
$line = $key;
undef $key;
}
status( $key, 'RED', $line );
}
my $RESET = Term::ANSIColor::color('RESET');
my $BOLD = Term::ANSIColor::color('BOLD');
sub _show_line
{
my $key = shift;
my $color = shift;
my $line = shift;
# If the color starts with red, it's an error and we should not touch it,
# otherwise, we should clean up the line
state $ERR_COLOR = Term::ANSIColor::color('RED');
if ( $color !~ m/^\Q$ERR_COLOR/ )
{
$line =~ s/\n/ /xmsg;
}
state @key_lines;
my $idx = first { $key_lines[$_] eq $key } 0 .. $#key_lines;
if ( !defined $key )
{
# Scroll Up 1 line
print STDERR "\n";
$idx = -1;
}
if ( !defined $idx )
{
unshift @key_lines, $key;
$idx = 0;
# Scroll Up 1 line
print STDERR "\n";
}
$idx++;
# Don't bother with fancy line movements if we are verbose
if ($VERBOSE)
{
print STDERR "$color$line$RESET\n";
return;
}
# We use some ANSI escape codes, so they are:
# \e[.F - Move up from current line, which is always the end of the list
# \e[K - Clear the line
# $color - Colorize the text
# $line - Print the text
# $RESET - Reset the colorize
# \e[.E - Move down from the current line, back to the end of the list
print STDERR "\e[${idx}F";
print STDERR "\e[K";
print STDERR "$color$line$RESET\n";
print STDERR "\e[" . ( $idx - 1 ) . "E"
if $idx > 1;
return;
}
sub status
{
my $key = shift;
my $color = shift;
my $line = shift;
if ( !defined $line )
{
$line = $color;
$color = 'RESET';
}
logmsg($line);
return
if $QUIET;
$color = eval { Term::ANSIColor::color($color) } // $RESET;
state @last_key;
# Undo the last line that is bold
if ( @last_key && !$VERBOSE && $last_key[0] ne $key )
{
_show_line(@last_key);
}
_show_line( $key, $color . $BOLD, $line );
@last_key = ( $key, $color, $line );
}
END { print STDERR "\n" unless $QUIET; }
INIT { print STDERR "\n" unless $QUIET; }
sub _get_project_dir
{
my $result = $PROJ_DIR;
return $result;
}
sub get_project_dir
{
my $result = _get_project_dir;
( run in 0.685 second using v1.01-cache-2.11-cpan-437f7b0c052 )