Skip to content

Commit

Permalink
Add status line with percent marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Jan 20, 2019
1 parent 767b223 commit 47acf54
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/App/termpub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ has chapters => sub { shift->epub->chapters };
has chapter => 0;
has line => 1;
has 'rows';
has 'columns';
has 'pad';
has 'max_lines';

Expand All @@ -28,6 +29,7 @@ sub run {
my ( $rows, $columns );
$self->win->getmaxyx( $rows, $columns );
$self->rows( $rows - 1 );
$self->columns($columns);

$self->set_chapter( $self->epub->start_chapter );
$self->update_screen;
Expand All @@ -47,7 +49,7 @@ sub run {
);

while (1) {
my $c = $self->win->getchar;
my $c = $self->win->getchar;
my $method = $keys{$c};
next if !$method;
last if $method eq 'quit';
Expand Down Expand Up @@ -120,12 +122,19 @@ sub update_screen {
$self->win->refresh;
prefresh( $self->pad, $self->line, 0, 0, 0, $self->rows - 1, 80 );
$self->win->move( $self->rows, 0 );
$self->win->attron(A_STANDOUT);
$self->win->addstring( $self->chapters->[$self->chapter]->title );
$self->win->addstring( $self->chapters->[ $self->chapter ]->title );

my $pos = int( $self->line * 100 / $self->max_lines ) . '%';
if ( $self->line + $self->rows - 1 >= $self->max_lines ) {
$self->win->addstring(' (END) ');
$pos = "end";
}
$self->win->attroff(A_STANDOUT);
$pos = "($pos)";
$self->win->addstring( '-' x $self->columns );
$self->win->move( $self->rows, $self->columns - length($pos) - 2 );
$self->win->addstring($pos);

$self->win->move( $self->rows, 0 );
$self->win->chgat( -1, A_STANDOUT, 0, 0 );
$self->win->refresh;
}

Expand Down

0 comments on commit 47acf54

Please sign in to comment.