diff --git a/pkg/mux/screen/replay/search.go b/pkg/mux/screen/replay/search.go index db7ff0a4..55b39ba9 100644 --- a/pkg/mux/screen/replay/search.go +++ b/pkg/mux/screen/replay/search.go @@ -82,8 +82,8 @@ func (r *Replay) searchAgain(isForward bool) { r.gotoMatch(initialIndex) } -type progressEvent struct { - value int +type ProgressEvent struct { + Percent int } func (r *Replay) waitProgress() tea.Cmd { @@ -92,8 +92,8 @@ func (r *Replay) waitProgress() tea.Cmd { } return func() tea.Msg { - return progressEvent{ - value: <-r.searchProgress, + return ProgressEvent{ + Percent: <-r.searchProgress, } } } diff --git a/pkg/mux/screen/replay/stories/module.go b/pkg/mux/screen/replay/stories/module.go index 4aa2f06a..4b0bfe3a 100644 --- a/pkg/mux/screen/replay/stories/module.go +++ b/pkg/mux/screen/replay/stories/module.go @@ -73,6 +73,19 @@ var Searching stories.InitFunc = func(ctx context.Context) mux.Screen { return replay } +var SearchProgress stories.InitFunc = func(ctx context.Context) mux.Screen { + replay := createStory( + ctx, + createTestSession(), + R.ActionSearchForward, + "query", + "enter", + R.ProgressEvent{Percent: 60}, + ) + + return replay +} + var JumpForward stories.InitFunc = func(ctx context.Context) mux.Screen { replay := createStory( ctx, @@ -115,6 +128,10 @@ func init() { Size: geom.DEFAULT_SIZE, IsSnapshot: true, }) + stories.Register("replay/time/search-progress", SearchProgress, stories.Config{ + Size: geom.DEFAULT_SIZE, + IsSnapshot: true, + }) stories.Register("replay/time/jump-forward", JumpForward, config) stories.Register("replay/time/search-reverse", SearchTimeBackward, config) stories.Register("replay/time/jump-backward", JumpBackward, config) diff --git a/pkg/mux/screen/replay/update.go b/pkg/mux/screen/replay/update.go index 0212aedb..cef7fa92 100644 --- a/pkg/mux/screen/replay/update.go +++ b/pkg/mux/screen/replay/update.go @@ -21,8 +21,8 @@ func (r *Replay) Update(msg tea.Msg) (taro.Model, tea.Cmd) { viewport := r.viewport switch msg := msg.(type) { - case progressEvent: - r.progressPercent = msg.value + case ProgressEvent: + r.progressPercent = msg.Percent return r, r.waitProgress() case PlaybackRateEvent: r.playbackRate = geom.Clamp(msg.Rate, -10, 10) diff --git a/pkg/mux/screen/replay/view.go b/pkg/mux/screen/replay/view.go index a84dae34..53dcc288 100644 --- a/pkg/mux/screen/replay/view.go +++ b/pkg/mux/screen/replay/view.go @@ -9,6 +9,7 @@ import ( "github.com/cfoust/cy/pkg/geom/image" "github.com/cfoust/cy/pkg/geom/tty" + "github.com/charmbracelet/bubbles/spinner" "github.com/charmbracelet/lipgloss" ) @@ -189,14 +190,34 @@ func (r *Replay) renderInput() image.Image { } } + input := inputStyle.Render(r.searchInput.View()) + if r.isWaiting { - prompt = fmt.Sprintf("searching...(%d/100)", r.progressPercent) + percent := r.progressPercent + + spin := spinner.Dot + first := spin.Frames[percent%len(spin.Frames)] + left := "searching..." + prompt = left + lipgloss.PlaceHorizontal( + width-len(left), + lipgloss.Right, + first, + ) + + progressStyle := inputStyle.Copy(). + Background(lipgloss.Color("#4D9DE0")) + + filled := int((float64(percent) / 100) * float64(width)) + + input = progressStyle.Width(filled).Render("") + inputStyle.Width(width-filled).Render("") } - input := lipgloss.JoinVertical( + prompt = promptStyle.Render(prompt) + + input = lipgloss.JoinVertical( lipgloss.Left, - inputStyle.Render(r.searchInput.View()), - promptStyle.Render(prompt), + input, + prompt, ) result := image.New(geom.Size{ R: lipgloss.Height(input),