Skip to content

Commit 2fb9dc4

Browse files
authored
fix: hotkeys in filter (#14)
1 parent 3a47497 commit 2fb9dc4

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

internal/app/action.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ func (m Model) quit() (Model, tea.Cmd) {
3131
return m, tea.Quit
3232
}
3333

34+
func (m Model) quitByRune() (tea.Model, tea.Cmd) {
35+
if m.IsFilterShown() {
36+
return nil, nil
37+
}
38+
39+
return m, tea.Quit
40+
}
41+
3442
func (m Model) showFilter() (tea.Model, tea.Cmd) {
43+
if m.IsFilterShown() {
44+
return nil, nil
45+
}
46+
3547
if !m.IsTableShown() {
3648
return nil, nil
3749
}

internal/app/app_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ func TestAppQuit(t *testing.T) {
104104
assert.Equal(t, tea.Quit(), cmd())
105105
}
106106
})
107+
108+
t.Run("q", func(t *testing.T) {
109+
t.Parallel()
110+
111+
_, cmd := toAppModel(appModel.Update(tea.KeyMsg{
112+
Type: tea.KeyRunes,
113+
Runes: []rune{'q'},
114+
}))
115+
116+
if assert.NotNil(t, cmd) {
117+
assert.Equal(t, tea.Quit(), cmd())
118+
}
119+
})
107120
}
108121

109122
func newTestModel(tb testing.TB, content []byte) app.Model {
@@ -124,3 +137,26 @@ func toAppModel(teaModel tea.Model, cmd tea.Cmd) (app.Model, tea.Cmd) {
124137

125138
return appModel, cmd
126139
}
140+
141+
func TestAppViewFiltereRunes(t *testing.T) {
142+
appModel := newTestModel(t, assets.ExampleJSONLog())
143+
144+
appModel, _ = toAppModel(appModel.Update(tea.KeyMsg{
145+
Type: tea.KeyRunes,
146+
Runes: []rune{'f'},
147+
}))
148+
assert.True(t, appModel.IsFilterShown(), appModel.View())
149+
150+
appModel, cmd := toAppModel(appModel.Update(tea.KeyMsg{
151+
Type: tea.KeyRunes,
152+
Runes: []rune{'q'},
153+
}))
154+
assert.NotEqual(t, tea.Quit(), cmd())
155+
156+
appModel, cmd = toAppModel(appModel.Update(tea.KeyMsg{
157+
Type: tea.KeyRunes,
158+
Runes: []rune{'f'},
159+
}))
160+
assert.NotEqual(t, tea.Quit(), cmd())
161+
assert.True(t, appModel.IsFilterShown(), appModel.View())
162+
}

internal/app/handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ func (m Model) handleKeyMsg(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
1212
switch msg.String() {
1313
case "esc":
1414
return m.back()
15-
case "q", "ctrl+c":
15+
case "ctrl+c":
1616
return m.quit()
17+
case "q":
18+
return m.quitByRune()
1719
case "enter":
1820
return m.handleEnter()
1921
case "f":

0 commit comments

Comments
 (0)