Skip to content

Commit

Permalink
feat: no match screen, also cursor hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Nov 15, 2023
1 parent ba7a842 commit 887d50a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/mux/screen/replay/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type Replay struct {

isForward bool
isWaiting bool
// Whether no matches came back
isEmpty bool
searchProgress chan int
progressPercent int
searchInput textinput.Model
Expand Down
4 changes: 2 additions & 2 deletions pkg/mux/screen/replay/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func (r *Replay) handleSearchResult(msg SearchResultEvent) (taro.Model, tea.Cmd)
// TODO(cfoust): 10/13/23 handle error

matches := msg.results
r.matches = matches
if len(matches) == 0 {
r.matches = matches
r.isEmpty = true
return r, nil
}

r.matches = matches
r.location = msg.origin
r.isForward = msg.isForward
r.searchAgain(true)
Expand Down
14 changes: 14 additions & 0 deletions pkg/mux/screen/replay/stories/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ var SearchTimeBackward stories.InitFunc = func(ctx context.Context) mux.Screen {
return replay
}

var SearchEmpty stories.InitFunc = func(ctx context.Context) mux.Screen {
replay := createStory(
ctx,
createTestSession(),
R.ActionBeginning,
R.ActionSearchForward,
"asdf",
"enter",
)

return replay
}

func init() {
config := stories.Config{
Size: geom.DEFAULT_SIZE,
Expand All @@ -136,4 +149,5 @@ func init() {
stories.Register("replay/time/jump-forward", JumpForward, config)
stories.Register("replay/time/search-reverse", SearchTimeBackward, config)
stories.Register("replay/time/jump-backward", JumpBackward, config)
stories.Register("replay/time/search-empty", SearchEmpty, config)
}
3 changes: 3 additions & 0 deletions pkg/mux/screen/replay/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func (r *Replay) Update(msg tea.Msg) (taro.Model, tea.Cmd) {
return r, nil
}
case taro.KeyMsg:
// Clear out the "no matches" dialog
r.isEmpty = false

// Pass unmatched keys into the binding engine; because of how
// text input works, :replay bindings have to be activated
// selectively
Expand Down
5 changes: 4 additions & 1 deletion pkg/mux/screen/replay/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ func (r *Replay) renderInput() image.Image {
filled := int((float64(percent) / 100) * float64(width))

input = progressStyle.Width(filled).Render("") + inputStyle.Width(width-filled).Render("")
} else if r.isEmpty {
prompt = "no matches found"
}

prompt = promptStyle.Render(prompt)
Expand Down Expand Up @@ -311,6 +313,7 @@ func (r *Replay) View(state *tty.State) {
state.Cursor = r.terminal.Cursor()
state.Cursor.X = termCursor.C
state.Cursor.Y = termCursor.R
state.CursorVisible = r.terminal.CursorVisible()
}

// Show the selection state
Expand All @@ -335,7 +338,7 @@ func (r *Replay) View(state *tty.State) {

// Render text input
/////////////////////////////
if r.mode != ModeInput && !r.isWaiting {
if r.mode != ModeInput && !r.isWaiting && !r.isEmpty {
return
}

Expand Down

0 comments on commit 887d50a

Please sign in to comment.