| 1 |
#!/usr/local/bin/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
use Tk; |
| 5 |
use Tk::ROText; |
| 6 |
use Tk::Font; |
| 7 |
use Carp; |
| 8 |
|
| 9 |
my $mw = MainWindow->new; |
| 10 |
my $mfont = $mw->Font(family => 'courier', slant => 'r', point => 140, weight => 'medium'); |
| 11 |
my $bfont = $mfont->Clone(weight => 'bold'); |
| 12 |
my $t = $mw->Scrolled('ROText',-font => $mfont, -wrap => 'none'); |
| 13 |
$t->Tag('bold',-font => $bfont); |
| 14 |
$t->Tag('underline',-underline => 1); |
| 15 |
|
| 16 |
$t->pack(-expand => 1, -fill => 'both'); |
| 17 |
|
| 18 |
# Netscape/Mosaic like paging |
| 19 |
$t->bind('<space>',['yview','scroll',1,'page']); |
| 20 |
$t->bind('<BackSpace>',['yview','scroll',-1,'page']); |
| 21 |
|
| 22 |
@ARGV = qw(perl) unless (@ARGV); |
| 23 |
|
| 24 |
load_doc($t,@ARGV); |
| 25 |
|
| 26 |
$mw->focusNext; |
| 27 |
|
| 28 |
MainLoop; |
| 29 |
|
| 30 |
sub load_doc |
| 31 |
{ |
| 32 |
my $t = shift; |
| 33 |
open(PIPE,join(' ','perldoc',@_,'|')) || die "Cannot open pipe:$!"; |
| 34 |
$t->delete('1.0' => 'end'); |
| 35 |
$t->insert('end',''); |
| 36 |
while (<PIPE>) |
| 37 |
{ |
| 38 |
my $line = ""; |
| 39 |
my @bold = (); |
| 40 |
my @under = (); |
| 41 |
while (length($_)) |
| 42 |
{ |
| 43 |
if (s/^(\n)//) |
| 44 |
{ |
| 45 |
$t->insert('end',$1); |
| 46 |
$t->markSet(insert => 'end'); |
| 47 |
} |
| 48 |
elsif (s/^_\010(.)//) |
| 49 |
{ |
| 50 |
$t->insert('insert',$1,['underline']); |
| 51 |
} |
| 52 |
elsif (s/^([^\010])(\010\1)+//) |
| 53 |
{ |
| 54 |
$t->insert('insert',$1,['bold']); |
| 55 |
} |
| 56 |
elsif (s/^\+\010o//) |
| 57 |
{ |
| 58 |
$t->insert('insert','o',['bold']); |
| 59 |
} |
| 60 |
elsif (s/^(\010+)//) |
| 61 |
{ |
| 62 |
# my $offset = length($1); |
| 63 |
# $t->markSet(insert => "insert - $offset c"); |
| 64 |
} |
| 65 |
elsif (s/^(.)//) |
| 66 |
{ |
| 67 |
$t->insert('insert',$1); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
close(PIPE); |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
|