App-termpub

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

    previously marked with that letter. Followed by another single quote,
    returns to the position at which the last "large" movement command was
    executed.

- \[num\] |

    Set pager width to _num_.

- \[num\] %

    Go to a line N percent into the chapter.

- \[num\] g

    Go to line _num_ in the chapter, defaults to 1.

- \[num\] G

    Go to line _num_ in the chapter, default to the end of the chapter.

- \[num\] o

lib/App/termpub/Epub.pm  view on Meta::CPAN


sub read_metadata {
    my $self = shift;
    my $content =
      $self->archive->contents('META-INF/com.domgoergen.termpub.json')
      || '{}';
    my $data = decode_json($content);
    if ( $data->{version} == 1 ) {
        $data->{position} = {
            chapter => $data->{position}->[0],
            percent => $data->{position}->[1]
        };
    }
    return $data;
}

sub save_metadata {
    my ( $self, $data ) = @_;
    my ($tempfile) = tempfile;

    $self->archive->removeMember('META-INF/com.domgoergen.termpub.json');

lib/App/termpub/Pager.pm  view on Meta::CPAN

        ' '                   => 'next_page',
        Curses::KEY_NPAGE     => 'next_page',
        Curses::KEY_PPAGE     => 'prev_page',
        Curses::KEY_BACKSPACE => 'prev_page',
        Curses::KEY_HOME      => 'first_page',
        Curses::KEY_END       => 'last_page',
        Curses::KEY_RESIZE    => 'handle_resize',
        'q'                   => 'quit',
        'g'                   => 'goto_line',
        'G'                   => 'goto_line_or_end',
        '%'                   => 'goto_percent',
        'm'                   => 'mark_position',
        "'"                   => 'restore_position',
    };
};

has 'prefix' => '';

sub goto_position {
    my ( $self, $position ) = @_;
    if (   $position->{line}
        && $position->{columns}
        && $position->{columns} == $self->pad_columns )
    {
        $self->goto_line( $position->{line} );
    }
    else {
        $self->goto_percent( $position->{percent} );
    }
}

sub get_position {
    my $self = shift;
    return {
        percent => $self->get_percent,
        line    => $self->line,
        columns => $self->pad_columns,
    };
}

sub set_mark {
    my ( $self, $position ) = @_;
    $self->positions->{"'"} = $position || $self->get_position;
}

lib/App/termpub/Pager.pm  view on Meta::CPAN

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 ) {

lib/App/termpub/Pager.pm  view on Meta::CPAN

    if ( $self->line - $self->rows > 0 ) {
        $self->line( $self->line - $self->rows );
    }
    else {
        $self->line(0);
    }
    $self->update_screen;
    return 1;
}

sub get_percent {
    my $self = shift;
    return 0 if !$self->pad_rows;
    int( ( $self->line + 1 ) * 100 / $self->pad_rows );
}

sub update_screen {
    my $self = shift;
    clear;
    refresh;
    prefresh( $self->pad, $self->line, 0, 0, 0, $self->rows - 1,
        $self->pad_columns );

    my $status = '-' x $self->columns;

    substr( $status, 0, length( $self->title ) ) = $self->title;

    my $pos = $self->get_percent . '%';
    if ( $self->line + $self->rows - 1 >= $self->pad_rows ) {
        $pos = "end";
    }
    $pos = "($pos)";

    substr( $status, -length($pos) - 2, length($pos) ) = $pos;

    move( $self->rows, 0 );
    addstring($status);

script/termpub  view on Meta::CPAN

previously marked with that letter. Followed by another single quote,
returns to the position at which the last "large" movement command was
executed.

=item [num] |

Set pager width to I<num>.

=item [num] %

Go to a line N percent into the chapter.

=item [num] g

Go to line I<num> in the chapter, defaults to 1.

=item [num] G

Go to line I<num> in the chapter, default to the end of the chapter.

=item [num] o



( run in 0.313 second using v1.01-cache-2.11-cpan-05162d3a2b1 )