Browse Source

Added watchlog.pl (currently only for *nices)

Alois Mahdal (@azzgoat) 11 years ago
parent
commit
e31d357fb7
3 changed files with 63 additions and 0 deletions
  1. 16
    0
      README.md
  2. 1
    0
      TODO.md
  3. 46
    0
      bin/watchdump.pl

+ 16
- 0
README.md View File

@@ -73,3 +73,19 @@ one second takes, it can serve as a snippet for Perl `&stamp()`.
73 73
 Container module for some utility methods for Perl.  Probably only `dmup()` 
74 74
 is interesting—it bears a nice quick and dirty way for dumping Perl 
75 75
 data.
76
+
77
+
78
+##watchdump.pl##
79
+
80
+Trivial utility that prints a text file, clears the screen and pauses for 2s
81
+over and over.
82
+
83
+Designed mainly for use with `helper::dmup();` to enable you to see changes
84
+in your dumped data structure continuously, but obviously you can use it for
85
+any text file that will fit your screen.
86
+
87
+For improved visual feedack, it will pre-pend the file contents with the file
88
+path and an "animation".  Display of the header can be controlled by options,
89
+see `--usage`.
90
+
91
+Note: Currently works only on UNIX-like systems.

+ 1
- 0
TODO.md View File

@@ -5,6 +5,7 @@ To-do:
5 5
         * mksheet.pl
6 6
         * htlogr: implement severities
7 7
         * htlogr: straighten up parameters
8
+        * watchdump.pl: make it work on Windows
8 9
 
9 10
     * document:
10 11
         * usage of mksheet.pl

+ 46
- 0
bin/watchdump.pl View File

@@ -0,0 +1,46 @@
1
+#!/usr/bin/perl -w
2
+
3
+use strict;
4
+use warnings;
5
+
6
+use Getopt::Long;
7
+
8
+my $opts;
9
+$opts->{no_header}  = 0;
10
+$opts->{delay}      = 2;
11
+$opts->{frames}     = "-/|\\";
12
+
13
+GetOptions (
14
+    "no-header" => \$opts->{no_header},
15
+    "usage"     => \$opts->{usage},
16
+    "help"      => \$opts->{usage},
17
+    "delay=i"   => \$opts->{delay},
18
+    "frames=s"  => \$opts->{frames},
19
+) or &usage;
20
+
21
+&usage if $opts->{usage};
22
+
23
+sub usage {
24
+    print "usage: watchdump.pl --no-header --delay=SEC --frames=CHARS FILE\n";
25
+    exit 0;
26
+}
27
+
28
+my @frames      = split "", $opts->{frames};
29
+my $frame_num   = 0;
30
+
31
+sub get_frame {
32
+    my $frame = $frames[$frame_num];
33
+    $frame_num++;
34
+    $frame_num = 0 if $frame_num > $#frames;
35
+    return $frame;
36
+}
37
+
38
+my $file = shift @ARGV or &usage;
39
+
40
+while (1) {
41
+    system("clear");
42
+    printf "[%s] watching: %s\n%s\n", &get_frame(), $file, "=" x 80
43
+        unless $opts->{no_header};
44
+    print `cat $file`;
45
+    sleep $opts->{delay};
46
+}