From 887d50ae8c94ee53444ba5a08a4227e4bd2f028d Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Tue, 14 Nov 2023 20:24:06 -0500 Subject: [PATCH] feat: no match screen, also cursor hiding --- pkg/mux/screen/replay/module.go | 2 ++ pkg/mux/screen/replay/search.go | 4 ++-- pkg/mux/screen/replay/stories/module.go | 14 ++++++++++++++ pkg/mux/screen/replay/update.go | 3 +++ pkg/mux/screen/replay/view.go | 5 ++++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pkg/mux/screen/replay/module.go b/pkg/mux/screen/replay/module.go index 8c414cce..998b4eff 100644 --- a/pkg/mux/screen/replay/module.go +++ b/pkg/mux/screen/replay/module.go @@ -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 diff --git a/pkg/mux/screen/replay/search.go b/pkg/mux/screen/replay/search.go index 55b39ba9..8ffe31b2 100644 --- a/pkg/mux/screen/replay/search.go +++ b/pkg/mux/screen/replay/search.go @@ -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) diff --git a/pkg/mux/screen/replay/stories/module.go b/pkg/mux/screen/replay/stories/module.go index f3ec915a..c19a6733 100644 --- a/pkg/mux/screen/replay/stories/module.go +++ b/pkg/mux/screen/replay/stories/module.go @@ -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, @@ -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) } diff --git a/pkg/mux/screen/replay/update.go b/pkg/mux/screen/replay/update.go index cef7fa92..ed3e2845 100644 --- a/pkg/mux/screen/replay/update.go +++ b/pkg/mux/screen/replay/update.go @@ -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 diff --git a/pkg/mux/screen/replay/view.go b/pkg/mux/screen/replay/view.go index e9427cde..13bc9a0a 100644 --- a/pkg/mux/screen/replay/view.go +++ b/pkg/mux/screen/replay/view.go @@ -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) @@ -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 @@ -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 }