From 857361eaf24bfcedf807caeb647d42a652d11025 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Tue, 30 Apr 2024 23:47:58 -0500 Subject: [PATCH] feat(player): Add `,`/`.` to step by a frame --- internal/player/keymap.go | 14 ++++++++++++++ internal/player/player.go | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/internal/player/keymap.go b/internal/player/keymap.go index ff045e91..a431aa5c 100644 --- a/internal/player/keymap.go +++ b/internal/player/keymap.go @@ -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(", (when paused)", "step backward"), + ), + stepNext: key.NewBinding( + key.WithKeys("."), + key.WithHelp(". (when paused)", "step forward"), + ), help: key.NewBinding( key.WithKeys("?"), key.WithHelp("?", "help"), @@ -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 } @@ -105,6 +115,10 @@ func (k keymap) FullHelp() [][]key.Binding { k.jump, k.jumpPrev, k.jumpNext, + k.stepPrev, + k.stepNext, + }, + { k.help, k.quit, }, diff --git a/internal/player/player.go b/internal/player/player.go index c91b4619..d870b401 100644 --- a/internal/player/player.go +++ b/internal/player/player.go @@ -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) {