more misc work

git-svn-id: svn://127.0.0.1/Perl/Proc-ProcessTable-Colorizer/trunk@960 0c1c3402-1be1-de11-8092-0022686faf23
This commit is contained in:
Zane C. B-H 2017-09-27 11:45:07 +00:00
parent 4c6a8e28b4
commit c51a744a65
2 changed files with 96 additions and 11 deletions

View File

@ -25,7 +25,7 @@
use strict;
use warnings;
use Getopt::Std;
use Log::Colorize::Helper;
use Proc::ProcessTable::Colorizer;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
@ -38,3 +38,7 @@ sub main::HELP_MESSAGE {
my %opts=();
getopts('', \%opts);
use Proc::ProcessTable::Colorizer;
my $cps = Proc::ProcessTable::Colorizer->new;
print $cps->colorize;

View File

@ -30,7 +30,7 @@ our $VERSION = '0.0.0';
use Proc::ProcessTable::Colorizer;
my $foo = Proc::ProcessTable::Colorizer->new();
my $cps = Proc::ProcessTable::Colorizer->new();
...
This module uses L<Error::Helper> for error reporting.
@ -68,7 +68,7 @@ sub new {
],
processColor=>'WHITE',
fields=>[
'pid'
'pid',
'uid',
'pctcpu',
'pctmem',
@ -81,6 +81,7 @@ sub new {
'time',
'proc',
],
header=>1,
};
bless $self;
return $self;
@ -129,9 +130,72 @@ These are the colors for seconds, minutes, hour, 10+ hours.
=cut
sub colorize{
my $self=$_[0];
$self->errorblank;
my $self=$_[0];
$self->errorblank;
#the feilds to use
my $fields=$self->fieldsGet;
#array of colored items
my @colored;
#
my $fieldInt=0;
my $header;
if ( $self->{header} ){
my @header;
while ( defined( $fields->[$fieldInt] ) ){
my $field=color('underline white');
if ( $fields->[$fieldInt] eq 'pid' ){
$field=$field.'PID';
}elsif( $fields->[$fieldInt] eq 'uid' ){
$field=$field.'User';
}elsif( $fields->[$fieldInt] eq 'pctcpu' ){
$field=$field.'CPU%';
}elsif( $fields->[$fieldInt] eq 'pctmem' ){
$field=$field.'Mem%';
}elsif( $fields->[$fieldInt] eq 'vmsize' ){
$field=$field.'VM Size';
}elsif( $fields->[$fieldInt] eq 'rss' ){
$field=$field.'RSS';
}elsif( $fields->[$fieldInt] eq 'wchan' ){
$field=$field.'WChan';
}elsif( $fields->[$fieldInt] eq 'proc' ){
$field=$field.'Command';
}else{
$field=$field.ucfirst($fields->[$fieldInt]);
}
push( @header, $field.color('reset') );
$fieldInt++;
}
push( @colored, @header );
}
#get the process table
my $pt=Proc::ProcessTable->new;
my $procs=$pt->table;
#goes through it all and puts it together
my $PIDint=0;
while( defined( $procs->[$PIDint] ) ){
my @line;
#process the requested fields
$fieldInt=0;
while ( defined( $fields->[$fieldInt] ) ){
$fieldInt++;
}
$PIDint++;
}
my $tb = Text::Table->new;
return $tb->load( \@colored );
}
=head2 timeString
@ -156,13 +220,13 @@ sub timeString{
#find the most common one and return it
if ( $year ne $cyear ){
return $year.$mon.$day'-'$hour.$min;
return $year.$mon.$mday.'-'/$hour.$min;
}
if ( $mon ne $cmon ){
return $mon.$day'-'$hour.$min;
return $mon.$mday.'-'.$hour.$min;
}
if ( $day ne $cday ){
return $day'-'$hour.$min;
if ( $mday ne $cmday ){
return $mday.'-'.$hour.$min;
}
#just return this for anything less
@ -199,9 +263,9 @@ sub fields{
Gets the currently set fields.
Returns a list of current fields to be printed.
Returns a array ref of current fields to be printed.
my @fields=$cps->fieldsGet;
my $fields=$cps->fieldsGet;
=cut
@ -212,6 +276,23 @@ sub fieldsGet{
return $self->{fields};
}
=head2 fieldsSet
Gets the currently set fields.
Returns a list of current fields to be printed.
my @fields=$cps->fieldsGet;
=cut
sub fieldsSet{
my $self=$_[0];
$self->errorblank;
}
=head2 timeColorsGet
my @timeColors=$cps->timeColorsGet;