From 8460da569ce45696aaf9e29484b99e2b7c74bf99 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 20 Jun 2023 00:21:59 -0400 Subject: [PATCH] Added command line switches --- perl/df-highlight.pl | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/perl/df-highlight.pl b/perl/df-highlight.pl index 5dc6a60..8145901 100644 --- a/perl/df-highlight.pl +++ b/perl/df-highlight.pl @@ -5,19 +5,23 @@ use strict; use Term::ANSIColor; use Time::HiRes qw(usleep nanosleep); use Time::localtime; -use Getopt::Long; # "User modifiable" data -my $MY_COL=3; my $DFCMD="/usr/bin/df"; my $TPUT="/usr/bin/tput"; my $DFARGS="-h"; my $CLEAR_SCREEN=`/usr/bin/clear`; +# Arguments +my ($CLS, $RBG, $ARGDEX, $MY_COL) = (0,0,0,3); +for (@ARGV) { + if ($_ eq "-p") {$RBG=1;} + elsif ($_ eq "-c") {$MY_COL=$ARGV[$ARGDEX+1];} + elsif ($_ eq "--help" or $_ eq "-h" ) {get_help();} + $ARGDEX++; +} + # Static data -#GetOptions("=s" => \( my $INTERVAL=300 ),"header|h=i" => \( my $HEADER_REPEAT = 24 ),) or die "command line arguments error"; -my $CLS = grep( /^-c/, @ARGV ) ? 1 : 0; -my $RBG = grep( /^-p/, @ARGV ) ? 1 : 0; my $ROW_START=`$TPUT cub 120`; # If this doesn't work on your terminal, make the value more than 120 lol my $UP_ONE_ROW=`$TPUT cuu1`; my $CLEAR_TO_END=`$TPUT el`; @@ -31,6 +35,16 @@ my $COLOR_OFFSET=9; sub clean {my $text = shift; $text=~s/\n//g; $text=~s/\r//g;return $text;} sub randcol {return int(rand(6)+1);} sub cachemath {my $lcache=(localtime->min*60)+localtime->sec;return $lcache;} +sub get_help { + my ($underline,$undereset)=(`tput smul`,`tput sgr0`); + my @help_columns=qw(12); + printf("\n%s%s%s\n\n","$underline","DF Highlight Script Usage","$undereset"); + printf(""); + printf(" %-$help_columns[0]s %s\n","-h, --help","Displays this help and exits"); + printf(" %-$help_columns[0]s %s\n","-c #","Highlights the specified column (default: 3)"); + printf(" %-$help_columns[0]s %s\n","-p","Enables a pinball-esque color mode before highlighting the chosen column"); + exit 0; +} # Runtime data my @linedata=(); @@ -75,13 +89,15 @@ sub dfboi { } } -my $blinky=10; -my $undoline=0; -while ($blinky--) { - dfboi(randcol()); - select()->flush(); - usleep($blinky < 2 ? 600000 : $blinky < 4 ? 300000 : 150000); - $undoline=0; - while ($undoline < $rows) {printf("%s",$UP_ONE_ROW);$undoline++;} +if ($RBG) { + my $blinky=10; + my $undoline=0; + while ($blinky--) { + dfboi(randcol()); + select()->flush(); + usleep($blinky < 2 ? 600000 : $blinky < 4 ? 300000 : 150000); + $undoline=0; + while ($undoline < $rows) {printf("%s",$UP_ONE_ROW);$undoline++;} + } } dfboi($MY_COL);