Skip to content

Commit

Permalink
Show title on status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Jan 19, 2019
1 parent 30efbf6 commit 821490c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/App/termpub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ sub update_screen {
$self->win->clear;
$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 );
if ( $self->line + $self->rows - 1 >= $self->max_lines ) {
$self->win->move( $self->rows, 0 );
$self->win->attron(A_STANDOUT);
$self->win->addstring('(END) ');
$self->win->attroff(A_STANDOUT);
$self->win->refresh;
$self->win->addstring(' (END) ');
}
$self->win->attroff(A_STANDOUT);
$self->win->refresh;
}

sub set_chapter {
Expand Down
7 changes: 7 additions & 0 deletions lib/App/termpub/Epub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@ has chapters => sub {
my $href = $item->attr('href');
next if !$href;

my $title;
if ( $self->nav_doc ) {
$title =
$self->nav_doc->find("a[href=$href]")->map('content')->first;
}

push @chapters,
App::termpub::Epub::Chapter->new(
archive => $self->archive,
filename => $self->root_file->sibling($href)->to_rel->to_string,
href => $href,
$title ? ( title => $title ) : (),
);
}
return \@chapters;
Expand Down
7 changes: 7 additions & 0 deletions lib/App/termpub/Epub/Chapter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ has 'archive';
has 'title';
has 'filename';
has 'href';
has title => sub {
shift->dom->find('title')->map('content')->first;
};
has content => sub {
my $self = shift;
$self->archive->contents( $self->filename );
};

has dom => sub {
Mojo::DOM->new( shift->content );
};

1;

0 comments on commit 821490c

Please sign in to comment.