diff --git a/bin/sealerwatch.pl b/bin/sealerwatch.pl index 9c01dd7305d69d983a36bff2c8a27ee50f69caff..d9d38901e5250d635f3a44d9af6fc6abee1f0d44 100755 --- a/bin/sealerwatch.pl +++ b/bin/sealerwatch.pl @@ -193,6 +193,12 @@ sub number return hex( $_[0]->result->{'number'} ); } +sub difficulty +{ + return if not exists $_[0]->result->{'difficulty'}; + return hex( $_[0]->result->{'difficulty'} ); +} + sub td { return if not exists $_[0]->result->{'totalDifficulty'}; @@ -339,25 +345,41 @@ sub determine_colour if $diff == 0; return ansi::green() if $diff < scalar ( keys %signers ); - return ansi::bgyellow() . ansi::black + return ansi::bgyellow() . ansi::black() if $diff < 720; # one hour return ansi::red(); } sub colour_split { - my ($name, $diff, $col) = @_; + my ($name, $diff, $col, $difficulty) + = @_; return $name if $diff == 0; my $len = length $name; - return - substr( $name, 0, $len-$diff) . - (( $col eq '' ) ? ansi::green() : $col) . - substr( $name, $len-$diff ) . - ansi::normal() - if $diff <= $len; + if ( $diff <= $len ) + { + my $part1 = substr $name, 0,$len-$diff; + my $part2 = substr $name, $len-$diff,1; + my $part3 = substr $name, $len-$diff+1; + if ( $difficulty == 2 ) + { + $part3 = $part2 . $part3; + $part2 = ''; + } + $part2 = ansi::bgyellow() . ansi::black() . $part2 . ansi::normal() + if $part2 ne ''; + return + $part1 . + $part2 . + (( $col eq '' ) ? ansi::green() : $col) . + $part3 . + ansi::normal(); + } # diff > len - return $col . $name . ansi::normal(); + return + ansi::red() . substr( $name, 0, 1 ) . ansi::normal() . + $col . substr( $name, 1 ) . ansi::normal(); } sub presentation_top @@ -436,7 +458,10 @@ while ( defined $block || sleep 1 ) my $lastnum = exists $signers{$this} ? $signers{$this} : -12345; my $diff = $number - $lastnum; my $col = determine_colour( $diff ); - my $id = colour_split( $this, $diff, $col ); + my $difficulty = ( exists $signers{$this} and exists $cache{$signers{$this}}{'block'} ) + ? $cache{$signers{$this}}{'block'}->difficulty + : 0; + my $id = colour_split( $this, $diff, $col, $difficulty ); my $flags = $diff == 0 ? '*' : ''; my $alias = alias::translate( $this ); my $numtxt = (not defined $lastnum or $lastnum < 0) ? 'n/a' : $lastnum; @@ -448,4 +473,5 @@ while ( defined $block || sleep 1 ) print ansi::ED(0); # $number = $block->number + 1; + select( undef, undef,undef, 0.2 ); }