Skip to content

Commit

Permalink
feat(player): Add keybinds to jump backward/forward 5 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Apr 27, 2024
1 parent 325fa58 commit e5e553c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/movie/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ func newKeymap() keymap {
key.WithKeys("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"),
key.WithHelp("0-9", "jump to position"),
),
jumpPrev: key.NewBinding(
key.WithKeys("shift+left", "H", "A"),
key.WithHelp("shift+left", "jump backward"),
),
jumpNext: key.NewBinding(
key.WithKeys("shift+right", "L", "D"),
key.WithHelp("shift+right", "jump forward"),
),
help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "help"),
Expand All @@ -70,6 +78,8 @@ type keymap struct {
chooseFull key.Binding
jumps []key.Binding
jump key.Binding
jumpPrev key.Binding
jumpNext key.Binding
help key.Binding
}

Expand All @@ -93,6 +103,8 @@ func (k keymap) FullHelp() [][]key.Binding {
},
{
k.jump,
k.jumpPrev,
k.jumpNext,
k.help,
k.quit,
},
Expand Down
18 changes: 18 additions & 0 deletions internal/movie/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ func (p Player) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, p.keymap.help):
p.help.ShowAll = !p.help.ShowAll
p.helpViewStale = true
case key.Matches(msg, p.keymap.jumpPrev):
var d time.Duration
for d < 5*time.Second && p.frame > 0 {
p.frame--
d += p.movie.Frames[p.frame].Duration
}
if p.isPlaying() {
return p, p.play()
}
case key.Matches(msg, p.keymap.jumpNext):
var d time.Duration
for d < 5*time.Second && p.frame < len(p.movie.Frames)-1 {
p.frame++
d += p.movie.Frames[p.frame].Duration
}
if p.isPlaying() {
return p, p.play()
}
case key.Matches(msg, p.keymap.jumps...):
for i, binding := range p.keymap.jumps {
if key.Matches(msg, binding) {
Expand Down

0 comments on commit e5e553c

Please sign in to comment.