Skip to content

Commit

Permalink
fix: simplify filter mode logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Jul 3, 2024
1 parent 10fbeca commit 40a1dff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
6 changes: 1 addition & 5 deletions internal/tui/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ func WithParent(parent resource.Resource) NavigateOption {

type InfoMsg string

// FilterFocusReqMsg is a request to focus the filter widget. FilterFocusAckMsg
// should be sent in response to ackowledge the request.
// FilterFocusReqMsg is a request to focus the filter widget.
type FilterFocusReqMsg struct{}

// FilterFocusAckMsg acknowledges a request to focus the filter widget
type FilterFocusAckMsg struct{}

// FilterBlurMsg is a request to unfocus the filter widget. It is not
// acknowledged.
type FilterBlurMsg struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ func (m Model[V]) Update(msg tea.Msg) (Model[V], tea.Cmd) {
blink := m.filter.Focus()
// Resize the viewport to accommodate the filter widget
m.setDimensions(m.width, m.height)
// Acknowledge the request, and start blinking the cursor.
return m, tea.Batch(tui.CmdHandler(tui.FilterFocusAckMsg{}), blink)
// Start blinking the cursor.
return m, blink
case tui.FilterBlurMsg:
// Blur the filter widget
m.filter.Blur()
Expand Down
12 changes: 5 additions & 7 deletions internal/tui/top/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

switch msg := msg.(type) {
case tui.FilterFocusAckMsg:
// The filter widget has acknowledged the focus request, so we can now
// enable filter mode.
m.mode = filterMode
case tui.PromptMsg:
// Enable prompt widget
m.mode = promptMode
Expand Down Expand Up @@ -216,9 +212,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// existing child models
m.resetDimensions()
case key.Matches(msg, keys.Global.Filter):
// '/' enables filter mode, but only if the current model
// acknowledges the message.
cmd = m.updateCurrent(tui.FilterFocusReqMsg{})
// '/' enables filter mode if the current model indicates it
// supports it, which it does so by sending back a non-nil command.
if cmd = m.updateCurrent(tui.FilterFocusReqMsg{}); cmd != nil {
m.mode = filterMode
}
return m, cmd
case key.Matches(msg, keys.Global.Logs):
// show logs
Expand Down

0 comments on commit 40a1dff

Please sign in to comment.