]> lifelog.hopto.org Git - wb-shell-scripts.git/commitdiff
Updated positioning.
authorWill Budic <redacted>
Mon, 25 Nov 2024 12:05:07 +0000 (23:05 +1100)
committerWill Budic <redacted>
Mon, 25 Nov 2024 12:05:07 +0000 (23:05 +1100)
timer.pl

index c94d095178772869d9c0b0dbdd21dcd809cb7180..bfebe950da3c203f5868856a7e0494e19e24421d 100755 (executable)
--- a/timer.pl
+++ b/timer.pl
@@ -3,8 +3,10 @@ use strict;
 use warnings;
 use Term::ANSIColor 2.01 qw(:constants colored);
 use Term::Screen;
+binmode STDOUT, ":encoding(utf8)";
 
-my ($sta,$end) = (time,undef);#my $end = $sta + 15*60;
+
+my ($sta,$end_at) = (time,undef);
 my ($time, $cmd); 
 
 our @pos = getCPos();
@@ -22,17 +24,17 @@ if( scalar @ARGV > 0 ){
             print BOLD "\rTimer:", BRIGHT_BLUE, ON_BRIGHT_BLACK," $title \n", RESET
         }
         elsif ( $arg =~ /^\d+/ ) {
-            $end = $sta + $arg * 60;
+            $end_at = $sta + $arg * 60;
             print "\rCountdown set to minutes: $arg\n";
         }
         elsif ( $arg =~ /^-+t.*/ ) {
             $tlo = 1;
         }
-                 elsif ( $arg =~ /^-+f.*/ ) {
+               elsif ( $arg =~ /^-+f.*/ ) {
             &fzf;
         }
         elsif ( $arg =~ /^-+[^0-9]+/ ) {
-                       $t->at($row-3,0)->clreol();undef $t; 
+                       $t->at($row-3,0)->clreos(); undef $t;
             while (<DATA>) {print transPrint($_)}
             exit;
         }
@@ -68,18 +70,20 @@ sub transPrint { my $ln = shift;
 return
 }
 
-&fzf unless $end;
+&fzf unless $end_at;
 
 my $stopwatch = time;
 my ($tt, $ptime, $stoptime, $tc,$cur,$sur) = 0;
 my ($stop,$stop_countdown) = (0,0);
-$t->at($row, 0)->curinvis(); die "Time not specified!" unless $end;
+die "Time not specified!" unless $end_at;
+
+$t->at($row, 0)->curinvis();
 
 while() {
        $time = time;
-       last if ($time > $end);
+       last if ($time > $end_at);
 
-       $cur = $end - $time unless $stop_countdown;
+       $cur = $end_at - $time unless $stop_countdown;
        $sur = $time - $stopwatch unless $stop;
        $t->flush_input();
        $t->clreol();
@@ -88,19 +92,20 @@ while() {
        my $stmp2 = sprintf(" [%02d:%02d:%02d]", $sur/(60*60), $sur/(60)%60, $sur%60);
        $stmp2=~s/^\d//;        
 
+
        if (($cur/(60)%60)>1){
-               print  YELLOW "\rTimer-> ", ON_BRIGHT_BLACK, BOLD, CYAN, "  $stmp1  ", RESET, GREEN, $stmp2, RESET unless $stop_countdown;
+               print  YELLOW "\rTimer \x{2015}\x{2AAB} ", ON_BRIGHT_BLACK, BOLD, CYAN, "  $stmp1  ", RESET, GREEN, $stmp2, RESET unless $stop_countdown;
        }else{
                $tc=0 if $tc++>3;
                if (($cur%60)<2){
-                       print  BOLD, GREEN, "\rTIMER ",  "---> ", $stmp1, RESET, GREEN, $stmp2, RESET;
+                       print  BOLD, GREEN, "\rTIMER ",  "\x{2015}\x{2015}\x{2015}\x{2AAB} ", $stmp1, RESET, GREEN, $stmp2, RESET;
                }else{
-                       print  RED "\rTimer ", BOLD;
-                       if($tc==0){print YELLOW, "-", RED, "--"}
-                       elsif($tc==1){print "-", YELLOW, "-", RED, "-"; print chr(7)}
-                       elsif($tc==2){print "--", YELLOW, "-"}
-                       else{print "---", YELLOW}
-                       print "> ", RED,  $stmp1, RESET, GREEN, $stmp2, RESET;
+                       ($tc>0?print RED:print YELLOW); print "\rTimer ", BOLD;
+                       if($tc==0){print YELLOW, "\x{2015}", RED, "\x{2015}\x{2015}"}
+                       elsif($tc==1){print "\x{2015}", YELLOW, "\x{2015}", RED, "\x{2015}"; print chr(7)}
+                       elsif($tc==2){print "\x{2015}\x{2015}", YELLOW, "\x{2015}"}
+                       else{print "\x{2015}\x{2015}\x{2015}", YELLOW}
+                       print "\x{2AAB} ", RED,  $stmp1, RESET, GREEN, $stmp2, RESET;
                }
        }
        
@@ -111,7 +116,7 @@ while() {
                        $stop_countdown =$stop_countdown?0:1; $stop=0;
                        print RED, BLINK, " Countdown -> ".($stop_countdown?"Paused":"Running")."!", RESET;
                        if($stop_countdown){$stoptime = time}
-                       else{$end += time - $stoptime;}
+                       else{$end_at += time - $stoptime;}
                }else{
                        $stop = $stop?0:1;
                        print RED " Stopwatch -> ".($stop?"Paused":"Running")."!";
@@ -125,18 +130,20 @@ while() {
        }
 }
 
-$t->curvis()->normal()->clreol();$title=$$ unless $title; 
+$t->curvis()->normal()->clreol();  $title=$$ unless $title; 
 my $msg = "Timer '$title' has expired!";
 
 `/usr/bin/notify-send "TIMER $title" "$msg"&`;
 
 $ptime = `date '+%r'`; $ptime =~ s/\n$//;
-print BRIGHT_RED, BLINK, "\r$msg  [ $ptime ]\n", RESET;
+$t->at($row+1,0)->clreos()->curvis()->clreol();
+print BRIGHT_RED, BLINK, "\r$msg  [ $ptime ]", RESET;
 
 if($cmd){
-       $t->echo();
-       system('echo "\e[?25h"'); 
-       print YELLOW "\rResult of ->`".$cmd, "` is:\r\n";
+       $t->echo();     
+       $t->at($row+1,0);
+       system('echo "\e[?25h\b"'); 
+       print YELLOW "Result of \x{2015}\x{2AAB} `".$cmd, "` is:\r\n";
     my @res = qx/$cmd/; 
        foreach my $l(@res){
                $l =~ s/\n*$//;
@@ -145,7 +152,7 @@ if($cmd){
 }else{    #MODIFY BELLOW TO DESIRED ALARM, or move the provided ./chiming-and-alarm-beeps.wav to your Music folder.
        system("mpv --vid=no --loop-file=3 $ENV{HOME}/Music/chiming-and-alarm-beeps.wav > /dev/null");
        $row-=5 if $row>$t->rows();
-       $t->at($row+1, 0)->clreol()->at($row, 0); print BRIGHT_RED, "\r$msg  [ $ptime ]", RESET;
+       $t->at($row+1, 0)->clreol()->at($row, 0)->clreol(); print BRIGHT_RED, "\r$msg  [ $ptime ]", RESET;
        system('echo "\e[?25h"'); 
        $t->dl()->at($row+1, 0)->clreol()->echo()->curvis();
 }
@@ -167,31 +174,31 @@ my $cmd = qq(
                if($sel =~ m/m$/){
                        $sel =~ s/m$//;
                        print "Setting timer($$) to $sel minutes.\n";
-                       $end = $sta + $sel * 60;
+                       $end_at = $sta + $sel * 60;
                }
                elsif($sel =~ m/h$/){
                        $sel =~ s/h$//;
                        print "Setting timer($$) to $sel in hours.\n";                  
                        $sel *= 60;
-                       $end = $sta + $sel * 60;
+                       $end_at = $sta + $sel * 60;
                }elsif($sel =~ m/s$/){
                        $sel =~ s/s$//;
                        print "Setting timer($$) to $sel in seconds.\n";                        
-                       $end = $sta + $sel;
+                       $end_at = $sta + $sel;
                }
                else{
                        exit 1;#<- should not be possible!
-               }               
+               }
        }else{
                exit;
-       }
+       }       
        return $t->at($row-=5, 0)
 }
 sub interupt {
        $exited=1;      
        system('echo "\e[?25h"');#sleep 1;
        $row+=1;        
-       $t->at($row, 0)->clreos()->echo()->curvis();    
+       $t->at($row, 0)->clreol()->echo()->curvis()->normal()->clreos();
        print RESET, "[CTRL]+[C] <- Terminated!\r\n";
        exit 0;
 };