Skip to content

Commit

Permalink
feat(player): Add ,/. to step by a frame
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed May 1, 2024
1 parent b9c29ef commit 45d8cb8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/player/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func newKeymap() keymap {
key.WithKeys("shift+right", "L", "D"),
key.WithHelp("shift+right", "jump forward"),
),
stepPrev: key.NewBinding(
key.WithKeys(","),
key.WithHelp(",", "step backward"),
),
stepNext: key.NewBinding(
key.WithKeys("."),
key.WithHelp(".", "step forward"),
),
help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "help"),
Expand All @@ -80,6 +88,8 @@ type keymap struct {
jump key.Binding
jumpPrev key.Binding
jumpNext key.Binding
stepPrev key.Binding
stepNext key.Binding
help key.Binding
}

Expand All @@ -105,6 +115,10 @@ func (k keymap) FullHelp() [][]key.Binding {
k.jump,
k.jumpPrev,
k.jumpNext,
k.stepPrev,
k.stepNext,
},
{
k.help,
k.quit,
},
Expand Down
10 changes: 10 additions & 0 deletions internal/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ func (p *Player) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if p.isPlaying() {
return p, p.play()
}
case key.Matches(msg, p.keymap.stepPrev):
if !p.isPlaying() && p.frame > 0 {
p.frame--
return p, nil
}
case key.Matches(msg, p.keymap.stepNext):
if !p.isPlaying() && p.frame < len(p.movie.Frames)-1 {
p.frame++
return p, nil
}
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 45d8cb8

Please sign in to comment.