App-termpub
view release on metacpan or search on metacpan
lib/App/termpub/Pager.pm view on Meta::CPAN
}
sub handle_resize {
my $self = shift;
my ( $rows, $columns );
getmaxyx( $rows, $columns );
$self->rows( $rows - 1 );
$self->columns($columns);
}
sub run {
my $self = shift;
keypad(1);
$self->update_screen;
while (1) {
my $c = getch;
## Clear message line
$self->display_msg;
if ( $c eq '' ) {
$self->prefix('');
next;
}
if ( $c =~ /^[0-9]$/ ) {
$self->prefix( $self->prefix . $c );
next;
}
my $method = $self->key_bindings->{$c};
if ( !$method ) {
$self->display_msg("Key is not bound. Press 'h' for help.");
next;
}
if ( !$self->can($method) ) {
$self->display_msg("Unknown function $method called.");
next;
}
if ( ( $self->$method || '' ) eq 'quit' ) {
last;
}
$self->prefix('');
}
return;
}
sub quit {
return 'quit';
}
sub display_msg {
my ( $self, $msg ) = @_;
move( $self->rows + 1, 0 );
clrtoeol;
addstr($msg) if defined $msg;
return;
}
sub goto_line {
my ( $self, $num ) = @_;
$num ||= ( $self->prefix || 1 ) - 1;
if ( $num <= $self->pad_rows ) {
$self->line($num);
$self->update_screen if $self->rows;
}
return;
}
sub goto_percent {
my ( $self, $num ) = @_;
$num ||= ( $self->prefix || 0 );
$self->set_mark;
$self->goto_line( int( $num * $self->pad_rows / 100 ) );
}
sub goto_line_or_end {
my $self = shift;
$self->set_mark;
if ( $self->prefix ) {
$self->goto_line;
}
else {
$self->last_page;
}
return;
}
sub next_line {
my $self = shift;
if ( $self->line + 1 <= $self->pad_rows
and $self->line + $self->rows <= $self->pad_rows )
{
$self->line( $self->line + 1 );
$self->update_screen;
}
}
sub prev_line {
my $self = shift;
if ( $self->line != 0 ) {
$self->line( $self->line - 1 );
$self->update_screen;
}
}
sub first_page {
my $self = shift;
$self->set_mark;
$self->line(0);
$self->update_screen;
}
sub last_page {
my $self = shift;
( run in 1.161 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )