| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
use vars qw($VERSION); |
| 5 |
|
| 6 |
$VERSION = 5.08; |
| 7 |
|
| 8 |
use Tk; |
| 9 |
use Tk::More; |
| 10 |
use Getopt::Long; |
| 11 |
|
| 12 |
my %opt; |
| 13 |
|
| 14 |
Getopt::Long::config('pass_through'); |
| 15 |
if (!GetOptions(\%opt, "font=s", "i|ignore-case!", "encoding=s", "S")) { |
| 16 |
require Pod::Usage; |
| 17 |
Pod::Usage::pod2usage(2); |
| 18 |
} |
| 19 |
|
| 20 |
my $mw = tkinit; |
| 21 |
|
| 22 |
# Unhandled options left? |
| 23 |
Getopt::Long::config('nopass_through'); |
| 24 |
if (!GetOptions({})) { |
| 25 |
require Pod::Usage; |
| 26 |
Pod::Usage::pod2usage(2); |
| 27 |
} |
| 28 |
|
| 29 |
my $file = shift @ARGV; |
| 30 |
if (!defined $file) { |
| 31 |
die "Filename is missing.\n"; |
| 32 |
} |
| 33 |
|
| 34 |
my $more = $mw->Scrolled("More", |
| 35 |
-font => $opt{font}, |
| 36 |
-scrollbars => "osoe", |
| 37 |
-searchcase => !$opt{i}, |
| 38 |
($opt{S} ? (-wrap => 'none') : ()), |
| 39 |
)->pack(-fill => "both", -expand => 1); |
| 40 |
|
| 41 |
my $menu = $more->menu; |
| 42 |
my $fm = $menu->entrycget("File", -menu); |
| 43 |
$fm->insert("Exit", "command", -label => "Open ...", -underline => 0, |
| 44 |
-command => sub { |
| 45 |
my $f = $more->getOpenFile; |
| 46 |
return if !defined $f; |
| 47 |
load_file($f); |
| 48 |
}); |
| 49 |
$fm->entryconfigure("Exit", -accelerator => "Ctrl-Q"); |
| 50 |
|
| 51 |
my $helpmenu = $menu->Menu |
| 52 |
(-tearoff => 0, |
| 53 |
-menuitems => [ |
| 54 |
[Button => "~Usage", |
| 55 |
-command => sub { |
| 56 |
require Tk::Pod; |
| 57 |
$mw->Pod(-file => "Tk::More"); |
| 58 |
}] |
| 59 |
] |
| 60 |
); |
| 61 |
$menu->cascade(-label => "Help", -underline => 0, -menu => $helpmenu); |
| 62 |
$mw->configure(-menu => $menu); |
| 63 |
|
| 64 |
$more->focus; |
| 65 |
load_file($file); |
| 66 |
$more->AddQuitBindings; |
| 67 |
MainLoop; |
| 68 |
|
| 69 |
sub load_file { |
| 70 |
my $file = shift; |
| 71 |
LOAD_FILE: { |
| 72 |
# check if it's gzipped |
| 73 |
my $buf; |
| 74 |
if (open(FILE, "<$file") && |
| 75 |
read(FILE, $buf, 2) == 2 && |
| 76 |
$buf eq "\037\213" && |
| 77 |
eval { require PerlIO::gzip; 1 } |
| 78 |
) { |
| 79 |
seek FILE, 0, 0 or die $!; |
| 80 |
binmode FILE, ':gzip'; |
| 81 |
$more->LoadFH(\*FILE, -encoding => $opt{encoding}); |
| 82 |
last LOAD_FILE; |
| 83 |
} |
| 84 |
|
| 85 |
$more->Load($file, -encoding => $opt{encoding}); |
| 86 |
}; |
| 87 |
$mw->title("tkmore - $file"); |
| 88 |
} |
| 89 |
|
| 90 |
__END__ |
| 91 |
|
| 92 |
=head1 NAME |
| 93 |
|
| 94 |
tkmore - a Perl/Tk based pager |
| 95 |
|
| 96 |
=head1 SYNOPSIS |
| 97 |
|
| 98 |
tkmore [X11 options] [-i] [-encoding encoding] filename |
| 99 |
|
| 100 |
=head1 DESCRIPTION |
| 101 |
|
| 102 |
B<tkmore> is a pager similar to L<more(1)> or L<less(1)>. |
| 103 |
|
| 104 |
=head2 OPTIONS |
| 105 |
|
| 106 |
Besides standard X11 options like C<-font>, B<tkmore> supports: |
| 107 |
|
| 108 |
=over |
| 109 |
|
| 110 |
=item -i |
| 111 |
|
| 112 |
Turn on case-insensitive search. Alias: C<-ignore-case>. |
| 113 |
|
| 114 |
=item -encoding encoding |
| 115 |
|
| 116 |
Specify the encoding for the specified file and all subsequently |
| 117 |
loaded files. By default no encoding is assumed. |
| 118 |
|
| 119 |
=item -S |
| 120 |
|
| 121 |
Set wrap mode to B<none>. The effect is similar like the C<-S> option |
| 122 |
of C<less>. |
| 123 |
|
| 124 |
=back |
| 125 |
|
| 126 |
=head2 KEY BINDINGS |
| 127 |
|
| 128 |
For a list of key bindings, see L<Tk::More/ADDITIONAL BINDINGS>. |
| 129 |
|
| 130 |
=head1 AUTHOR |
| 131 |
|
| 132 |
Slaven Rezic |
| 133 |
|
| 134 |
=head1 SEE ALSO |
| 135 |
|
| 136 |
L<Tk::More>, L<more(1)>, L<less(1)> |
| 137 |
|
| 138 |
=cut |