Skip to content

Commit

Permalink
feat: search progress
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Nov 11, 2023
1 parent 3ba2582 commit d4f8ca8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pkg/mux/screen/replay/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -92,8 +92,8 @@ func (r *Replay) waitProgress() tea.Cmd {
}

return func() tea.Msg {
return progressEvent{
value: <-r.searchProgress,
return ProgressEvent{
Percent: <-r.searchProgress,
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/mux/screen/replay/stories/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/mux/screen/replay/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 25 additions & 4 deletions pkg/mux/screen/replay/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d4f8ca8

Please sign in to comment.