Browse Source

now with more dependencies!

Brennen Bearnes 6 years ago
parent
commit
090610c876
1 changed files with 12 additions and 6 deletions
  1. 12
    6
      wthr

+ 12
- 6
wthr View File

@@ -4,20 +4,26 @@ use strict;
4 4
 use warnings;
5 5
 use 5.10.0;
6 6
 
7
+use Time::HiRes qw(sleep);
7 8
 use Term::ReadKey qw(GetTerminalSize);
8 9
 use File::Slurp;
9 10
 
10
-my ($width, $height) = GetTerminalSize();
11
-
12 11
 my @snowflakes = qw(❄ ❅ ❆);
12
+my ($width, $height) = GetTerminalSize();
13 13
 
14
-my $count //= grep { /^processor\s+: [0-9]/ } read_file('/proc/cpuinfo');
14
+my $cpu_count = grep { /^processor\s+: [0-9]/ } read_file('/proc/cpuinfo');
15 15
 
16 16
 while (1) {
17 17
    my ($load) = (read_file('/proc/loadavg') =~ m/^([\d.]+)/);
18
-   my $heaviness = int(($load / $count) * $width);
18
+   my $heaviness = int($load / $cpu_count);
19 19
    for (0 .. $heaviness) {
20
-       say ' ' x int(rand($width)) . ($snowflakes[ rand @snowflakes ]);
20
+       my $flake = $snowflakes[ rand @snowflakes ];
21
+       say ' ' x int(rand($width)) . $flake;
22
+   }
23
+
24
+   if ($heaviness > 0) {
25
+       sleep (1 / $heaviness)
26
+   } else {
27
+       sleep .75;
21 28
    }
22
-   sleep 1;
23 29
 }

Loading…
Cancel
Save