| 1 |
#!/usr/local/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Tk; |
| 4 |
use IO::File; |
| 5 |
|
| 6 |
sub readfile |
| 7 |
{ |
| 8 |
my ($t,$fh) = @_; |
| 9 |
my $size = (stat($fh))[7]; |
| 10 |
my $len = $size - $t->{'posn'}; |
| 11 |
if ($len > 0) |
| 12 |
{ |
| 13 |
my $buffer = ""; |
| 14 |
my $got = sysread($fh,$buffer,$len); |
| 15 |
$t->insert('end',$buffer); |
| 16 |
$t->{posn} += $got; |
| 17 |
$t->see('end'); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
my $mw = MainWindow->new; |
| 22 |
|
| 23 |
my $fh = IO::File->new("<$ARGV[0]"); |
| 24 |
|
| 25 |
my $t = $mw->Scrolled('Text',-scrollbars => 'w'); |
| 26 |
|
| 27 |
$t->pack(-expand => 1, -fill => 'both'); |
| 28 |
|
| 29 |
$t->{posn} = 0; |
| 30 |
|
| 31 |
$t->repeat(5000,sub { readfile($t,$fh) } ); |
| 32 |
|
| 33 |
MainLoop; |