mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
feat: add generic event filter (#536)
`WithFilter` lets you supply an event filter that will be invoked before Bubble Tea processes a `tea.Msg`. The event filter can return any `tea.Msg` which will then get handled by Bubble Tea instead of the original event. If the event filter returns nil, the event will be ignored and Bubble Tea will not process it. As an example, this could be used to prevent a program from shutting down if there are unsaved changes. Based on the fantastic work by @aschey and supersedes #521. Resolves #472.
This commit is contained in:
committed by
GitHub
parent
8514d90b9e
commit
c56884c0e2
@@ -35,6 +35,13 @@ func TestOptions(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("filter", func(t *testing.T) {
|
||||
p := NewProgram(nil, WithFilter(func(_ Model, msg Msg) Msg { return msg }))
|
||||
if p.filter == nil {
|
||||
t.Errorf("expected filter to be set")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("startup options", func(t *testing.T) {
|
||||
exercise := func(t *testing.T, opt ProgramOption, expect startupOptions) {
|
||||
p := NewProgram(nil, opt)
|
||||
|
||||
Reference in New Issue
Block a user