Commit Graph

11 Commits

Author SHA1 Message Date
Christian Muehlhaeuser c56884c0e2
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.
2023-04-17 22:02:55 +02:00
Christoffer Åström e95e1a0db5 feat: `sequence` support `BatchMsg` 2023-02-07 10:06:46 -05:00
Christian Muehlhaeuser e15bcb7e0e feat: tea.WithContext ProgramOption to supply a context
WithContext lets you specify a context in which to run the Program.
This is useful if you want to cancel the execution from outside.
When a Program gets cancelled it will exit with an error
ErrProgramKilled.
2022-10-23 05:59:10 +02:00
treilik 918d35746b feat: export BatchMsg
There's no good reason to keep it private. Exporting it helps
testability, debugging, and allows for a few special model.Update
implementations.
2022-10-22 22:51:46 +02:00
Christian Muehlhaeuser 3609d87e70 fix: don't block in Send after shutdown
Send should block before a tea.Program has been started, but result
in a no-op when it has already been terminated.

Fixed godocs.
2022-10-15 04:21:44 +02:00
Christian Muehlhaeuser 1ed623fdc0 fix: kill should result in Start returning an error
This fixes Kill resulting in a final nil model being returned.

We can also drop the kill channel and rely on our existing context
channel.
2022-10-12 05:26:39 +02:00
Christian Muehlhaeuser 77619d21f5 test: add sequenceMsg test 2022-10-08 19:02:54 +02:00
Christian Muehlhaeuser 9117bbc137 test: add batchMsg test 2022-10-08 18:52:09 +02:00
Christian Muehlhaeuser 6b77c8fc10 chore: rename StartReturningModel to Run
Added aliases for the old functions, but deprecated them.
2022-10-08 01:34:17 +02:00
Christian Muehlhaeuser 5d1ffa74cd test: quit/kill model after the first render 2022-09-27 05:02:33 +02:00
Christian Muehlhaeuser e9fe942675 test: run model with provided input and check output 2022-09-22 19:40:40 +02:00